当前位置: 首页>>代码示例>>Python>>正文


Python shade.operator_cloud函数代码示例

本文整理汇总了Python中shade.operator_cloud函数的典型用法代码示例。如果您正苦于以下问题:Python operator_cloud函数的具体用法?Python operator_cloud怎么用?Python operator_cloud使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了operator_cloud函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

 def setUp(self):
     super(TestDomain, self).setUp()
     self.cloud = shade.operator_cloud(cloud='devstack-admin')
     if self.cloud.cloud_config.get_api_version('identity') in ('2', '2.0'):
         self.skipTest('Identity service does not support domains')
     self.domain_prefix = self.getUniqueString('domain')
     self.addCleanup(self._cleanup_domains)
开发者ID:erickcantwell,项目名称:shade,代码行数:7,代码来源:test_domain.py

示例2: test_update_user_password

    def test_update_user_password(self):
        user_name = self.user_prefix + '_password'
        user_email = '[email protected]'
        user = self._create_user(name=user_name,
                                 email=user_email,
                                 password='old_secret')
        self.assertIsNotNone(user)
        self.assertTrue(user['enabled'])

        # This should work for both v2 and v3
        new_user = self.operator_cloud.update_user(
            user['id'], password='new_secret')
        self.assertIsNotNone(new_user)
        self.assertEqual(user['id'], new_user['id'])
        self.assertEqual(user_name, new_user['name'])
        self.assertEqual(user_email, new_user['email'])
        self.assertTrue(new_user['enabled'])
        self.assertTrue(self.operator_cloud.grant_role(
            'Member', user=user['id'], project='demo', wait=True))
        self.addCleanup(
            self.operator_cloud.revoke_role,
            'Member', user=user['id'], project='demo', wait=True)
        self.assertIsNotNone(operator_cloud(
            cloud=self._demo_name,
            username=user_name, password='new_secret').keystone_client)
开发者ID:dbckz,项目名称:shade,代码行数:25,代码来源:test_users.py

示例3: get_cloud

    def get_cloud(self):
        """ Get shade openstack and operator cloud objects

        :return: cloud, opcloud are the shade openstack and operator objects
        """
        cloud = shade.openstack_cloud()
        opcloud = shade.operator_cloud()
        return cloud, opcloud
开发者ID:LIP-Computing,项目名称:openstack-nagios-plugins,代码行数:8,代码来源:openstacknagios.py

示例4: main

def main():
    argument_spec = openstack_full_argument_spec(
        state        = dict(required=False, default='present',
                            choices=['absent', 'present']),
        name         = dict(required=True),
        host         = dict(required=True),
    )

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(
        argument_spec,
        supports_check_mode=True, **module_kwargs)

    if not HAS_SHADE:
        module.fail_json(msg='shade is required for this module')

    state = module.params['state']
    name = module.params['name']
    hostname_or_id = module.params['host']

    try:
        cloud = shade.operator_cloud(**module.params)
        agg = _get_aggregate(cloud, name)
        host = _get_host(cloud, hostname_or_id)

        if module.check_mode:
            module.exit_json(changed=_system_state_change(module, agg, host))

        if state == 'present':
            for resource in ((host, hostname_or_id), (agg, name)):
                if not resource[0]:
                    module.fail_json(msg="No matches found for %s" %
                                     resource[1])
            if not _host_exists(agg, host):
                agg = cloud.nova_client.aggregates.add_host(
                        aggregate=agg,
                        host=host.service['host'])
                changed=True
            else:
                changed=False

            module.exit_json(changed=changed,
                             agg=agg.to_dict(),
                             hosts=agg.hosts)

        elif state == 'absent':
            if not host or not agg:
                module.exit_json(changed=False)
            elif _host_exists(agg, host):
                agg = cloud.nova_client.aggregates.remove_host(
                        aggregate=agg,
                        host=host.service['host'])
                module.exit_json(changed=True)
            else:
                module.exit_json(changed=False)

    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
开发者ID:1anch,项目名称:ursula,代码行数:58,代码来源:os_nova_host_agg_host.py

示例5: setUp

    def setUp(self):
        super(TestServices, self).setUp()
        self.operator_cloud = operator_cloud(cloud='devstack-admin')

        # Generate a random name for services in this test
        self.new_service_name = 'test_' + ''.join(
            random.choice(string.ascii_lowercase) for _ in range(5))

        self.addCleanup(self._cleanup_services)
开发者ID:erickcantwell,项目名称:shade,代码行数:9,代码来源:test_services.py

示例6: setUp

    def setUp(self):
        super(TestFlavor, self).setUp()
        self.demo_cloud = shade.openstack_cloud(cloud="devstack")
        self.operator_cloud = shade.operator_cloud(cloud="devstack-admin")

        # Generate a random name for flavors in this test
        self.new_item_name = "flavor_" + "".join(random.choice(string.ascii_lowercase) for _ in range(5))

        self.addCleanup(self._cleanup_flavors)
开发者ID:jhedden,项目名称:shade,代码行数:9,代码来源:test_flavor.py

示例7: main

def main():

    argument_spec = openstack_full_argument_spec(
        name=dict(required=True),
        description=dict(default=None),
        enabled=dict(default=True, type="bool"),
        state=dict(default="present", choices=["absent", "present"]),
    )

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec, supports_check_mode=True, **module_kwargs)

    if not HAS_SHADE:
        module.fail_json(msg="shade is required for this module")

    name = module.params["name"]
    description = module.params["description"]
    enabled = module.params["enabled"]
    state = module.params["state"]

    try:
        cloud = shade.operator_cloud(**module.params)

        domains = cloud.search_domains(filters=dict(name=name))

        if len(domains) > 1:
            module.fail_json(msg="Domain name %s is not unique" % name)
        elif len(domains) == 1:
            domain = domains[0]
        else:
            domain = None

        if module.check_mode:
            module.exit_json(changed=_system_state_change(module, domain))

        if state == "present":
            if domain is None:
                domain = cloud.create_domain(name=name, description=description, enabled=enabled)
                changed = True
            else:
                if _needs_update(module, domain):
                    domain = cloud.update_domain(domain.id, name=name, description=description, enabled=enabled)
                    changed = True
                else:
                    changed = False
            module.exit_json(changed=changed, domain=domain, id=domain.id)

        elif state == "absent":
            if domain is None:
                changed = False
            else:
                cloud.delete_domain(domain.id)
                changed = True
            module.exit_json(changed=changed)

    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
开发者ID:2ndQuadrant,项目名称:ansible,代码行数:57,代码来源:os_keystone_domain.py

示例8: _build_client

def _build_client(module):
    """Create and return an Ironic inspector client."""
    cloud = shade.operator_cloud(**module.params)
    session = cloud.cloud_config.get_session()
    client = ironic_inspector_client.v1.ClientV1(
        inspector_url=module.params['inspector_url'],
        session=session, region_name=module.params['region_name'],
        api_version=ironic_inspector_client.v1.MAX_API_VERSION)
    return client
开发者ID:pforai,项目名称:kayobe,代码行数:9,代码来源:os_ironic_inspector_rule.py

示例9: main

def main():
    argument_spec = openstack_full_argument_spec(
        password=dict(required=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.operator_cloud(**module.params)

        for _project in cloud.keystone_client.projects.list():
            if _project.name == project_name:
                project = _project

        for _role in cloud.keystone_client.roles.list():
            if _role.name == role_name:
                role = _role

        for _user in cloud.keystone_client.users.list():
            if _user.name == user_name:
                user = _user

        if not project:
            changed = True
            project = cloud.keystone_client.projects.create(
                name=project_name, domain='default')

        if not role:
            changed = True
            role = cloud.keystone_client.roles.create(name=role_name)

        if not user:
            changed = True
            user = cloud.keystone_client.users.create(name=user_name,
                                                      password=password,
                                                      project=project)
            cloud.keystone_client.roles.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()))
开发者ID:Beanking77,项目名称:kolla,代码行数:56,代码来源:kolla_keystone_user.py

示例10: setUp

    def setUp(self):
        super(TestServices, self).setUp()
        # Shell should have OS-* envvars from openrc, typically loaded by job
        self.operator_cloud = operator_cloud()

        # Generate a random name for services in this test
        self.new_service_name = 'test_' + ''.join(
            random.choice(string.ascii_lowercase) for _ in range(5))

        self.addCleanup(self._cleanup_services)
开发者ID:adreznec,项目名称:shade,代码行数:10,代码来源:test_services.py

示例11: setUp

    def setUp(self):
        super(TestFlavor, self).setUp()
        # Shell should have OS-* envvars from openrc, typically loaded by job
        self.operator_cloud = shade.operator_cloud()

        # Generate a random name for flavors in this test
        self.new_item_name = 'flavor_' + ''.join(
            random.choice(string.ascii_lowercase) for _ in range(5))

        self.addCleanup(self._cleanup_flavors)
开发者ID:jsmartin,项目名称:shade,代码行数:10,代码来源:test_flavor.py

示例12: main

def main():
    argument_spec = openstack_full_argument_spec(
        name=dict(required=True),
        description=dict(required=False, default=None),
        domain_id=dict(required=False, default=None),
        state=dict(default='present', choices=['absent', 'present']),
    )

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec,
                           supports_check_mode=True,
                           **module_kwargs)

    if not HAS_SHADE:
        module.fail_json(msg='shade is required for this module')

    name = module.params.pop('name')
    description = module.params.pop('description')
    domain_id = module.params.pop('domain_id')
    state = module.params.pop('state')

    try:
        cloud = shade.operator_cloud(**module.params)
        if domain_id:
            group = cloud.get_group(name, filters={'domain_id': domain_id})
        else:
            group = cloud.get_group(name)

        if module.check_mode:
            module.exit_json(changed=_system_state_change(state, description, group))

        if state == 'present':
            if group is None:
                group = cloud.create_group(
                    name=name, description=description, domain=domain_id)
                changed = True
            else:
                if description is not None and group.description != description:
                    group = cloud.update_group(
                        group.id, description=description)
                    changed = True
                else:
                    changed = False
            module.exit_json(changed=changed, group=group)

        elif state == 'absent':
            if group is None:
                changed=False
            else:
                cloud.delete_group(group.id)
                changed=True
            module.exit_json(changed=changed)

    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
开发者ID:ernstp,项目名称:ansible,代码行数:55,代码来源:os_group.py

示例13: main

def main():
    argument_spec = openstack_full_argument_spec(
        auth_type=dict(required=False),
        uuid=dict(required=False),
        name=dict(required=False),
        mac=dict(required=False),
        ironic_url=dict(required=False),
        timeout=dict(default=1200, type='int', required=False),
    )
    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec, **module_kwargs)

    if not HAS_SHADE:
        module.fail_json(msg='shade is required for this module')
    if StrictVersion(shade.__version__) < StrictVersion('1.0.0'):
        module.fail_json(msg="To utilize this module, the installed version of"
                             "the shade library MUST be >=1.0.0")

    if (module.params['auth_type'] in [None, 'None'] and
            module.params['ironic_url'] is None):
        module.fail_json(msg="Authentication appears to be disabled, "
                             "Please define an ironic_url parameter")

    if (module.params['ironic_url'] and
            module.params['auth_type'] in [None, 'None']):
        module.params['auth'] = dict(
            endpoint=module.params['ironic_url']
        )

    try:
        cloud = shade.operator_cloud(**module.params)

        if module.params['name'] or module.params['uuid']:
            server = cloud.get_machine(_choose_id_value(module))
        elif module.params['mac']:
            server = cloud.get_machine_by_mac(module.params['mac'])
        else:
            module.fail_json(msg="The worlds did not align, "
                                 "the host was not found as "
                                 "no name, uuid, or mac was "
                                 "defined.")
        if server:
            cloud.inspect_machine(server['uuid'], module.params['wait'])
            # TODO(TheJulia): diff properties, ?and ports? and determine
            # if a change occurred.  In theory, the node is always changed
            # if introspection is able to update the record.
            module.exit_json(changed=True,
                             ansible_facts=server['properties'])

        else:
            module.fail_json(msg="node not found.")

    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
开发者ID:ernstp,项目名称:ansible,代码行数:54,代码来源:os_ironic_inspect.py

示例14: main

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'),
        admin_url=dict(required=True, type='str'),
        internal_url=dict(required=True, type='str'),
        public_url=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')
        admin_url = module.params.pop('admin_url')
        internal_url = module.params.pop('internal_url')
        public_url = module.params.pop('public_url')
        endpoint_region = module.params.pop('endpoint_region')

        changed = False
        service = None
        endpoint = None

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

        for _service in cloud.keystone_client.services.list():
            if _service.type == service_type:
                service = _service

        if service is not None:
            for _endpoint in cloud.keystone_client.endpoints.list():
                if _endpoint.service_id == service.id:
                    endpoint = _endpoint
        else:
            service = cloud.keystone_client.services.create(
                name=service_name,
                service_type=service_type,
                description=description)

        if endpoint is None:
            changed = True
            cloud.keystone_client.endpoints.create(
                service_id=service.id,
                adminurl=admin_url,
                internalurl=internal_url,
                publicurl=public_url,
                region=endpoint_region)

        module.exit_json(changed=changed)
    except Exception as e:
        module.exit_json(failed=True, changed=True, msg=e)
开发者ID:danycaiti,项目名称:kolla,代码行数:53,代码来源:kolla_keystone_service.py

示例15: main

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.operator_cloud(**module.params)

        for _service in cloud.keystone_client.services.list():
            if _service.type == service_type:
                service = _service

        if service is not None:
            for _endpoint in cloud.keystone_client.endpoints.list():
                if _endpoint.service_id == service.id and \
                   _endpoint.interface == interface:
                    endpoint = _endpoint
        else:
            service = cloud.keystone_client.services.create(
                name=service_name,
                service_type=service_type,
                description=description)

        if endpoint is None:
            changed = True
            cloud.keystone_client.endpoints.create(
                service=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()))
开发者ID:Beanking77,项目名称:kolla,代码行数:52,代码来源:kolla_keystone_service.py


注:本文中的shade.operator_cloud函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。