def main():
    argument_spec = openstack_full_argument_spec(password=dict(required=True,
                                                               no_log=True,
                                                               type='str'),
                                                 project=dict(required=True,
                                                              type='str'),
                                                 role=dict(required=True,
                                                           type='str'),
                                                 user=dict(required=True,
                                                           type='str'))
    module = AnsibleModule(argument_spec)

    try:
        password = module.params.pop('password')
        project_name = module.params.pop('project')
        role_name = module.params.pop('role')
        user_name = module.params.pop('user')

        changed = False
        project = None
        role = None
        user = None

        cloud = shade.OperatorCloud(**module.params)

        for _project in cloud.search_projects():
            if _project.name == project_name:
                project = _project

        for _role in cloud.search_roles():
            if _role.name == role_name:
                role = _role

        for _user in cloud.search_users():
            if _user.name == user_name:
                user = _user

        if not project:
            changed = True
            project = cloud.create_project(project_name, domain_id='default')

        if not role:
            changed = True
            role = cloud.create_role(role_name)

        if not user:
            changed = True
            user = cloud.create_user(user_name,
                                     password=password,
                                     default_project=project,
                                     domain_id='default')
            cloud.grant_role(role, user=user, project=project)

        module.exit_json(changed=changed)
    except Exception:
        module.exit_json(failed=True,
                         changed=True,
                         msg=repr(traceback.format_exc()))
Example #2
0
    def setUp(self):
        super(BaseFunctionalTestCase, self).setUp()

        self.config = occ.OpenStackConfig()
        demo_config = self.config.get_one_cloud(cloud='devstack')
        self.demo_cloud = shade.OpenStackCloud(cloud_config=demo_config,
                                               log_inner_exceptions=True)
        operator_config = self.config.get_one_cloud(cloud='devstack-admin')
        self.operator_cloud = shade.OperatorCloud(cloud_config=operator_config,
                                                  log_inner_exceptions=True)
Example #3
0
File: base.py Project: manics/shade
    def setUp(self):
        super(BaseFunctionalTestCase, self).setUp()

        demo_name = os.environ.get('SHADE_DEMO_CLOUD', 'devstack')
        op_name = os.environ.get('SHADE_OPERATOR_CLOUD', 'devstack-admin')

        self.config = occ.OpenStackConfig()
        demo_config = self.config.get_one_cloud(cloud=demo_name)
        self.demo_cloud = shade.OpenStackCloud(
            cloud_config=demo_config,
            log_inner_exceptions=True)
        operator_config = self.config.get_one_cloud(cloud=op_name)
        self.operator_cloud = shade.OperatorCloud(
            cloud_config=operator_config,
            log_inner_exceptions=True)
#!/usr/bin/python
import shade
from shade import *

simple_logging(debug=True)
#conn=shade.OpenStackCloud(cloud='mordred')
conn = shade.OperatorCloud(cloud='mordred')

# To get the information about available flavours
flavors = conn.list_flavors()
for i in flavors:
    print "printing each flavour information"
    print "printing the mem information %s" % (i['ram'])
    print "printing the cpu information %s" % (i['vcpus'])
    print i

info = conn.get_aggregate("openstack-dev")
print info

op_conn = OperatorCloud(auth_url='http://10.1.4.205:5000/')
machine_info = op_conn.get_machine("test1")
print machine_info

#info = op_conn.get_aggregate("openstack-dev")
#print info
def main():
    argument_spec = openstack_full_argument_spec(
        description=dict(required=True, type='str'),
        service_name=dict(required=True, type='str'),
        service_type=dict(required=True, type='str'),
        url=dict(required=True, type='str'),
        interface=dict(required=True, type='str'),
        endpoint_region=dict(required=True, type='str'))
    module = AnsibleModule(argument_spec)

    try:
        description = module.params.pop('description')
        service_name = module.params.pop('service_name')
        service_type = module.params.pop('service_type')
        url = module.params.pop('url')
        interface = module.params.pop('interface')
        endpoint_region = module.params.pop('endpoint_region')

        changed = False
        service = None
        endpoint = None

        cloud = shade.OperatorCloud(**module.params)

        for _service in cloud.list_services():
            if _service.type == service_type:
                service = _service
                if service.name != service_name or \
                        service.description != description:
                    changed = True
                    cloud.update_service(service,
                                         name=service_name,
                                         description=description)
                break
        else:
            changed = True
            service = cloud.create_service(name=service_name,
                                           service_type=service_type,
                                           description=description)

        for _endpoint in cloud.list_endpoints():
            if _endpoint.service_id == service.id and \
                    _endpoint.interface == interface and \
                    _endpoint.region == endpoint_region:
                endpoint = _endpoint
                if endpoint.url != url:
                    changed = True
                    cloud.update_endpoint(endpoint, url=url)
                break
        else:
            changed = True
            cloud.create_endpoint(service_name_or_id=service.id,
                                  url=url,
                                  interface=interface,
                                  region=endpoint_region)

        module.exit_json(changed=changed)
    except Exception:
        module.exit_json(failed=True,
                         changed=True,
                         msg=repr(traceback.format_exc()))
Example #6
0
 def __init__(self, **kwargs):
     self.cloud = shade.OperatorCloud(os_client_config.get_config(**kwargs))
     self.images = []
     self.flavors = []
Example #7
0
 def _set_operator_cloud(self, **kwargs):
     operator_config = self.config.get_one_cloud(cloud=self._op_name,
                                                 **kwargs)
     self.operator_cloud = shade.OperatorCloud(cloud_config=operator_config,
                                               log_inner_exceptions=True)
Example #8
0
 def _set_operator_cloud(self, **kwargs):
     operator_config = self.config.get_one_cloud(cloud=self._op_name,
                                                 **kwargs)
     self.operator_cloud = shade.OperatorCloud(cloud_config=operator_config)