Merge pull request #289 from prmtl/nodes_ohai

[PoC] get info from ohai and use "new" paritioning
This commit is contained in:
Łukasz Oleś 2015-10-30 15:18:12 +01:00
commit db0246d951
8 changed files with 68 additions and 17 deletions

View File

@ -0,0 +1,4 @@
[program:{{name}}]
command={{cmd}}
redirect_stderr=true
stdout_logfile=/var/log/{{name}}.log

View File

@ -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

View File

@ -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)

View File

@ -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|<ROOT>|${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

View File

@ -21,5 +21,8 @@ input:
schema: str!
value: $uuid
reverse: True
partitioning:
schema: dict!
value:
tags: [resources=node]

View File

@ -1,2 +1,4 @@
[DEFAULT]
debug=true
nc_template_path=<ROOT>/templates/cloud-init-templates/
log_file=/var/log/fuel-agent.log

View File

@ -1,4 +1,5 @@
{
"partitioning": {{ partitioning | to_pretty_json }},
"profile": "ubuntu_1404_x86_64",
"name_servers_search": "\"example.com\"",
"uid": "2",

View File

@ -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)