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 2808c1a3..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,8 +54,25 @@ # Install discovery service - shell: pip install git+https://github.com/rustyrobot/discovery.git - - shell: 'discovery &' # 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 diff --git a/examples/provisioning/provision.py b/examples/provisioning/provision.py index 5b58830e..bd39d31c 100755 --- a/examples/provisioning/provision.py +++ b/examples/provisioning/provision.py @@ -1,18 +1,36 @@ #!/usr/bin/env python - 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.events.controls import React from solar.events.api import add_event +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): + + def __getattr__(self, name): + try: + return self[name] + except KeyError: + raise AttributeError(name) + + @property + def safe_mac(self): + return self['mac'].replace(':', '_') + + @property + 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 @@ -23,14 +41,18 @@ 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') + 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'}) + + 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) diff --git a/resources/not_provisioned_node/actions/provision.sh b/resources/not_provisioned_node/actions/provision.sh index ccbdb45c..408d0717 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 --data_driver nailgun_simple --input_data_file "${DIR}"/templates/provisioning.json --config-file "${DIR}"/templates/agent.config 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/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 diff --git a/resources/not_provisioned_node/templates/provisioning.json b/resources/not_provisioned_node/templates/provisioning.json.jinja similarity index 99% rename from resources/not_provisioned_node/templates/provisioning.json rename to resources/not_provisioned_node/templates/provisioning.json.jinja index 6b077189..445f39a3 100644 --- a/resources/not_provisioned_node/templates/provisioning.json +++ 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", 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) -