diff --git a/cli.py b/cli.py index c0f72eef..b65f60f3 100644 --- a/cli.py +++ b/cli.py @@ -7,10 +7,10 @@ import networkx as nx import os import subprocess -from x import actions as xa -from x import deployment as xd -from x import resource as xr -from x import signals as xs +from solar.core import actions as xa +from solar.core import deployment as xd +from solar.core import resource as xr +from solar.core import signals as xs @click.group() diff --git a/example.py b/example.py index 06903f4c..a5b87782 100644 --- a/example.py +++ b/example.py @@ -1,5 +1,6 @@ import shutil import os +import requests import time from solar.core import resource @@ -12,22 +13,22 @@ if os.path.exists('rs'): shutil.rmtree('rs') os.mkdir('rs') -node1 = resource.create('node1', 'resources/ro_node/', 'rs/', {'ip':'10.0.0.3', 'ssh_key' : '/vagrant/tmp/keys/ssh_private', 'ssh_user':'vagrant'}) -node2 = resource.create('node2', 'resources/ro_node/', 'rs/', {'ip':'10.0.0.4', 'ssh_key' : '/vagrant/tmp/keys/ssh_private', 'ssh_user':'vagrant'}) +node1 = resource.create('node1', 'resources/ro_node/', 'rs/', {'ip':'10.0.0.3', 'ssh_key' : '/vagrant/.vagrant/machines/solar-dev2/virtualbox/private_key', 'ssh_user':'vagrant'}) +node2 = resource.create('node2', 'resources/ro_node/', 'rs/', {'ip':'10.0.0.4', 'ssh_key' : '/vagrant/.vagrant/machines/solar-dev3/virtualbox/private_key', 'ssh_user':'vagrant'}) mariadb_service1 = resource.create('mariadb_service1', 'resources/mariadb_service', 'rs/', {'image':'mariadb', 'root_password' : 'mariadb', 'port' : '3306', 'ip': '', 'ssh_user': '', 'ssh_key': ''}) keystone_db = resource.create('keystone_db', 'resources/mariadb_db/', 'rs/', {'db_name':'keystone_db', 'login_password':'', 'login_user':'root', 'login_port': '', 'ip':'', 'ssh_user':'', 'ssh_key':''}) keystone_db_user = resource.create('keystone_db_user', 'resources/mariadb_user/', 'rs/', {'new_user_name' : 'keystone', 'new_user_password' : 'keystone', 'db_name':'', 'login_password':'', 'login_user':'root', 'login_port': '', 'ip':'', 'ssh_user':'', 'ssh_key':''}) keystone_config1 = resource.create('keystone_config1', 'resources/keystone_config/', 'rs/', {'config_dir' : '/etc/solar/keystone', 'ip':'', 'ssh_user':'', 'ssh_key':'', 'admin_token':'admin', 'db_password':'', 'db_name':'', 'db_user':'', 'db_host':''}) -keystone_service1 = resource.create('keystone_service1', 'resources/keystone_service/', 'rs/', {'port':'5001', 'admin_port':'35357', 'ip':'', 'ssh_key':'', 'ssh_user':'', 'config_dir':'', 'config_dir':''}) +keystone_service1 = resource.create('keystone_service1', 'resources/keystone_service/', 'rs/', {'port':'5001', 'admin_port':'35357', 'image': '', 'ip':'', 'ssh_key':'', 'ssh_user':'', 'config_dir':''}) keystone_config2 = resource.create('keystone_config2', 'resources/keystone_config/', 'rs/', {'config_dir' : '/etc/solar/keystone', 'ip':'', 'ssh_user':'', 'ssh_key':'', 'admin_token':'admin', 'db_password':'', 'db_name':'', 'db_user':'', 'db_host':''}) -keystone_service2 = resource.create('keystone_service2', 'resources/keystone_service/', 'rs/', {'port':'5002', 'admin_port':'35357', 'ip':'', 'ssh_key':'', 'ssh_user':'', 'config_dir':'', 'config_dir':''}) +keystone_service2 = resource.create('keystone_service2', 'resources/keystone_service/', 'rs/', {'port':'5002', 'admin_port':'35357', 'image': '', 'ip':'', 'ssh_key':'', 'ssh_user':'', 'config_dir':''}) haproxy_keystone_config = resource.create('haproxy_keystone1_config', 'resources/haproxy_config/', 'rs/', {'name':'keystone_config', 'listen_port':'5000', 'servers':[], 'ports':[]}) -haproxy_config = resource.create('haproxy_config', 'resources/haproxy', 'rs/', {'ip':'', 'ssh_key':'', 'ssh_user':'', 'configs_names':[], 'configs_ports':[], 'listen_ports':[], 'configs':[]}) +haproxy_config = resource.create('haproxy_config', 'resources/haproxy', 'rs/', {'ip':'', 'ssh_key':'', 'ssh_user':'', 'configs_names':[], 'configs_ports':[], 'listen_ports':[], 'configs':[], 'config_dir': ''}) haproxy_service = resource.create('haproxy_service', 'resources/docker_container/', 'rs/', {'image' : 'tutum/haproxy', 'ports': [], 'host_binds': [], 'volume_binds':[], 'ip':'', 'ssh_key':'', 'ssh_user':''}) @@ -71,6 +72,23 @@ signals.connect(node2, haproxy_service) signals.connect(haproxy_config, haproxy_service, {'listen_ports':'ports', 'config_dir':'host_binds'}) +from solar.core import validation + +for r in [node1, + node2, + mariadb_service1, + keystone_db, + keystone_db_user, + keystone_config1, + keystone_service1, + keystone_config2, + keystone_service2, + haproxy_keystone_config, + haproxy_config, + haproxy_service]: + validation.validate_resource(r) + + #run from solar.core import actions @@ -80,6 +98,7 @@ actions.resource_action(keystone_db, 'run') actions.resource_action(keystone_db_user, 'run') actions.resource_action(keystone_config1, 'run') actions.resource_action(keystone_service1, 'run') +actions.resource_action(keystone_config2, 'run') actions.resource_action(keystone_service2, 'run') actions.resource_action(haproxy_config, 'run') actions.resource_action(haproxy_service, 'run') @@ -93,3 +112,9 @@ actions.resource_action(haproxy_service, 'run') #actions.resource_action(keystone_db_user, 'remove') #actions.resource_action(keystone_db, 'remove') #actions.resource_action(mariadb_service1, 'remove') + + +# test working configuration +requests.get('http://%s:%s' % (keystone_service1.args['ip'].value, keystone_service1.args['port'].value)) +requests.get('http://%s:%s' % (keystone_service2.args['ip'].value, keystone_service2.args['port'].value)) +requests.get('http://%s:%s' % (haproxy_service.args['ip'].value, haproxy_service.args['ports'].value[0]['value'][0]['value'])) diff --git a/requirements.txt b/requirements.txt index 9b690cee..a963a8f2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ jinja2==2.7.3 networkx==1.9.1 PyYAML==3.11 jsonschema==2.4.0 +requests==2.7.0 diff --git a/resources/docker_container/actions/run.yml b/resources/docker_container/actions/run.yml index 9156b900..6dc492a7 100644 --- a/resources/docker_container/actions/run.yml +++ b/resources/docker_container/actions/run.yml @@ -9,7 +9,9 @@ net: host ports: {% for port in ports.value %} - - {{ port['value'] }}:{{ port['value'] }} + {% for p in port['value'] %} + - {{ p['value'] }}:{{ p['value'] }} + {% endfor %} {% endfor %} volumes: # TODO: host_binds might need more work diff --git a/resources/docker_container/meta.yaml b/resources/docker_container/meta.yaml index dd54506e..09675015 100644 --- a/resources/docker_container/meta.yaml +++ b/resources/docker_container/meta.yaml @@ -12,10 +12,10 @@ input: schema: [int] value: [] host_binds: - schema: [int] + schema: [[int]] value: [] volume_binds: - schema: [int] + schema: [{src: str, dst: str}] value: [] ssh_user: schema: str! diff --git a/solar/solar/core/deployment.py b/solar/solar/core/deployment.py index b3034ec8..e67f622a 100644 --- a/solar/solar/core/deployment.py +++ b/solar/solar/core/deployment.py @@ -4,9 +4,9 @@ import os import shutil import yaml -from x import db -from x import resource as xr -from x import signals as xs +from solar.core import db +from solar.core import resource as xr +from solar.core import signals as xs def deploy(filename): diff --git a/solar/solar/core/resource.py b/solar/solar/core/resource.py index 4f28651a..df6da373 100644 --- a/solar/solar/core/resource.py +++ b/solar/solar/core/resource.py @@ -27,7 +27,11 @@ class Resource(object): metadata_arg = self.metadata['input'][arg_name] type_ = validation.schema_input_type(metadata_arg.get('schema', 'str')) - self.args[arg_name] = observer.create(type_, self, arg_name, arg_value) + value = arg_value + if not value and metadata_arg['value']: + value = metadata_arg['value'] + + self.args[arg_name] = observer.create(type_, self, arg_name, value) self.changed = [] self.tags = tags or [] diff --git a/solar/solar/test/test_validation.py b/solar/solar/test/test_validation.py index da0da6d0..0e5339bb 100644 --- a/solar/solar/test/test_validation.py +++ b/solar/solar/test/test_validation.py @@ -38,7 +38,6 @@ input: errors = sv.validate_resource(r) self.assertListEqual(errors.keys(), ['value-required']) - def test_input_int_type(self): sample_meta_dir = self.make_resource_meta(""" id: sample