Create multiple containers and add rabbitmq resource on idx=28
This commit is contained in:
parent
f1ddb454a1
commit
b92672b30e
@ -1,22 +1,37 @@
|
|||||||
import click
|
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 signals
|
||||||
from solar.core import validation
|
|
||||||
from solar.core.resource import virtual_resource as vr
|
from solar.core.resource import virtual_resource as vr
|
||||||
from solar import errors
|
|
||||||
|
|
||||||
from solar.interfaces.db import get_db
|
from solar.interfaces.db import get_db
|
||||||
|
|
||||||
|
from solar.system_log import change
|
||||||
|
from solar.cli import orch
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
def main():
|
def main():
|
||||||
pass
|
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()
|
@click.command()
|
||||||
def deploy():
|
def deploy():
|
||||||
db = get_db()
|
db = get_db()
|
||||||
@ -28,7 +43,8 @@ def deploy():
|
|||||||
|
|
||||||
ssh_key = vr.create('ssh_key1', 'resources/ssh_key', {
|
ssh_key = vr.create('ssh_key1', 'resources/ssh_key', {
|
||||||
'path': '/vagrant/.ssh/id_rsa',
|
'path': '/vagrant/.ssh/id_rsa',
|
||||||
'pub_path': '/vagrant/.ssh/id_rsa.pub'
|
'pub_path': '/vagrant/.ssh/id_rsa.pub',
|
||||||
|
'passphrase': '',
|
||||||
})[0]
|
})[0]
|
||||||
signals.connect(seed, ssh_key)
|
signals.connect(seed, ssh_key)
|
||||||
|
|
||||||
@ -67,28 +83,51 @@ def deploy():
|
|||||||
lxc_infra1 = vr.create('lxc_infra1', 'resources/lxc_host', {})[0]
|
lxc_infra1 = vr.create('lxc_infra1', 'resources/lxc_host', {})[0]
|
||||||
signals.connect(node1, lxc_infra1)
|
signals.connect(node1, lxc_infra1)
|
||||||
|
|
||||||
lxc_host1 = vr.create('lxc_host1', 'resources/lxc_container', {
|
lxc_hosts = range(28, 35)
|
||||||
'container_name': 'test13',
|
hosts_map = {}
|
||||||
'inventory_hostname': 'test13',
|
for idx in lxc_hosts:
|
||||||
'properties':
|
|
||||||
{'container_release': 'trusty'},
|
lxc_host_idx = vr.create(
|
||||||
'container_networks':
|
'lxc_host{}'.format(idx),
|
||||||
{'mgmt': {
|
'resources/lxc_container', lxc_template(idx))[0]
|
||||||
'address': '172.18.11.2', # address for container
|
hosts_map[idx] = lxc_host_idx
|
||||||
'bridge': 'br-int53', # bridge to attach veth pair
|
|
||||||
'bridge_address': '172.18.11.253/24',
|
signals.connect(node1, lxc_host_idx, {
|
||||||
'interface': 'eth1', # interface name in container
|
'ip': ['ansible_ssh_host', 'physical_host'],
|
||||||
'netmask': '255.255.255.0',
|
})
|
||||||
'type': 'veth'}}
|
# this is a required to introduce depends on relationship between lxc infre
|
||||||
})[0]
|
# and lxc container
|
||||||
signals.connect(node1, lxc_host1, {
|
signals.connect(lxc_infra1, lxc_host_idx, {'provides': 'requires'})
|
||||||
'ip': ['ansible_ssh_host', 'physical_host'],
|
signals.connect(cnets2, lxc_host_idx)
|
||||||
})
|
signals.connect(ssh_key, lxc_host_idx, {
|
||||||
# this is a required to introduce depends on relationship between lxc infre
|
'pub_path': 'pub_key',
|
||||||
# and lxc container
|
'path': 'user_key'})
|
||||||
signals.connect(lxc_infra1, lxc_host1, {'provides': 'requires'})
|
|
||||||
signals.connect(cnets2, lxc_host1)
|
# RABBIT
|
||||||
signals.connect(ssh_key, lxc_host1, {'pub_path': 'pub_key'})
|
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)
|
main.add_command(deploy)
|
||||||
|
|
||||||
@ -96,3 +135,4 @@ main.add_command(deploy)
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
ansible-playbook --module-path /vagrant/library -i /tmp/tmp8bTQzi/tmpGUYX4Bdocker20/inventory /tmp/tmp8bTQzi/tmpGUYX4Bdocker20/runIMUDej
|
@ -15,6 +15,15 @@ input:
|
|||||||
ansible_ssh_host:
|
ansible_ssh_host:
|
||||||
schema: str!
|
schema: str!
|
||||||
value:
|
value:
|
||||||
|
user:
|
||||||
|
schema: str!
|
||||||
|
value:
|
||||||
|
user_key:
|
||||||
|
schema: str!
|
||||||
|
value:
|
||||||
|
mgmt_ip:
|
||||||
|
schema: str!
|
||||||
|
value:
|
||||||
physical_host:
|
physical_host:
|
||||||
schema: str!
|
schema: str!
|
||||||
value:
|
value:
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
# this is default variables, they will be overwritten by resource one
|
# this is default variables, they will be overwritten by resource one
|
||||||
vars:
|
vars:
|
||||||
path: /vagrant/.ssh/id_rsa
|
path: /vagrant/.ssh/id_rsa
|
||||||
passphrase: containers
|
passphrase: ''
|
||||||
tasks:
|
tasks:
|
||||||
- stat: path={{path}}
|
- stat: path={{path}}
|
||||||
register: key
|
register: key
|
||||||
- shell: ssh-keygen -t rsa -f {{path}} -N {{passphrase}}
|
- shell: ssh-keygen -t rsa -f {{path}} -N ""
|
||||||
when: key.stat.exists == False
|
when: key.stat.exists == False
|
||||||
|
@ -20,4 +20,4 @@ input:
|
|||||||
value:
|
value:
|
||||||
passphrase:
|
passphrase:
|
||||||
schema: str
|
schema: str
|
||||||
value: default_passphrase
|
value:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user