Create multiple containers and add rabbitmq resource on idx=28

This commit is contained in:
Dmitry Shulyak 2015-08-04 12:39:09 +03:00
parent f1ddb454a1
commit b92672b30e
4 changed files with 81 additions and 32 deletions

View File

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

View File

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

View File

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

View File

@ -20,4 +20,4 @@ input:
value:
passphrase:
schema: str
value: default_passphrase
value: