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 35580bd3f4
5 changed files with 43 additions and 14 deletions

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",