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


Python shade.operator_cloud方法代码示例

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


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

示例1: main

# 需要导入模块: import shade [as 别名]
# 或者: from shade import operator_cloud [as 别名]
def main():
    module = AnsibleModule(
        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'),
            service=dict(required=True, type='str'),
        )
    )

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

        getattr(SanityChecks, module.params.pop("service"))(cloud)

        module.exit_json(changed=changed)
    except Exception:
        module.exit_json(failed=True, changed=True,
                         msg=repr(traceback.format_exc()))

# import module snippets 
开发者ID:yaoice,项目名称:openstack-deploy,代码行数:25,代码来源:os_sanity.py

示例2: main

# 需要导入模块: import shade [as 别名]
# 或者: from shade import operator_cloud [as 别名]
def main():
    module = AnsibleModule(
        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'),
            service=dict(required=True, type='str'),
        )
    )

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

        getattr(SanityChecks, module.params.pop("service"))(cloud)

        module.exit_json(changed=changed)
    except Exception as e:
        module.exit_json(failed=True, changed=True, msg=e)

# import module snippets 
开发者ID:rthallisey,项目名称:kolla-kubernetes-personal,代码行数:24,代码来源:kolla_sanity.py

示例3: main

# 需要导入模块: import shade [as 别名]
# 或者: from shade import operator_cloud [as 别名]
def main():
    module = AnsibleModule(
        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'),
            service=dict(required=True, type='str'),
        )
    )

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

        getattr(SanityChecks, module.params.pop("service"))(cloud)

        module.exit_json(changed=changed)
    except Exception:
        module.exit_json(failed=True, changed=True,
                         msg=repr(traceback.format_exc()))

# import module snippets 
开发者ID:coolsvap,项目名称:kolla-images,代码行数:25,代码来源:kolla_sanity.py

示例4: main

# 需要导入模块: import shade [as 别名]
# 或者: from shade import operator_cloud [as 别名]
def main():

    argument_spec = openstack_full_argument_spec(
        name=dict(required=False, default=None),
        filters=dict(required=False, type='dict', default=None),
    )
    module_kwargs = openstack_module_kwargs(
        mutually_exclusive=[
            ['name', 'filters'],
        ]
    )
    module = AnsibleModule(argument_spec, **module_kwargs)

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

    try:
        name = module.params['name']
        filters = module.params['filters']

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

        if name:
            # Let's suppose user is passing domain ID
            try:
                domains = cloud.get_domain(name)
            except:
                domains = opcloud.search_domains(filters={'name': name})

        else:
            domains = opcloud.search_domains(filters)

        module.exit_json(changed=False, ansible_facts=dict(
            openstack_domains=domains))

    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e)) 
开发者ID:YoLoveLife,项目名称:DevOps,代码行数:39,代码来源:os_keystone_domain_facts.py

示例5: _build_client

# 需要导入模块: import shade [as 别名]
# 或者: from shade import operator_cloud [as 别名]
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:stackhpc,项目名称:kayobe,代码行数:11,代码来源:os_ironic_inspector_rule.py

示例6: main

# 需要导入模块: import shade [as 别名]
# 或者: from shade import operator_cloud [as 别名]
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 as e:
        module.exit_json(failed=True, changed=True, msg=e)

# import module snippets 
开发者ID:rthallisey,项目名称:kolla-kubernetes-personal,代码行数:55,代码来源:kolla_keystone_service.py

示例7: main

# 需要导入模块: import shade [as 别名]
# 或者: from shade import operator_cloud [as 别名]
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 as e:
        module.exit_json(failed=True, changed=True, msg=e)

# import module snippets 
开发者ID:rthallisey,项目名称:kolla-kubernetes-personal,代码行数:59,代码来源:kolla_keystone_user.py

示例8: main

# 需要导入模块: import shade [as 别名]
# 或者: from shade import operator_cloud [as 别名]
def main():
    argument_spec = openstack_full_argument_spec(
        user=dict(required=True),
        group=dict(required=True),
        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')

    user = module.params['user']
    group = module.params['group']
    state = module.params['state']

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

        in_group = cloud.is_user_in_group(user, group)

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

        changed = False
        if state == 'present':
            if not in_group:
                cloud.add_user_to_group(user, group)
                changed = True

        elif state == 'absent':
            if in_group:
                cloud.remove_user_from_group(user, group)
                changed=True

        module.exit_json(changed=changed)

    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e), extra_data=e.extra_data) 
开发者ID:YoLoveLife,项目名称:DevOps,代码行数:44,代码来源:os_user_group.py

示例9: main

# 需要导入模块: import shade [as 别名]
# 或者: from shade import operator_cloud [as 别名]
def main():
    argument_spec = openstack_full_argument_spec(
        name=dict(required=True),
        description=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')
    state = module.params.pop('state')

    try:
        cloud = shade.operator_cloud(**module.params)
        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)
                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:YoLoveLife,项目名称:DevOps,代码行数:52,代码来源:os_group.py

示例10: main

# 需要导入模块: import shade [as 别名]
# 或者: from shade import operator_cloud [as 别名]
def main():
    argument_spec = openstack_full_argument_spec(
        name=dict(required=True),
        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')
    state = module.params.pop('state')

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

        role = cloud.get_role(name)

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

        if state == 'present':
            if role is None:
                role = cloud.create_role(name)
                changed = True
            else:
                changed = False
            module.exit_json(changed=changed, role=role)
        elif state == 'absent':
            if role is None:
                changed=False
            else:
                cloud.delete_role(name)
                changed=True
            module.exit_json(changed=changed)

    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e)) 
开发者ID:YoLoveLife,项目名称:DevOps,代码行数:44,代码来源:os_keystone_role.py

示例11: main

# 需要导入模块: import shade [as 别名]
# 或者: from shade import operator_cloud [as 别名]
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 occured.  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))


# this is magic, see lib/ansible/module_common.py 
开发者ID:YoLoveLife,项目名称:DevOps,代码行数:59,代码来源:os_ironic_inspect.py

示例12: main

# 需要导入模块: import shade [as 别名]
# 或者: from shade import operator_cloud [as 别名]
def main():

    argument_spec = openstack_full_argument_spec(
        name=dict(required=False, default=None),
        domain=dict(required=False, default=None),
        filters=dict(required=False, type='dict', default=None),
    )

    module = AnsibleModule(argument_spec)

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

    try:
        name = module.params['name']
        domain = module.params['domain']
        filters = module.params['filters']

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

        if domain:
            try:
                # We assume admin is passing domain id
                dom = opcloud.get_domain(domain)['id']
                domain = dom
            except:
                # If we fail, maybe admin is passing a domain name.
                # Note that domains have unique names, just like id.
                dom = opcloud.search_domains(filters={'name': domain})
                if dom:
                    domain = dom[0]['id']
                else:
                    module.fail_json(msg='Domain name or ID does not exist')

            if not filters:
                filters = {}

            filters['domain_id'] = domain

        users = opcloud.search_users(name,
                                        filters)
        module.exit_json(changed=False, ansible_facts=dict(
            openstack_users=users))

    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e)) 
开发者ID:YoLoveLife,项目名称:DevOps,代码行数:48,代码来源:os_user_facts.py

示例13: main

# 需要导入模块: import shade [as 别名]
# 或者: from shade import operator_cloud [as 别名]
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()))

# import module snippets 
开发者ID:coolsvap,项目名称:kolla-images,代码行数:56,代码来源:kolla_keystone_service.py

示例14: main

# 需要导入模块: import shade [as 别名]
# 或者: from shade import operator_cloud [as 别名]
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()))

# import module snippets 
开发者ID:coolsvap,项目名称:kolla-images,代码行数:60,代码来源:kolla_keystone_user.py


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