From 0e104336c02a385334fc73c2d7e90b28223c24bf Mon Sep 17 00:00:00 2001 From: Sebastian Kalinowski Date: Fri, 23 Oct 2015 13:54:57 +0200 Subject: [PATCH 01/13] Get node data from ohai and put it into discovery Node info is gathered by running ohai using ssh transport from solar. Then it's uploaded to discovery system. --- examples/provisioning/provision.py | 53 +++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/examples/provisioning/provision.py b/examples/provisioning/provision.py index 5b58830e..6178a002 100755 --- a/examples/provisioning/provision.py +++ b/examples/provisioning/provision.py @@ -1,18 +1,43 @@ #!/usr/bin/env python +import json + import requests -from solar.core import resource -from solar.core import signals -from solar.core import validation from solar.core.resource import virtual_resource as vr +from solar.core.transports.ssh import SSHRunTransport -from solar.events.controls import React from solar.events.api import add_event +from solar.events.controls import React +transport_run = SSHRunTransport() + discovery_service = 'http://0.0.0.0:8881' + +class NodeAdapter(dict): + + def __getattr__(self, name): + try: + return self[name] + except KeyError: + raise AttributeError(name) + + @property + def safe_mac(self): + return self['mac'].replace(':', '_') + + +def feed_discovery(mac, ohai_data): + return requests.put( + "{base_url}/nodes/{mac}/".format( + base_url=discovery_service, + mac=mac, + ), + json=ohai_data, + ) + nodes_list = requests.get(discovery_service).json() # Create slave node resources @@ -23,14 +48,20 @@ master_node = filter(lambda n: n.name == 'node_master', node_resources)[0] # Dnsmasq resources for node in nodes_list: - dnsmasq = vr.create('dnsmasq_{0}'.format(node['mac'].replace(':', '_')), 'resources/dnsmasq', {})[0] - node = filter(lambda n: n.name.endswith('node_{0}'.format(node['mac']).replace(':', '_')), node_resources)[0] - master_node.connect(dnsmasq) - node.connect(dnsmasq, {'admin_mac': 'exclude_mac_pxe'}) + node = NodeAdapter(node) + node_resource = filter(lambda n: n.name.endswith('node_{0}'.format(node.safe_mac)), node_resources)[0] - event = React(node.name, 'run', 'success', node.name, 'provision') + run_result = transport_run.run(node_resource, 'ohai') + ohai = json.loads(run_result.stdout) + feed_discovery(node['mac'], ohai) + + dnsmasq = vr.create('dnsmasq_{0}'.format(node.safe_mac), 'resources/dnsmasq', {})[0] + master_node.connect(dnsmasq) + node_resource.connect(dnsmasq, {'admin_mac': 'exclude_mac_pxe'}) + + event = React(node_resource.name, 'run', 'success', node_resource.name, 'provision') add_event(event) - event = React(node.name, 'provision', 'success', dnsmasq.name, 'exclude_mac_pxe') + event = React(node_resource.name, 'provision', 'success', dnsmasq.name, 'exclude_mac_pxe') add_event(event) - event = React(dnsmasq.name, 'exclude_mac_pxe', 'success', node.name, 'reboot') + event = React(dnsmasq.name, 'exclude_mac_pxe', 'success', node_resource.name, 'reboot') add_event(event) From 5c71dc881bb0bde6dc76b0af0ee5172a5b53bbfb Mon Sep 17 00:00:00 2001 From: Sebastian Kalinowski Date: Tue, 27 Oct 2015 13:06:42 +0100 Subject: [PATCH 02/13] Use "new" partition format during provisioning --- .../not_provisioned_node/actions/provision.sh | 3 +- .../templates/provisioning_new.json | 289 ++++++++++++++++++ 2 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 resources/not_provisioned_node/templates/provisioning_new.json diff --git a/resources/not_provisioned_node/actions/provision.sh b/resources/not_provisioned_node/actions/provision.sh index ccbdb45c..2e1737a0 100644 --- a/resources/not_provisioned_node/actions/provision.sh +++ b/resources/not_provisioned_node/actions/provision.sh @@ -6,4 +6,5 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # TODO should be a way to render configs, in order to do this # we should have scripts dir variable passed from above sed -i "s||${DIR}|" "${DIR}"/templates/agent.config -provision --input_data_file "${DIR}"/templates/provisioning.json --config-file "${DIR}"/templates/agent.config +#provision --input_data_file "${DIR}"/templates/provisioning.json --config-file "${DIR}"/templates/agent.config +provision --input_data_file "${DIR}"/templates/provisioning_new.json --config-file "${DIR}"/templates/agent.config --data_driver nailgun_simple diff --git a/resources/not_provisioned_node/templates/provisioning_new.json b/resources/not_provisioned_node/templates/provisioning_new.json new file mode 100644 index 00000000..188513cc --- /dev/null +++ b/resources/not_provisioned_node/templates/provisioning_new.json @@ -0,0 +1,289 @@ +{ + "profile": "ubuntu_1404_x86_64", + "name_servers_search": "\"example.com\"", + "uid": "2", + "interfaces": { + "eth1": { + "static": "0", + "mac_address": "08:00:27:6e:6d:b4" + }, + "eth0": { + "ip_address": "10.0.2.15", + "dns_name": "node-8.test.domain.local", + "netmask": "255.255.255.0", + "static": "0", + "mac_address": "08:00:27:ea:35:e7" + } + }, + "interfaces_extra": { + "eth1": { + "onboot": "no", + "peerdns": "no" + }, + "eth0": { + "onboot": "no", + "peerdns": "no" + } + }, + "power_type": "ssh", + "power_user": "root", + "kernel_options": { + "udevrules": "08:00:27:6e:6d:b4_eth1,08:00:27:ea:35:e7_eth0", + "netcfg/choose_interface": "08:00:27:ea:35:e7" + }, + "power_address": "10.20.0.1", + "name_servers": "\"127.0.0.1\"", + "ks_meta": { + "gw": "10.20.0.1", + "mco_enable": 1, + "mco_vhost": "mcollective", + "repo_setup": { + "installer_kernel": { + "local": "/var/www/nailgun/ubuntu/x86_64/images/linux", + "remote_relative": "dists/trusty/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/linux" + }, + "repos": [ + { + "name": "ubuntu", + "section": "main universe multiverse", + "uri": "http://archive.ubuntu.com/ubuntu/", + "priority": null, + "suite": "trusty", + "type": "deb" + }, + { + "name": "ubuntu-updates", + "section": "main universe multiverse", + "uri": "http://archive.ubuntu.com/ubuntu/", + "priority": null, + "suite": "trusty-updates", + "type": "deb" + }, + { + "name": "ubuntu-security", + "section": "main universe multiverse", + "uri": "http://archive.ubuntu.com/ubuntu/", + "priority": null, + "suite": "trusty-security", + "type": "deb" + }, + { + "name": "mos", + "section": "main restricted", + "uri": "http://127.0.0.1:8080/2015.1.0-7.0/ubuntu/x86_64", + "priority": 1050, + "suite": "mos7.0", + "type": "deb" + }, + { + "name": "mos-updates", + "section": "main restricted", + "uri": "http://mirror.fuel-infra.org/mos/ubuntu/", + "priority": 1050, + "suite": "mos7.0-updates", + "type": "deb" + }, + { + "name": "mos-security", + "section": "main restricted", + "uri": "http://mirror.fuel-infra.org/mos/ubuntu/", + "priority": 1050, + "suite": "mos7.0-security", + "type": "deb" + }, + { + "name": "mos-holdback", + "section": "main restricted", + "uri": "http://mirror.fuel-infra.org/mos/ubuntu/", + "priority": 1100, + "suite": "mos7.0-holdback", + "type": "deb" + }, + { + "name": "Auxiliary", + "section": "main restricted", + "uri": "http://127.0.0.1:8080/2015.1.0-7.0/ubuntu/auxiliary", + "priority": 1150, + "suite": "auxiliary", + "type": "deb" + } + ], + "metadata": { + "always_editable": true, + "weight": 50, + "label": "Repositories" + }, + "installer_initrd": { + "local": "/var/www/nailgun/ubuntu/x86_64/images/initrd.gz", + "remote_relative": "dists/trusty/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/initrd.gz" + } + }, + "authorized_keys": [], + "mlnx_iser_enabled": false, + "mco_pskey": "Gie6iega9ohngaenahthohngu8aebohxah9seidi", + "mco_user": "guest", + "puppet_enable": 0, + "fuel_version": "6.1", + "install_log_2_syslog": 1, + "image_data": { + "/boot": { + "container": "gzip", + "uri": "http://10.0.0.2:8001/tmp/targetimages/env_3_ubuntu_1404_amd64-boot.img.gz", + "format": "ext2" + }, + "/": { + "container": "gzip", + "uri": "http://10.0.0.2:8001/tmp/targetimages/env_3_ubuntu_1404_amd64.img.gz", + "format": "ext4" + } + }, + "timezone": "Etc/UTC", + "puppet_auto_setup": 1, + "puppet_master": "localhost", + "mco_auto_setup": 1, + "mco_password": "guest", + "auth_key": "\"\"", + "pm_data": { + "kernel_params": "console=ttyS0,9600 console=tty0 net.ifnames=0 biosdevname=0 rootdelay=90 nomodeset", + "ks_spaces": [] + }, + "mlnx_plugin_mode": "disabled", + "master_ip": "127.0.0.1", + "mco_connector": "rabbitmq", + "mlnx_vf_num": "16", + "admin_net": "10.20.0.0/24", + "mco_host": "localhost" + }, + "name": "node-2", + "hostname": "node-2.example.com", + "slave_name": "node-2", + "power_pass": "/root/.ssh/bootstrap.rsa", + "netboot_enabled": "1", + "partitioning": { + "pvs": [ + { + "metadatasize": 28, + "name": "/dev/sda4", + "metadatacopies": 2, + "keep_data": false + } + ], + "lvs": [ + { + "vgname": "os", + "keep_data": false, + "name": "root", + "size": 11744 + }, + { + "vgname": "os", + "keep_data": false, + "name": "swap", + "size": 8192 + } + ], + "fss": [ + { + "keep_data": false, + "mount": "/boot", + "fs_label": "", + "fs_type": "ext2", + "fs_options": "", + "device": "/dev/sda3" + }, + { + "keep_data": false, + "mount": "/", + "fs_label": "", + "fs_type": "ext4", + "fs_options": "", + "device": "/dev/mapper/os-root" + }, + { + "keep_data": false, + "mount": "swap", + "fs_label": "", + "fs_type": "swap", + "fs_options": "", + "device": "/dev/mapper/os-swap" + } + ], + "parteds": [ + { + "install_bootloader": true, + "partitions": [ + { + "count": 1, + "begin": 1, + "end": 25, + "name": "/dev/sda1", + "keep_data": false, + "device": "/dev/sda", + "flags": ["bios_grub"], + "guid": null, + "configdrive": false, + "partition_type": "primary" + }, + { + "count": 2, + "begin": 25, + "end": 225, + "name": "/dev/sda2", + "keep_data": false, + "device": "/dev/sda", + "flags": [], + "guid": null, + "configdrive": false, + "partition_type": "primary" + }, + { + "count": 3, + "begin": 225, + "end": 425, + "name": "/dev/sda3", + "keep_data": false, + "device": "/dev/sda", + "flags": [], + "guid": null, + "configdrive": false, + "partition_type": "primary" + }, + { + "count": 4, + "begin": 425, + "end": 20425, + "name": "/dev/sda4", + "keep_data": false, + "device": "/dev/sda", + "flags": [], + "guid": null, + "configdrive": false, + "partition_type": "primary" + }, + { + "count": 5, + "begin": 20425, + "end": 20445, + "name": "/dev/sda5", + "keep_data": false, + "device": "/dev/sda", + "flags": [], + "guid": null, + "configdrive": true, + "partition_type": "primary" + } + ], + "name": "/dev/sda", + "label": "gpt" + } + ], + "mds": [], + "vgs": [ + { + "keep_data": false, + "name": "os", + "pvnames": ["/dev/sda4"] + } + ] + } +} From 318409bd69664229aec966c9ce80952da0dae26d Mon Sep 17 00:00:00 2001 From: Evgeniy L Date: Tue, 27 Oct 2015 16:53:40 +0300 Subject: [PATCH 03/13] Remove new provisioning.json template for not_provisioned_node resource --- .../templates/provisioning_new.json | 289 ------------------ 1 file changed, 289 deletions(-) delete mode 100644 resources/not_provisioned_node/templates/provisioning_new.json diff --git a/resources/not_provisioned_node/templates/provisioning_new.json b/resources/not_provisioned_node/templates/provisioning_new.json deleted file mode 100644 index 188513cc..00000000 --- a/resources/not_provisioned_node/templates/provisioning_new.json +++ /dev/null @@ -1,289 +0,0 @@ -{ - "profile": "ubuntu_1404_x86_64", - "name_servers_search": "\"example.com\"", - "uid": "2", - "interfaces": { - "eth1": { - "static": "0", - "mac_address": "08:00:27:6e:6d:b4" - }, - "eth0": { - "ip_address": "10.0.2.15", - "dns_name": "node-8.test.domain.local", - "netmask": "255.255.255.0", - "static": "0", - "mac_address": "08:00:27:ea:35:e7" - } - }, - "interfaces_extra": { - "eth1": { - "onboot": "no", - "peerdns": "no" - }, - "eth0": { - "onboot": "no", - "peerdns": "no" - } - }, - "power_type": "ssh", - "power_user": "root", - "kernel_options": { - "udevrules": "08:00:27:6e:6d:b4_eth1,08:00:27:ea:35:e7_eth0", - "netcfg/choose_interface": "08:00:27:ea:35:e7" - }, - "power_address": "10.20.0.1", - "name_servers": "\"127.0.0.1\"", - "ks_meta": { - "gw": "10.20.0.1", - "mco_enable": 1, - "mco_vhost": "mcollective", - "repo_setup": { - "installer_kernel": { - "local": "/var/www/nailgun/ubuntu/x86_64/images/linux", - "remote_relative": "dists/trusty/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/linux" - }, - "repos": [ - { - "name": "ubuntu", - "section": "main universe multiverse", - "uri": "http://archive.ubuntu.com/ubuntu/", - "priority": null, - "suite": "trusty", - "type": "deb" - }, - { - "name": "ubuntu-updates", - "section": "main universe multiverse", - "uri": "http://archive.ubuntu.com/ubuntu/", - "priority": null, - "suite": "trusty-updates", - "type": "deb" - }, - { - "name": "ubuntu-security", - "section": "main universe multiverse", - "uri": "http://archive.ubuntu.com/ubuntu/", - "priority": null, - "suite": "trusty-security", - "type": "deb" - }, - { - "name": "mos", - "section": "main restricted", - "uri": "http://127.0.0.1:8080/2015.1.0-7.0/ubuntu/x86_64", - "priority": 1050, - "suite": "mos7.0", - "type": "deb" - }, - { - "name": "mos-updates", - "section": "main restricted", - "uri": "http://mirror.fuel-infra.org/mos/ubuntu/", - "priority": 1050, - "suite": "mos7.0-updates", - "type": "deb" - }, - { - "name": "mos-security", - "section": "main restricted", - "uri": "http://mirror.fuel-infra.org/mos/ubuntu/", - "priority": 1050, - "suite": "mos7.0-security", - "type": "deb" - }, - { - "name": "mos-holdback", - "section": "main restricted", - "uri": "http://mirror.fuel-infra.org/mos/ubuntu/", - "priority": 1100, - "suite": "mos7.0-holdback", - "type": "deb" - }, - { - "name": "Auxiliary", - "section": "main restricted", - "uri": "http://127.0.0.1:8080/2015.1.0-7.0/ubuntu/auxiliary", - "priority": 1150, - "suite": "auxiliary", - "type": "deb" - } - ], - "metadata": { - "always_editable": true, - "weight": 50, - "label": "Repositories" - }, - "installer_initrd": { - "local": "/var/www/nailgun/ubuntu/x86_64/images/initrd.gz", - "remote_relative": "dists/trusty/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/initrd.gz" - } - }, - "authorized_keys": [], - "mlnx_iser_enabled": false, - "mco_pskey": "Gie6iega9ohngaenahthohngu8aebohxah9seidi", - "mco_user": "guest", - "puppet_enable": 0, - "fuel_version": "6.1", - "install_log_2_syslog": 1, - "image_data": { - "/boot": { - "container": "gzip", - "uri": "http://10.0.0.2:8001/tmp/targetimages/env_3_ubuntu_1404_amd64-boot.img.gz", - "format": "ext2" - }, - "/": { - "container": "gzip", - "uri": "http://10.0.0.2:8001/tmp/targetimages/env_3_ubuntu_1404_amd64.img.gz", - "format": "ext4" - } - }, - "timezone": "Etc/UTC", - "puppet_auto_setup": 1, - "puppet_master": "localhost", - "mco_auto_setup": 1, - "mco_password": "guest", - "auth_key": "\"\"", - "pm_data": { - "kernel_params": "console=ttyS0,9600 console=tty0 net.ifnames=0 biosdevname=0 rootdelay=90 nomodeset", - "ks_spaces": [] - }, - "mlnx_plugin_mode": "disabled", - "master_ip": "127.0.0.1", - "mco_connector": "rabbitmq", - "mlnx_vf_num": "16", - "admin_net": "10.20.0.0/24", - "mco_host": "localhost" - }, - "name": "node-2", - "hostname": "node-2.example.com", - "slave_name": "node-2", - "power_pass": "/root/.ssh/bootstrap.rsa", - "netboot_enabled": "1", - "partitioning": { - "pvs": [ - { - "metadatasize": 28, - "name": "/dev/sda4", - "metadatacopies": 2, - "keep_data": false - } - ], - "lvs": [ - { - "vgname": "os", - "keep_data": false, - "name": "root", - "size": 11744 - }, - { - "vgname": "os", - "keep_data": false, - "name": "swap", - "size": 8192 - } - ], - "fss": [ - { - "keep_data": false, - "mount": "/boot", - "fs_label": "", - "fs_type": "ext2", - "fs_options": "", - "device": "/dev/sda3" - }, - { - "keep_data": false, - "mount": "/", - "fs_label": "", - "fs_type": "ext4", - "fs_options": "", - "device": "/dev/mapper/os-root" - }, - { - "keep_data": false, - "mount": "swap", - "fs_label": "", - "fs_type": "swap", - "fs_options": "", - "device": "/dev/mapper/os-swap" - } - ], - "parteds": [ - { - "install_bootloader": true, - "partitions": [ - { - "count": 1, - "begin": 1, - "end": 25, - "name": "/dev/sda1", - "keep_data": false, - "device": "/dev/sda", - "flags": ["bios_grub"], - "guid": null, - "configdrive": false, - "partition_type": "primary" - }, - { - "count": 2, - "begin": 25, - "end": 225, - "name": "/dev/sda2", - "keep_data": false, - "device": "/dev/sda", - "flags": [], - "guid": null, - "configdrive": false, - "partition_type": "primary" - }, - { - "count": 3, - "begin": 225, - "end": 425, - "name": "/dev/sda3", - "keep_data": false, - "device": "/dev/sda", - "flags": [], - "guid": null, - "configdrive": false, - "partition_type": "primary" - }, - { - "count": 4, - "begin": 425, - "end": 20425, - "name": "/dev/sda4", - "keep_data": false, - "device": "/dev/sda", - "flags": [], - "guid": null, - "configdrive": false, - "partition_type": "primary" - }, - { - "count": 5, - "begin": 20425, - "end": 20445, - "name": "/dev/sda5", - "keep_data": false, - "device": "/dev/sda", - "flags": [], - "guid": null, - "configdrive": true, - "partition_type": "primary" - } - ], - "name": "/dev/sda", - "label": "gpt" - } - ], - "mds": [], - "vgs": [ - { - "keep_data": false, - "name": "os", - "pvnames": ["/dev/sda4"] - } - ] - } -} From 67328e4e344af49881361f2b649a9c844aac33de Mon Sep 17 00:00:00 2001 From: Evgeniy L Date: Tue, 27 Oct 2015 16:55:08 +0300 Subject: [PATCH 04/13] Remove commented line from provision.sh --- resources/not_provisioned_node/actions/provision.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/not_provisioned_node/actions/provision.sh b/resources/not_provisioned_node/actions/provision.sh index 2e1737a0..408d0717 100644 --- a/resources/not_provisioned_node/actions/provision.sh +++ b/resources/not_provisioned_node/actions/provision.sh @@ -6,5 +6,5 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # TODO should be a way to render configs, in order to do this # we should have scripts dir variable passed from above sed -i "s||${DIR}|" "${DIR}"/templates/agent.config -#provision --input_data_file "${DIR}"/templates/provisioning.json --config-file "${DIR}"/templates/agent.config -provision --input_data_file "${DIR}"/templates/provisioning_new.json --config-file "${DIR}"/templates/agent.config --data_driver nailgun_simple + +provision --data_driver nailgun_simple --input_data_file "${DIR}"/templates/provisioning.json --config-file "${DIR}"/templates/agent.config From 6285b7955c2ddb35c9b1e5e990ac94bbc7a33144 Mon Sep 17 00:00:00 2001 From: Evgeniy L Date: Tue, 27 Oct 2015 17:14:14 +0300 Subject: [PATCH 05/13] Use BatTransport instead of ssh to get discovery info --- examples/provisioning/provision.py | 6 +++--- solar/solar/core/transports/bat.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/provisioning/provision.py b/examples/provisioning/provision.py index 6178a002..e69aa082 100755 --- a/examples/provisioning/provision.py +++ b/examples/provisioning/provision.py @@ -5,13 +5,13 @@ import json import requests from solar.core.resource import virtual_resource as vr -from solar.core.transports.ssh import SSHRunTransport +from solar.core.transports.bat import BatRunTransport from solar.events.api import add_event from solar.events.controls import React -transport_run = SSHRunTransport() +transport_run = BatRunTransport() discovery_service = 'http://0.0.0.0:8881' @@ -35,7 +35,7 @@ def feed_discovery(mac, ohai_data): base_url=discovery_service, mac=mac, ), - json=ohai_data, + data=json.dumps(ohai_data), ) nodes_list = requests.get(discovery_service).json() diff --git a/solar/solar/core/transports/bat.py b/solar/solar/core/transports/bat.py index 4ff6f6a6..3814738c 100644 --- a/solar/solar/core/transports/bat.py +++ b/solar/solar/core/transports/bat.py @@ -54,6 +54,7 @@ class BatTransport(SolarTransport): super(BatTransport, self).__init__(*args, **kwargs) self._cache = {} self._used_transports = [] + self._other_remember = None def select_valid_transport(self, resource, *args, **kwargs): key_name = '_bat_transport_%s' % self._mode @@ -114,4 +115,3 @@ class BatRunTransport(RunTransport, BatTransport): def run(self, resource, *args, **kwargs): transport = self.select_valid_transport(resource) return transport.run(resource, *args, **kwargs) - From f23b87bd887680ad5b84c75bb08467832c9012a5 Mon Sep 17 00:00:00 2001 From: Evgeniy L Date: Tue, 27 Oct 2015 17:24:22 +0300 Subject: [PATCH 06/13] Use provisionin.json as template --- .../templates/{provisioning.json => provisioning.json.jinja} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename resources/not_provisioned_node/templates/{provisioning.json => provisioning.json.jinja} (100%) diff --git a/resources/not_provisioned_node/templates/provisioning.json b/resources/not_provisioned_node/templates/provisioning.json.jinja similarity index 100% rename from resources/not_provisioned_node/templates/provisioning.json rename to resources/not_provisioned_node/templates/provisioning.json.jinja From 256d7b3570c85a28f7cbdeb43c1b6742291783cc Mon Sep 17 00:00:00 2001 From: Evgeniy L Date: Tue, 27 Oct 2015 17:42:47 +0300 Subject: [PATCH 07/13] Get partitioning information from bareon-api --- examples/provisioning/provision.py | 7 +++++++ resources/not_provisioned_node/meta.yaml | 3 +++ .../not_provisioned_node/templates/provisioning.json.jinja | 1 + 3 files changed, 11 insertions(+) diff --git a/examples/provisioning/provision.py b/examples/provisioning/provision.py index e69aa082..e225a9d2 100755 --- a/examples/provisioning/provision.py +++ b/examples/provisioning/provision.py @@ -14,6 +14,7 @@ from solar.events.controls import React transport_run = BatRunTransport() discovery_service = 'http://0.0.0.0:8881' +bareon_service = 'http://0.0.0.0:9322/v1/nodes/{0}/partitioning' class NodeAdapter(dict): @@ -28,6 +29,10 @@ class NodeAdapter(dict): def safe_mac(self): return self['mac'].replace(':', '_') + @property + def partitioning(self): + return requests.get(bareon_service.format(self['mac'])).json() + def feed_discovery(mac, ohai_data): return requests.put( @@ -55,6 +60,8 @@ for node in nodes_list: ohai = json.loads(run_result.stdout) feed_discovery(node['mac'], ohai) + node_resource.update({'partitioning': node.partitioning}) + dnsmasq = vr.create('dnsmasq_{0}'.format(node.safe_mac), 'resources/dnsmasq', {})[0] master_node.connect(dnsmasq) node_resource.connect(dnsmasq, {'admin_mac': 'exclude_mac_pxe'}) diff --git a/resources/not_provisioned_node/meta.yaml b/resources/not_provisioned_node/meta.yaml index 7d9a6686..e541342c 100644 --- a/resources/not_provisioned_node/meta.yaml +++ b/resources/not_provisioned_node/meta.yaml @@ -21,5 +21,8 @@ input: schema: str! value: $uuid reverse: True + partitioning: + schema: dict! + value: tags: [resources=node] diff --git a/resources/not_provisioned_node/templates/provisioning.json.jinja b/resources/not_provisioned_node/templates/provisioning.json.jinja index 6b077189..445f39a3 100644 --- a/resources/not_provisioned_node/templates/provisioning.json.jinja +++ b/resources/not_provisioned_node/templates/provisioning.json.jinja @@ -1,4 +1,5 @@ { + "partitioning": {{ partitioning | to_pretty_json }}, "profile": "ubuntu_1404_x86_64", "name_servers_search": "\"example.com\"", "uid": "2", From 7178d66e9d38678f39cd554d2ee1e9ce2ba75475 Mon Sep 17 00:00:00 2001 From: Evgeniy L Date: Wed, 28 Oct 2015 16:50:31 +0300 Subject: [PATCH 08/13] Enable logging for fuel-agent --- resources/not_provisioned_node/templates/agent.config | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/not_provisioned_node/templates/agent.config b/resources/not_provisioned_node/templates/agent.config index d51d09a3..7f807556 100644 --- a/resources/not_provisioned_node/templates/agent.config +++ b/resources/not_provisioned_node/templates/agent.config @@ -1,2 +1,4 @@ [DEFAULT] +debug=true nc_template_path=/templates/cloud-init-templates/ +log_file=/var/log/fuel-agent.log From 6d56dcfe1646a6f67d25354ba3bdba1fdec592c1 Mon Sep 17 00:00:00 2001 From: Sebastian Kalinowski Date: Wed, 28 Oct 2015 16:20:39 +0100 Subject: [PATCH 09/13] Use new discovery scan service Instead of pulling data about nodes into the discovery when provisioning starts, use a separate service that will periodically scan nodes. --- bootstrap/playbooks/pxe.yaml | 1 + examples/provisioning/provision.py | 21 --------------------- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/bootstrap/playbooks/pxe.yaml b/bootstrap/playbooks/pxe.yaml index 2808c1a3..001a0270 100644 --- a/bootstrap/playbooks/pxe.yaml +++ b/bootstrap/playbooks/pxe.yaml @@ -54,6 +54,7 @@ # Install discovery service - shell: pip install git+https://github.com/rustyrobot/discovery.git - shell: 'discovery &' + - shell: 'discovery-scan --ssh_key {{insecure_pub_key_path}} &' # Install bareon-api - shell: pip install git+https://github.com/Mirantis/bareon-api.git diff --git a/examples/provisioning/provision.py b/examples/provisioning/provision.py index e225a9d2..61bd3fe8 100755 --- a/examples/provisioning/provision.py +++ b/examples/provisioning/provision.py @@ -1,18 +1,11 @@ #!/usr/bin/env python - -import json - import requests from solar.core.resource import virtual_resource as vr -from solar.core.transports.bat import BatRunTransport - from solar.events.api import add_event from solar.events.controls import React -transport_run = BatRunTransport() - discovery_service = 'http://0.0.0.0:8881' bareon_service = 'http://0.0.0.0:9322/v1/nodes/{0}/partitioning' @@ -33,16 +26,6 @@ class NodeAdapter(dict): def partitioning(self): return requests.get(bareon_service.format(self['mac'])).json() - -def feed_discovery(mac, ohai_data): - return requests.put( - "{base_url}/nodes/{mac}/".format( - base_url=discovery_service, - mac=mac, - ), - data=json.dumps(ohai_data), - ) - nodes_list = requests.get(discovery_service).json() # Create slave node resources @@ -56,10 +39,6 @@ for node in nodes_list: node = NodeAdapter(node) node_resource = filter(lambda n: n.name.endswith('node_{0}'.format(node.safe_mac)), node_resources)[0] - run_result = transport_run.run(node_resource, 'ohai') - ohai = json.loads(run_result.stdout) - feed_discovery(node['mac'], ohai) - node_resource.update({'partitioning': node.partitioning}) dnsmasq = vr.create('dnsmasq_{0}'.format(node.safe_mac), 'resources/dnsmasq', {})[0] From 164d8ebb5e87da6df7175effe907c5a9fab210f9 Mon Sep 17 00:00:00 2001 From: Evgeniy L Date: Thu, 29 Oct 2015 16:07:59 +0300 Subject: [PATCH 10/13] Sync data in brareon-api before starting for provisioning --- examples/provisioning/provision.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/provisioning/provision.py b/examples/provisioning/provision.py index 61bd3fe8..bd39d31c 100755 --- a/examples/provisioning/provision.py +++ b/examples/provisioning/provision.py @@ -8,6 +8,7 @@ from solar.events.controls import React discovery_service = 'http://0.0.0.0:8881' bareon_service = 'http://0.0.0.0:9322/v1/nodes/{0}/partitioning' +bareon_sync = 'http://0.0.0.0:9322/v1/actions/sync_all' class NodeAdapter(dict): @@ -26,6 +27,10 @@ class NodeAdapter(dict): def partitioning(self): return requests.get(bareon_service.format(self['mac'])).json() +# Sync hw info about nodes from discovery service into bareon-api +requests.post(bareon_sync) + +# Get list of nodes from discovery service nodes_list = requests.get(discovery_service).json() # Create slave node resources From 5f17cadcb5284452f98f4f5ea6d046ef81bf12fa Mon Sep 17 00:00:00 2001 From: Evgeniy L Date: Thu, 29 Oct 2015 18:20:10 +0300 Subject: [PATCH 11/13] Add workaround for bareon-api installation since pbr does not work with git sources --- bootstrap/playbooks/pxe.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bootstrap/playbooks/pxe.yaml b/bootstrap/playbooks/pxe.yaml index 001a0270..6cfbbea4 100644 --- a/bootstrap/playbooks/pxe.yaml +++ b/bootstrap/playbooks/pxe.yaml @@ -57,5 +57,7 @@ - shell: 'discovery-scan --ssh_key {{insecure_pub_key_path}} &' # Install bareon-api + # Workaround is required because pbr does not handle git-eggs correctly and fails to install fuel-agent + - shell: 'pip install git+git://github.com/prmtl/fuel-agent.git@detach_from_nailgun#egg=fuel_agent' - shell: pip install git+https://github.com/Mirantis/bareon-api.git - shell: 'bareon-api &' From 55ca3434cf44ccb08b34e82fa852495a48894aaa Mon Sep 17 00:00:00 2001 From: Evgeniy L Date: Thu, 29 Oct 2015 18:20:50 +0300 Subject: [PATCH 12/13] Add nat rules for solar-dev to provide internet connectivity for slaves --- bootstrap/playbooks/pxe.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bootstrap/playbooks/pxe.yaml b/bootstrap/playbooks/pxe.yaml index 6cfbbea4..f810d52a 100644 --- a/bootstrap/playbooks/pxe.yaml +++ b/bootstrap/playbooks/pxe.yaml @@ -61,3 +61,6 @@ - shell: 'pip install git+git://github.com/prmtl/fuel-agent.git@detach_from_nailgun#egg=fuel_agent' - shell: pip install git+https://github.com/Mirantis/bareon-api.git - shell: 'bareon-api &' + + # Add nat rules so slaves have internet access via solar-dev + - shell: iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE From 9f37e610fd30dbe28c40d65fa7b1e7ca9facc3b4 Mon Sep 17 00:00:00 2001 From: Evgeniy L Date: Thu, 29 Oct 2015 20:19:53 +0300 Subject: [PATCH 13/13] Run services under supervisor --- bootstrap/playbooks/files/supervisor.conf | 4 ++++ bootstrap/playbooks/pxe.yaml | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 bootstrap/playbooks/files/supervisor.conf diff --git a/bootstrap/playbooks/files/supervisor.conf b/bootstrap/playbooks/files/supervisor.conf new file mode 100644 index 00000000..b30f0944 --- /dev/null +++ b/bootstrap/playbooks/files/supervisor.conf @@ -0,0 +1,4 @@ +[program:{{name}}] +command={{cmd}} +redirect_stderr=true +stdout_logfile=/var/log/{{name}}.log diff --git a/bootstrap/playbooks/pxe.yaml b/bootstrap/playbooks/pxe.yaml index f810d52a..b8ffe395 100644 --- a/bootstrap/playbooks/pxe.yaml +++ b/bootstrap/playbooks/pxe.yaml @@ -15,6 +15,7 @@ image_builder_path: /tmp/image_builder http_ip: 10.0.0.2 http_port: 8000 + supervisor_dir: /etc/supervisor/conf.d/ tasks: # Istall and configure dnsmasq @@ -53,14 +54,25 @@ # Install discovery service - shell: pip install git+https://github.com/rustyrobot/discovery.git - - shell: 'discovery &' - - shell: 'discovery-scan --ssh_key {{insecure_pub_key_path}} &' # Install bareon-api # Workaround is required because pbr does not handle git-eggs correctly and fails to install fuel-agent - shell: 'pip install git+git://github.com/prmtl/fuel-agent.git@detach_from_nailgun#egg=fuel_agent' - shell: pip install git+https://github.com/Mirantis/bareon-api.git - - shell: 'bareon-api &' + + # Install and configure supervisor + - apt: name=supervisor state=present + + - set_fact: {'name': 'discovery', 'cmd': 'discovery'} + - template: src=files/supervisor.conf dest={{supervisor_dir}}/discovery.conf + + - set_fact: {'name': 'discovery-scan', 'cmd': 'discovery-scan --ssh_key /vagrant/tmp/keys/ssh_private'} + - template: src=files/supervisor.conf dest={{supervisor_dir}}/discovery-scan.conf + + - set_fact: {'name': 'bareon-api', 'cmd': 'bareon-api'} + - template: src=files/supervisor.conf dest={{supervisor_dir}}/bareon-api.conf + + - service: name=supervisor state=restarted # Add nat rules so slaves have internet access via solar-dev - shell: iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE