Working mariadb -> keystone -> haproxy connections

This commit is contained in:
Evgeniy L 2015-06-02 14:23:47 +02:00
parent 2a4bfaa421
commit 08a0c0a177
23 changed files with 126 additions and 54 deletions

2
Vagrantfile vendored
View File

@ -3,7 +3,7 @@
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
SLAVES_COUNT = 2
SLAVES_COUNT = 3
init_script = <<SCRIPT
apt-get update

30
example.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
set -eux
rm /vagrant/tmp/storage/* || true
rm /vagrant/tmp/connections.yaml || true
find /vagrant/solar/solar -name '*.pyc' -delete || true
sudo docker stop $(sudo docker ps -q) || true
solar profile -c -t env/test_env -i prf1
solar discover
solar assign -n 'node/node_2 | node/node_1' -r 'resources/docker'
solar assign -n 'node/node_1' -r 'resources/mariadb'
solar assign -n 'node/node_1' -r 'resources/keystone'
solar assign -n 'node/node_1' -r 'resources/haproxy'
solar connect --profile prf1
solar run -a run -t 'resources/docker'
solar run -a run -t 'resource/mariadb_service'
solar run -a run -t 'resource/mariadb_keystone_db'
solar run -a run -t 'resource/mariadb_keystone_user'
solar run -a run -t 'resource/keystone_config'
solar run -a run -t 'resource/keystone_service'
solar run -a run -t 'resource/haproxy_config'
solar run -a run -t 'resources/haproxy'

View File

@ -1,5 +1,5 @@
- hosts: [resource/docker]
- hosts: [{{ ip }}]
sudo: yes
tasks:
- shell: docker --version

View File

@ -4,9 +4,13 @@ version: 1.0.0
input:
ip:
schema: str!
value:
ssh_user:
schema: str!
value:
ssh_key:
schema: str!
value:
input-types:
tags: [resource/docker]
tags: [resources/docker]

View File

@ -1,4 +1,4 @@
id: haproxy
id: haproxy_config
handler: ansible
version: 1.0.0
input:
@ -27,4 +27,4 @@ input:
schema: str!
value:
tags: [resources/haproxy]
tags: [resources/haproxy, resource/haproxy_config]

View File

@ -10,9 +10,9 @@ input:
value: 9999
ports:
schema: [{value: int}]
value:
value: []
servers:
schema: [{value: str}]
value:
value: []
tags: [resources/haproxy, resource/haproxy_keystone_config]

View File

@ -8,7 +8,7 @@ input:
value: /etc/solar/keystone
admin_token:
schema: str!
value:
value: admin
db_password:
schema: str!
value: password

View File

@ -10,10 +10,10 @@ input:
value: /etc/solar/keystone
port:
schema: int!
value:
value: 5000
admin_port:
schema: int!
value:
value: 35357
ip:
schema: str!
value:

View File

@ -1,4 +1,4 @@
id: mariadb_table
id: mariadb_keystone_db
handler: ansible
version: 1.0.0
actions:
@ -7,16 +7,16 @@ actions:
input:
db_name:
schema: str!
value:
value: keystone_db
login_user:
schema: str!
value: root
login_password:
schema: str!
value:
login_port:
schema: int!
value:
login_user:
schema: str!
value:
ip:
schema: str!
value:
@ -27,4 +27,4 @@ input:
schema: str!
value:
tags: [resource/mariadb_table, resources/mariadb]
tags: [resource/mariadb_keystone_db, resources/mariadb]

View File

@ -1,4 +1,4 @@
id: mariadb_user
id: mariadb_keystone_user
handler: ansible
version: 1.0.0
actions:
@ -7,10 +7,10 @@ actions:
input:
new_user_password:
schema: str!
value:
value: keystone
new_user_name:
schema: str!
value:
value: keystone
db_name:
schema: str!
value:
@ -33,5 +33,5 @@ input:
schema: str!
value:
tags: [resource/mariadb_user, resources/mariadb]
tags: [resource/mariadb_keystone_user, resources/mariadb]

View File

@ -10,3 +10,9 @@
- {{ port }}:3306
env:
MYSQL_ROOT_PASSWORD: {{ root_password }}
- shell: docker exec -t {{ name }} mysql -p{{ root_password }} -uroot -e "SELECT 1"
register: result
until: result.rc == 0
retries: 20
delay: 0.5

View File

@ -1,4 +1,4 @@
id: mariadb
id: mariadb_service
handler: ansible
version: 1.0.0
input:
@ -21,4 +21,4 @@ input:
schema: str!
value:
tags: [resource/mariadb, resources/mariadb]
tags: [resource/mariadb_service, resources/mariadb]

View File

@ -74,6 +74,12 @@ class Cmd(object):
parser.add_argument('-n', '--nodes')
parser.add_argument('-r', '--resources')
# Run action on tags
parser = self.subparser.add_parser('run')
parser.set_defaults(func=getattr(self, 'run'))
parser.add_argument('-t', '--tags')
parser.add_argument('-a', '--action')
# Perform resources connection
parser = self.subparser.add_parser('connect')
parser.set_defaults(func=getattr(self, 'connect'))
@ -81,6 +87,18 @@ class Cmd(object):
'-p',
'--profile')
def run(self, args):
from solar.core import actions
from solar.core import signals
resources = filter(
lambda r: Expression(args.tags, r.get('tags', [])).evaluate(),
self.db.get_list('resource'))
for resource in resources:
resource_obj = self.db.get_obj_resource(resource['id'])
actions.resource_action(resource_obj, args.action)
def profile(self, args):
if args.create:
params = {'tags': args.tags, 'id': args.id}
@ -107,6 +125,7 @@ class Cmd(object):
lambda r: Expression(args.resources, r.get('tags', [])).evaluate(),
self._get_resources_list())
print("For {0} nodes assign {1} resources".format(len(nodes), len(resources)))
assign_resources_to_nodes(resources, nodes)
def _get_resources_list(self):

View File

@ -36,8 +36,8 @@ class ResourcesConnectionGraph(object):
def iter_connections(self):
for connection in self.connections:
connections_from = self.resources_with_tags(depends_on(connection))
connections_to = self.resources_with_tags(connection['for_resources'])
connections_to = self.resources_with_tags(depends_on(connection))
connections_from = self.resources_with_tags(connection['for_resources'])
mapping = self.make_mapping(connection)
for connection_from in connections_from:

View File

@ -16,11 +16,6 @@ class Ansible(BaseHandler):
print 'EXECUTING: ', ' '.join(call_args)
subprocess.call(call_args)
#def _get_connection(self, resource):
# return {'ssh_user': '',
# 'ssh_key': '',
# 'host': ''}
def _create_inventory(self, r):
directory = self.dirs[r.name]
inventory_path = os.path.join(directory, 'inventory')

View File

@ -10,33 +10,51 @@ extensions:
tags: {{tags}}
connections:
- for_resources: [resource/keystone_config]
filter_resources: [resource/mariadb]
- for_resources: [resource/mariadb_service]
filter_resources: [resource/mariadb_keystone_db, resource/mariadb_keystone_user]
mapping:
root_password: login_password
port: login_port
- for_resources: [resource/mariadb_keystone_db]
filter_resources: [resource/mariadb_keystone_user]
mapping:
db_name: db_name
- for_resources: [resource/mariadb_service]
filter_resources: [resource/keystone_config]
mapping:
ip: db_host
root_password: db_password
port: db_port
- for_resources: [resource/keystone_service]
filter_resources: [resources/haproxy]
- for_resources: [resource/mariadb_keystone_user]
filter_resources: [resource/keystone_config]
mapping:
servers: ip
ports: admin_port
db_name: db_name
new_user_name: db_user
new_user_password: db_password
# NOTE(dshulyak) it is mandatory for some profiles to user graph based
# api to provide order of execution for different events
run:
- containers.actions.clean_list
- docker.actions.run
- mariadb.actions.run
- mariadb.actions.wait
- mariadb.actions.users
- keystone.actions.run
- haproxy.actions.run
- containers.actions.ensure
- for_resources: [resource/keystone_config]
filter_resources: [resource/keystone_service]
mapping:
config_dir: config_dir
remove:
- haproxy.actions.remove
- keystone.actions.remove
- mariadb.actions.remove
- docker.actions.remove
- for_resources: [resource/keystone_service]
filter_resources: [resource/haproxy_keystone_config]
mapping:
ip: servers
port: ports
- for_resources: [resource/haproxy_keystone_config]
filter_resources: [resource/haproxy_config]
mapping:
listen_port: listen_ports
name: configs_names
ports: configs_ports
servers: configs
- for_resources: [resource/haproxy_config]
filter_resources: [resource/haproxy_service]
mapping:
listen_ports: ports
config_dir: host_binds