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


Python shade.openstack_cloud方法代码示例

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


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

示例1: main

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

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

    try:
        cloud = shade.openstack_cloud(**module.params)
        networks = cloud.search_networks(module.params['name'],
                                         module.params['filters'])
        module.exit_json(changed=False, ansible_facts=dict(
            openstack_networks=networks))

    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e))

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

示例2: main

# 需要导入模块: import shade [as 别名]
# 或者: from shade import openstack_cloud [as 别名]
def main():
    argument_spec = openstack_full_argument_spec(
        name=dict(required=False, default=None),
        container=dict(required=True),
        filename=dict(required=False, default=None),
        container_access=dict(default='private', choices=['private', 'public']),
        state=dict(default='present', choices=['absent', 'present']),
    )
    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')

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

        changed = process_object(cloud, **module.params)

        module.exit_json(changed=changed)
    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e))

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

示例3: main

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

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

    try:
        cloud = shade.openstack_cloud(**module.params)
        subnets = cloud.search_subnets(module.params['name'],
                                         module.params['filters'])
        module.exit_json(changed=False, ansible_facts=dict(
            openstack_subnets=subnets))

    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e))

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

示例4: main

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

    argument_spec = openstack_full_argument_spec(
        image=dict(required=True),
    )
    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')

    try:
        cloud = shade.openstack_cloud(**module.params)
        image = cloud.get_image(module.params['image'])
        module.exit_json(changed=False, ansible_facts=dict(
            openstack_image=image))

    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e))

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

示例5: run

# 需要导入模块: import shade [as 别名]
# 或者: from shade import openstack_cloud [as 别名]
def run(self, volume_names, variables=None, **kwargs):
        cloud = shade.openstack_cloud()
        volume_attributes = [
            "id",
            "name",
            "display_name",
            "size",
            "description",
        ]

        def get_volume(name_or_id):
            volume = cloud.get_volume(name_or_id)
            if not volume:
                raise AnsibleError(
                    "Could not find volume: {}".format(name_or_id))

            result = {}
            for attribute_name in volume_attributes:
                result[attribute_name] = getattr(volume, attribute_name)
            return result

        return [get_volume(volume_name) for volume_name in volume_names] 
开发者ID:openshift,项目名称:openshift-ansible-contrib,代码行数:24,代码来源:os_cinder.py

示例6: _get_cloud

# 需要导入模块: import shade [as 别名]
# 或者: from shade import openstack_cloud [as 别名]
def _get_cloud(cloud, region, project=None):
    if project:
        domain_id = project.domain_id
        domain_name = project.domain_name
        project_id = project.id
        project_name = project.name
        kwargs = dict(
            project_domain_id=domain_id,
            project_domain_name=domain_name,
            project_id=project_id,
            project_name=project_name,
        )
    else:
        domain_id = domain_name = project_id = project_name = None
        kwargs = {}

    key = _make_cloud_key(
        cloud, region,
        domain_id or domain_name,
        project_id or project_name
    )
    if key not in all_clouds:
        all_clouds[key] = shade.openstack_cloud(
            cloud=cloud, region_name=region,
            debug=True, strict=True, **kwargs)
    return all_clouds[key] 
开发者ID:emonty,项目名称:oaktree,代码行数:28,代码来源:_clouds.py

示例7: main

# 需要导入模块: import shade [as 别名]
# 或者: from shade import openstack_cloud [as 别名]
def main():
    argument_spec = openstack_full_argument_spec(
        size=dict(default=None),
        volume_type=dict(default=None),
        display_name=dict(required=True, aliases=['name']),
        display_description=dict(default=None, aliases=['description']),
        image=dict(default=None),
        snapshot_id=dict(default=None),
        state=dict(default='present', choices=['absent', 'present']),
    )
    module_kwargs = openstack_module_kwargs(
        mutually_exclusive=[
            ['image', 'snapshot_id'],
        ],
    )
    module = AnsibleModule(argument_spec=argument_spec, **module_kwargs)

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

    state = module.params['state']

    if state == 'present' and not module.params['size']:
        module.fail_json(msg="Size is required when state is 'present'")

    try:
        cloud = shade.openstack_cloud(**module.params)
        if state == 'present':
            _present_volume(module, cloud)
        if state == 'absent':
            _absent_volume(module, cloud)
    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e))

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

示例8: main

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

    argument_spec = openstack_full_argument_spec(
        server=dict(required=False),
        detailed=dict(required=False, type='bool'),
    )
    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')

    try:
        cloud = shade.openstack_cloud(**module.params)
        openstack_servers = cloud.list_servers(
            detailed=module.params['detailed'])

        if module.params['server']:
            # filter servers by name
            pattern = module.params['server']
            openstack_servers = [server for server in openstack_servers
                                 if fnmatch.fnmatch(server['name'], pattern)]
        module.exit_json(changed=False, ansible_facts=dict(
            openstack_servers=openstack_servers))

    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e))

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

示例9: __init__

# 需要导入模块: import shade [as 别名]
# 或者: from shade import openstack_cloud [as 别名]
def __init__(self, container_id, cloud_config):
        clouds_dir = path.abspath(cloud_config['config_dir']) 
        chdir(clouds_dir)
        self.__cloud = shade.openstack_cloud(cloud='cslab')
        self.__srv_name = cloud_config['server_name']
        self.__vol_name = cloud_config['volume_name']
        super(OpenstackAtRestEncryptionDriver, self).__init__(container_id) 
开发者ID:giagiannis,项目名称:docker-layer-encryption,代码行数:9,代码来源:core.py

示例10: main

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

    try:
        cloud = shade.openstack_cloud(**module.params)
        secgroup = cloud.get_security_group(name)

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

        changed = False
        if state == 'present':
            if not secgroup:
                secgroup = cloud.create_security_group(name, description)
                changed = True
            else:
                if _needs_update(module, secgroup):
                    secgroup = cloud.update_security_group(
                        secgroup['id'], description=description)
                    changed = True
            module.exit_json(
                changed=changed, id=secgroup['id'], secgroup=secgroup)

        if state == 'absent':
            if secgroup:
                cloud.delete_security_group(secgroup['id'])
                changed = True
            module.exit_json(changed=changed)

    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e))

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

示例11: main

# 需要导入模块: import shade [as 别名]
# 或者: from shade import openstack_cloud [as 别名]
def main():
    argument_spec = openstack_full_argument_spec(
        name            = dict(required=True),
        public_key      = dict(default=None),
        public_key_file = dict(default=None),
        state           = dict(default='present',
                               choices=['absent', 'present']),
    )

    module_kwargs = openstack_module_kwargs(
        mutually_exclusive=[['public_key', 'public_key_file']])

    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']
    public_key = module.params['public_key']

    if module.params['public_key_file']:
        public_key = open(module.params['public_key_file']).read()
        public_key = public_key.rstrip()

    try:
        cloud = shade.openstack_cloud(**module.params)
        keypair = cloud.get_keypair(name)

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

        if state == 'present':
            if keypair and keypair['name'] == name:
                if public_key and (public_key != keypair['public_key']):
                    module.fail_json(
                        msg="Key name %s present but key hash not the same"
                            " as offered. Delete key first." % name
                    )
                else:
                    changed = False
            else:
                keypair = cloud.create_keypair(name, public_key)
                changed = True

            module.exit_json(changed=changed,
                             key=keypair,
                             id=keypair['id'])

        elif state == 'absent':
            if keypair:
                cloud.delete_keypair(name)
                module.exit_json(changed=True)
            module.exit_json(changed=False)

    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e))

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

示例12: main

# 需要导入模块: import shade [as 别名]
# 或者: from shade import openstack_cloud [as 别名]
def main():
    argument_spec = openstack_full_argument_spec(
        name=dict(required=False, default=None),
        ram=dict(required=False, default=None),
        vcpus=dict(required=False, default=None),
        limit=dict(required=False, default=None, type='int'),
    )
    module_kwargs = openstack_module_kwargs(
        mutually_exclusive=[
            ['name', 'ram'],
            ['name', 'vcpus'],
        ]
    )
    module = AnsibleModule(argument_spec, **module_kwargs)

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

    name = module.params['name']
    vcpus = module.params['vcpus']
    ram = module.params['ram']
    limit = module.params['limit']

    try:
        cloud = shade.openstack_cloud(**module.params)
        if name:
            flavors = cloud.search_flavors(filters={'name': name})

        else:
            flavors = cloud.list_flavors()
            filters = {}
            if vcpus:
                filters['vcpus'] = vcpus
            if ram:
                filters['ram'] = ram
            if filters:
                # Range search added in 1.5.0
                if StrictVersion(shade.__version__) < StrictVersion('1.5.0'):
                    module.fail_json(msg="Shade >= 1.5.0 needed for this functionality")
                flavors = cloud.range_search(flavors, filters)

        if limit is not None:
            flavors = flavors[:limit]

        module.exit_json(changed=False,
                         ansible_facts=dict(openstack_flavors=flavors))

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

示例13: main

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

    try:
        cloud = shade.openstack_cloud(**module.params)
        server_group = cloud.get_server_group(name)

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

        changed = False
        if state == 'present':
            if not server_group:
                if not policies:
                    module.fail_json(
                        msg="Parameter 'policies' is required in Server Group "
                            "Create"
                    )
                server_group = cloud.create_server_group(name, policies)
                changed = True

            module.exit_json(
                changed=changed,
                id=server_group['id'],
                server_group=server_group
            )
        if state == 'absent':
            if server_group:
                cloud.delete_server_group(server_group['id'])
                changed = True
            module.exit_json(changed=changed)
    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e), extra_data=e.extra_data)


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

示例14: main

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

    argument_spec = openstack_full_argument_spec(
        name=dict(required=True),
        template=dict(default=None),
        environment=dict(default=None, type='list'),
        parameters=dict(default={}, type='dict'),
        rollback=dict(default=False, type='bool'),
        timeout=dict(default=3600, type='int'),
        state=dict(default='present', choices=['absent', 'present']),
    )

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

    # stack API introduced in 1.8.0
    if not HAS_SHADE or (StrictVersion(shade.__version__) < StrictVersion('1.8.0')):
        module.fail_json(msg='shade 1.8.0 or higher is required for this module')

    state = module.params['state']
    name = module.params['name']
    # Check for required parameters when state == 'present'
    if state == 'present':
        for p in ['template']:
            if not module.params[p]:
                module.fail_json(msg='%s required with present state' % p)

    try:
        cloud = shade.openstack_cloud(**module.params)
        stack = cloud.get_stack(name)

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

        if state == 'present':
            if not stack:
                stack = _create_stack(module, stack, cloud)
            else:
                stack = _update_stack(module, stack, cloud)
            changed = True
            module.exit_json(changed=changed,
                             stack=stack,
                             id=stack.id)
        elif state == 'absent':
            if not stack:
                changed = False
            else:
                changed = True
                if not cloud.delete_stack(name, wait=module.params['wait']):
                    module.fail_json(msg='delete stack failed for stack: %s' % name)
            module.exit_json(changed=changed)
    except shade.OpenStackCloudException as e:
        module.fail_json(msg=str(e)) 
开发者ID:YoLoveLife,项目名称:DevOps,代码行数:58,代码来源:os_stack.py


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