From b92672b30e5d978a75f229ff5b71b864b6a6071a Mon Sep 17 00:00:00 2001 From: Dmitry Shulyak Date: Tue, 4 Aug 2015 12:39:09 +0300 Subject: [PATCH] Create multiple containers and add rabbitmq resource on idx=28 --- example-lxc.py | 98 ++++++++++++++++++++++--------- resources/lxc_container/meta.yaml | 9 +++ resources/ssh_key/actions/run.yml | 4 +- resources/ssh_key/meta.yaml | 2 +- 4 files changed, 81 insertions(+), 32 deletions(-) diff --git a/example-lxc.py b/example-lxc.py index e1fd3ed1..91af5a99 100644 --- a/example-lxc.py +++ b/example-lxc.py @@ -1,22 +1,37 @@ import click -import sys -import time -from solar.core import actions -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 import errors from solar.interfaces.db import get_db +from solar.system_log import change +from solar.cli import orch @click.group() def main(): pass +def lxc_template(idx): + return { + 'user': 'root', + 'mgmt_ip': '172.18.11.{}'.format(idx), + 'container_name': 'test{}'.format(idx), + 'inventory_hostname': 'test{}'.format(idx), + 'properties': + {'container_release': 'trusty'}, + 'container_networks': + {'mgmt': { + 'address': '172.18.11.{}'.format(idx), # address for container + 'bridge': 'br-int53', # bridge to attach veth pair + 'bridge_address': '172.18.11.253/24', + 'interface': 'eth1', # interface name in container + 'netmask': '255.255.255.0', + 'type': 'veth'}} + } + + @click.command() def deploy(): db = get_db() @@ -28,7 +43,8 @@ def deploy(): ssh_key = vr.create('ssh_key1', 'resources/ssh_key', { 'path': '/vagrant/.ssh/id_rsa', - 'pub_path': '/vagrant/.ssh/id_rsa.pub' + 'pub_path': '/vagrant/.ssh/id_rsa.pub', + 'passphrase': '', })[0] signals.connect(seed, ssh_key) @@ -67,28 +83,51 @@ def deploy(): lxc_infra1 = vr.create('lxc_infra1', 'resources/lxc_host', {})[0] signals.connect(node1, lxc_infra1) - lxc_host1 = vr.create('lxc_host1', 'resources/lxc_container', { - 'container_name': 'test13', - 'inventory_hostname': 'test13', - 'properties': - {'container_release': 'trusty'}, - 'container_networks': - {'mgmt': { - 'address': '172.18.11.2', # address for container - 'bridge': 'br-int53', # bridge to attach veth pair - 'bridge_address': '172.18.11.253/24', - 'interface': 'eth1', # interface name in container - 'netmask': '255.255.255.0', - 'type': 'veth'}} - })[0] - signals.connect(node1, lxc_host1, { - 'ip': ['ansible_ssh_host', 'physical_host'], - }) - # this is a required to introduce depends on relationship between lxc infre - # and lxc container - signals.connect(lxc_infra1, lxc_host1, {'provides': 'requires'}) - signals.connect(cnets2, lxc_host1) - signals.connect(ssh_key, lxc_host1, {'pub_path': 'pub_key'}) + lxc_hosts = range(28, 35) + hosts_map = {} + for idx in lxc_hosts: + + lxc_host_idx = vr.create( + 'lxc_host{}'.format(idx), + 'resources/lxc_container', lxc_template(idx))[0] + hosts_map[idx] = lxc_host_idx + + signals.connect(node1, lxc_host_idx, { + 'ip': ['ansible_ssh_host', 'physical_host'], + }) + # this is a required to introduce depends on relationship between lxc infre + # and lxc container + signals.connect(lxc_infra1, lxc_host_idx, {'provides': 'requires'}) + signals.connect(cnets2, lxc_host_idx) + signals.connect(ssh_key, lxc_host_idx, { + 'pub_path': 'pub_key', + 'path': 'user_key'}) + + # RABBIT + rabbitmq_service1 = vr.create('rabbitmq_service1', 'resources/rabbitmq_service/', { + 'management_port': 15672, + 'port': 5672, + })[0] + openstack_vhost = vr.create('openstack_vhost', 'resources/rabbitmq_vhost/', { + 'vhost_name': 'openstack' + })[0] + + openstack_rabbitmq_user = vr.create('openstack_rabbitmq_user', 'resources/rabbitmq_user/', { + 'user_name': 'openstack', + 'password': 'openstack_password' + })[0] + + signals.connect(hosts_map[28], rabbitmq_service1, { + 'mgmt_ip': 'ip', + 'user_key': 'ssh_key', + 'user': 'ssh_user'}) + signals.connect(rabbitmq_service1, openstack_vhost) + signals.connect(rabbitmq_service1, openstack_rabbitmq_user) + signals.connect(openstack_vhost, openstack_rabbitmq_user, { + 'vhost_name', + }) + + print change.send_to_orchestration() main.add_command(deploy) @@ -96,3 +135,4 @@ main.add_command(deploy) if __name__ == '__main__': main() +ansible-playbook --module-path /vagrant/library -i /tmp/tmp8bTQzi/tmpGUYX4Bdocker20/inventory /tmp/tmp8bTQzi/tmpGUYX4Bdocker20/runIMUDej \ No newline at end of file diff --git a/resources/lxc_container/meta.yaml b/resources/lxc_container/meta.yaml index 52d33f92..16644fc3 100644 --- a/resources/lxc_container/meta.yaml +++ b/resources/lxc_container/meta.yaml @@ -15,6 +15,15 @@ input: ansible_ssh_host: schema: str! value: + user: + schema: str! + value: + user_key: + schema: str! + value: + mgmt_ip: + schema: str! + value: physical_host: schema: str! value: diff --git a/resources/ssh_key/actions/run.yml b/resources/ssh_key/actions/run.yml index 83073f9b..f8fc1616 100644 --- a/resources/ssh_key/actions/run.yml +++ b/resources/ssh_key/actions/run.yml @@ -4,9 +4,9 @@ # this is default variables, they will be overwritten by resource one vars: path: /vagrant/.ssh/id_rsa - passphrase: containers + passphrase: '' tasks: - stat: path={{path}} register: key - - shell: ssh-keygen -t rsa -f {{path}} -N {{passphrase}} + - shell: ssh-keygen -t rsa -f {{path}} -N "" when: key.stat.exists == False diff --git a/resources/ssh_key/meta.yaml b/resources/ssh_key/meta.yaml index aa480273..ffe71dc1 100644 --- a/resources/ssh_key/meta.yaml +++ b/resources/ssh_key/meta.yaml @@ -20,4 +20,4 @@ input: value: passphrase: schema: str - value: default_passphrase + value: