• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python vcloud_plugin_common.get_vcloud_config函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_get_vcloud_config

 def test_get_vcloud_config(self):
     # context.NODE_INSTANCE
     fake_ctx = self.generate_node_context(
         properties={
             'vcloud_config': {
                 'vdc': 'vdc_name'
             }
         }
     )
     fake_ctx._instance = mock.Mock()
     with mock.patch(
         'vcloud_plugin_common.ctx', fake_ctx
     ):
         self.assertEqual(
             vcloud_plugin_common.get_vcloud_config(),
             {
                 'vdc': 'vdc_name'
             }
         )
     # context.RELATIONSHIP_INSTANCE
     fake_ctx = self.generate_relation_context()
     fake_ctx._source.node.properties = {
         'vcloud_config': {
             'vdc': 'vdc_name'
         }
     }
     with mock.patch(
         'vcloud_plugin_common.ctx', fake_ctx
     ):
         self.assertEqual(
             vcloud_plugin_common.get_vcloud_config(),
             {
                 'vdc': 'vdc_name'
             }
         )
     # context.DEPLOYMENT
     fake_ctx = self.generate_node_context(
         properties={
             'vcloud_config': {
                 'vdc': 'vdc_name'
             }
         }
     )
     fake_ctx._source = None
     fake_ctx._instance = None
     with mock.patch(
         'vcloud_plugin_common.ctx', fake_ctx
     ):
         with self.assertRaises(cfy_exc.NonRecoverableError):
             vcloud_plugin_common.get_vcloud_config()
开发者ID:denismakogon,项目名称:tosca-vcloud-plugin,代码行数:50,代码来源:test_mock_vcloud_plugin_common.py


示例2: _get_state

def _get_state(vca_client):
    vapp_name = get_vapp_name(ctx.instance.runtime_properties)
    config = get_vcloud_config()
    vdc = vca_client.get_vdc(config['vdc'])
    vapp = vca_client.get_vapp(vdc, vapp_name)
    nw_connections = _get_vm_network_connections(vapp)
    if len(nw_connections) == 0:
        ctx.logger.info("No networks connected")
        ctx.instance.runtime_properties['ip'] = None
        ctx.instance.runtime_properties['networks'] = {}
        return True
    management_network_name = _get_management_network_from_node()

    if not all([connection['ip'] for connection in nw_connections]):
        ctx.logger.info("Network configuration is not finished yet.")
        return False

    ctx.instance.runtime_properties['networks'] = {
        connection['network_name']: connection['ip']
        for connection in nw_connections}

    for connection in nw_connections:
        if connection['network_name'] == management_network_name:
            ctx.logger.info("Management network ip address {0}"
                            .format(connection['ip']))
            ctx.instance.runtime_properties['ip'] = connection['ip']
            return True
    return False
开发者ID:nmishkin,项目名称:tosca-vcloud-plugin,代码行数:28,代码来源:server.py


示例3: delete

def delete(vca_client, **kwargs):
    """
        delete vcloud air network
    """
    if ctx.node.properties['use_external_resource'] is True:
        del ctx.instance.runtime_properties[VCLOUD_NETWORK_NAME]
        ctx.logger.info("Network was not deleted - external resource has"
                        " been used")
        return
    network_name = get_network_name(ctx.node.properties)
    if not _dhcp_operation(vca_client, network_name, DELETE_POOL):
        return set_retry(ctx)
    ctx.logger.info("Delete network '{0}'".format(network_name))
    success, task = vca_client.delete_vdc_network(
        get_vcloud_config()['vdc'], network_name)
    if success:
        wait_for_task(vca_client, task)
        ctx.logger.info(
            "Network '{0}' has been successful deleted.".format(network_name))
    else:
        if task and CANT_DELETE in task:
            ctx.logger.info("Network {} in use. Deleting the network skipped.".
                            format(network_name))
            return
        raise cfy_exc.NonRecoverableError(
            "Could not delete network '{0}': {1}".format(network_name, task))
开发者ID:denismakogon,项目名称:tosca-vcloud-plugin,代码行数:26,代码来源:network.py


示例4: get_gateway

def get_gateway(vca_client, gateway_name):
    gateway = vca_client.get_gateway(get_vcloud_config()['vdc'],
                                     gateway_name)
    if not gateway:
        raise cfy_exc.NonRecoverableError(
            "Gateway {0}  not found".format(gateway_name))
    return gateway
开发者ID:nmishkin,项目名称:tosca-vcloud-plugin,代码行数:7,代码来源:__init__.py


示例5: start

def start(vca_client, **kwargs):
    """
    power on server and wait network connection availability for host
    """
    if ctx.node.properties.get('use_external_resource'):
        ctx.logger.info('not starting server since an external server is '
                        'being used')
    else:
        vapp_name = get_vapp_name(ctx.instance.runtime_properties)
        config = get_vcloud_config()
        vdc = vca_client.get_vdc(config['vdc'])
        vapp = vca_client.get_vapp(vdc, vapp_name)
        if _vapp_is_on(vapp) is False:
            ctx.logger.info("Power-on VApp {0}".format(vapp_name))
            task = vapp.poweron()
            if not task:
                raise cfy_exc.NonRecoverableError(
                    "Could not power-on vApp. {0}".
                                                  format(error_response(vapp)))
            wait_for_task(vca_client, task)

    if not _get_state(vca_client):
        return ctx.operation.retry(
            message="Waiting for VM's configuration to complete",
            retry_after=5)
开发者ID:jalopez11,项目名称:cloudify-dependencies,代码行数:25,代码来源:server.py


示例6: get_vm_ip

def get_vm_ip(vca_client, ctx, gateway):
    """
        get ip assigned to current vm from connected primary network.
    """
    try:
        vappName = get_vapp_name(ctx.source.instance.runtime_properties)
        vdc = vca_client.get_vdc(get_vcloud_config()['vdc'])
        vapp = vca_client.get_vapp(vdc, vappName)
        if not vapp:
            raise cfy_exc.NonRecoverableError(
                "Could not find vApp {0}".format(vappName))

        vm_info = vapp.get_vms_network_info()
        # assume that we have 1 vm per vApp
        for connection in vm_info[0]:
            if connection['is_connected'] and connection['is_primary']:
                if is_network_routed(vca_client,
                                     connection['network_name'],
                                     gateway):
                    return connection['ip']
                else:
                    raise cfy_exc.NonRecoverableError(
                        "Primary network {0} not routed"
                        .format(connection['network_name']))
        raise cfy_exc.NonRecoverableError("No connected primary network")
    except IndexError:
        raise cfy_exc.NonRecoverableError("Could not get vm IP address")
开发者ID:pkdevboxy,项目名称:tosca-vcloud-plugin,代码行数:27,代码来源:__init__.py


示例7: create_volume

def create_volume(vca_client, **kwargs):
    """
        create new volume, e.g.:
        {
            'use_external_resource': False,
            'volume': {
                'name': 'some-other',
                'size': 11
            }
        }
    """
    if ctx.node.properties.get('use_external_resource'):
        ctx.logger.info("External resource has been used")
        return
    vdc_name = get_vcloud_config()['vdc']
    name = ctx.node.properties['volume']['name']
    size = ctx.node.properties['volume']['size']
    size_in_Mb = size * 1024 * 1024
    success, disk = vca_client.add_disk(vdc_name, name, size_in_Mb)
    if success:
        wait_for_task(vca_client, disk.get_Tasks()[0])
        ctx.logger.info("Volume node {} has been created".format(name))
    else:
        raise cfy_exc.NonRecoverableError(
            "Disk creation error: {0}".format(disk))
开发者ID:jalopez11,项目名称:cloudify-dependencies,代码行数:25,代码来源:volume.py


示例8: create

def create(vca_client, **kwargs):
    """create vdc"""
    config = get_vcloud_config()
    # Subscription service does not support vdc create,
    # you must use predefined vdc only
    if is_subscription(config['service_type']):
            raise cfy_exc.NonRecoverableError(
                "Unable create VDC on subscription service.")
    if ctx.node.properties.get(USE_EXTERNAL_RESOURCE):
        # use external resource, does not create anything
        res_id = ctx.node.properties[RESOURCE_ID]
        ctx.instance.runtime_properties[VDC_NAME] = res_id
        vdc = vca_client.get_vdc(res_id)
        if not vdc:
            raise cfy_exc.NonRecoverableError(
                "Unable to find external VDC {0}."
                .format(res_id))
        ctx.logger.info(
            "External resource {0} has been used".format(res_id))
    else:
        # create new vdc
        vdc_name = ctx.node.properties.get('name')
        if not vdc_name:
            raise cfy_exc.NonRecoverableError("'vdc_name' not specified.")
        task = vca_client.create_vdc(vdc_name)
        if not task:
            raise cfy_exc.NonRecoverableError("Could not create VDC: {0}"
                                              .format(error_response(vca_client)))
        wait_for_task(vca_client, task)
开发者ID:pkdevboxy,项目名称:tosca-vcloud-plugin,代码行数:29,代码来源:vdc.py


示例9: _dhcp_operation

def _dhcp_operation(vca_client, network_name, operation):
    """
        update dhcp setting for network
    """
    dhcp_settings = ctx.node.properties["network"].get("dhcp")
    if dhcp_settings is None:
        return
    gateway_name = ctx.node.properties["network"]["edge_gateway"]
    gateway = vca_client.get_gateway(get_vcloud_config()["vdc"], gateway_name)
    if not gateway:
        raise cfy_exc.NonRecoverableError("Gateway {0} not found!".format(gateway_name))

    if operation == ADD_POOL:
        ip = _split_adresses(dhcp_settings["dhcp_range"])
        low_ip_address = check_ip(ip.start)
        hight_ip_address = check_ip(ip.end)
        default_lease = dhcp_settings.get("default_lease")
        max_lease = dhcp_settings.get("max_lease")
        gateway.add_dhcp_pool(network_name, low_ip_address, hight_ip_address, default_lease, max_lease)
        ctx.logger.info("DHCP rule successful created for network {0}".format(network_name))

    if operation == DELETE_POOL:
        gateway.delete_dhcp_pool(network_name)
        ctx.logger.info("DHCP rule successful deleted for network {0}".format(network_name))

    if not save_gateway_configuration(gateway, vca_client):
        return ctx.operation.retry(message="Waiting for gateway.", retry_after=10)
开发者ID:rbramwell,项目名称:tosca-vcloud-plugin,代码行数:27,代码来源:network.py


示例10: _save_configuration

def _save_configuration(gateway, vca_client, operation, public_ip):
    """
        save/refresh nat rules on gateway
    """
    ctx.logger.info("Save NAT configuration.")
    success = save_gateway_configuration(gateway, vca_client, ctx)
    if not success:
        return False
    ctx.logger.info("NAT configuration has been saved.")
    if operation == CREATE:
        ctx.target.instance.runtime_properties[PUBLIC_IP] = public_ip
    else:
        service_type = get_vcloud_config().get('service_type')
        if is_ondemand(service_type):
            if not ctx.target.node.properties['nat'].get(PUBLIC_IP):
                del_ondemand_public_ip(
                    vca_client, gateway,
                    ctx.target.instance.runtime_properties[PUBLIC_IP],
                    ctx
                )
        if PUBLIC_IP in ctx.target.instance.runtime_properties:
            del ctx.target.instance.runtime_properties[PUBLIC_IP]
        if PORT_REPLACEMENT in ctx.target.instance.runtime_properties:
            del ctx.target.instance.runtime_properties[PORT_REPLACEMENT]
        if SSH_PORT in ctx.target.instance.runtime_properties:
            del ctx.target.instance.runtime_properties[SSH_PORT]
        if SSH_PUBLIC_IP in ctx.target.instance.runtime_properties:
            del ctx.target.instance.runtime_properties[SSH_PUBLIC_IP]
    return True
开发者ID:pkdevboxy,项目名称:tosca-vcloud-plugin,代码行数:29,代码来源:public_nat.py


示例11: create

def create(vca_client, **kwargs):
    """
        create server by template,
        if external_resource set return without creation,
        e.g.:
        {
            'management_network': '_management_network',
            'server': {
                'template': 'template',
                'catalog': 'catalog',
                'guest_customization': {
                    'pre_script': 'pre_script',
                    'post_script': 'post_script',
                    'admin_password': 'pass',
                    'computer_name': 'computer'

                }
            }
        }
    """
    config = get_vcloud_config()
    server = {
        'name': ctx.instance.id,
    }
    server.update(ctx.node.properties.get('server', {}))
    transform_resource_name(server, ctx)

    if ctx.node.properties.get('use_external_resource'):
        res_id = ctx.node.properties['resource_id']
        ctx.instance.runtime_properties[VCLOUD_VAPP_NAME] = res_id
        ctx.logger.info(
            "External resource {0} has been used".format(res_id))
    else:
        _create(vca_client, config, server)
开发者ID:jalopez11,项目名称:cloudify-dependencies,代码行数:34,代码来源:server.py


示例12: _get_gateway_name

def _get_gateway_name(properties):
    security_group = properties.get('security_group')
    if security_group and 'edge_gateway' in security_group:
        getaway_name = security_group.get('edge_gateway')
    else:
        getaway_name = get_vcloud_config()['edge_gateway']
    return getaway_name
开发者ID:nmishkin,项目名称:tosca-vcloud-plugin,代码行数:7,代码来源:security_group.py


示例13: _get_state

def _get_state(vca_client):
    """
        check network connection availability for host
    """
    vapp_name = get_vapp_name(ctx.instance.runtime_properties)
    config = get_vcloud_config()
    vdc = vca_client.get_vdc(config['vdc'])
    vapp = vca_client.get_vapp(vdc, vapp_name)
    nw_connections = _get_vm_network_connections(vapp)
    if len(nw_connections) == 0:
        ctx.logger.info("No networks connected")
        ctx.instance.runtime_properties['ip'] = None
        ctx.instance.runtime_properties['networks'] = {}
        return True

    if not all([connection['ip'] for connection in nw_connections]):
        ctx.logger.info("Network configuration is not finished yet.")
        return False

    ctx.instance.runtime_properties['networks'] = {
        connection['network_name']: connection['ip']
        for connection in nw_connections}

    for connection in nw_connections:
        if connection['is_primary']:
            ctx.logger.info("Primary network ip address '{0}' for"
                            "  network '{1}'."
                            .format(connection['ip'],
                                    connection['network_name']))
            ctx.instance.runtime_properties['ip'] = connection['ip']
            return True
    return False
开发者ID:jalopez11,项目名称:cloudify-dependencies,代码行数:32,代码来源:server.py


示例14: configure

def configure(vca_client, **kwargs):
    ctx.logger.info("Configure server")
    server = {'name': ctx.instance.id}
    server.update(ctx.node.properties.get('server', {}))
    vapp_name = server['name']
    config = get_vcloud_config()
    custom = server.get(GUEST_CUSTOMIZATION, {})
    public_keys = _get_connected_keypairs()
    if custom or public_keys:
        vdc = vca_client.get_vdc(config['vdc'])
        vapp = vca_client.get_vapp(vdc, vapp_name)
        script = _build_script(custom, public_keys)
        password = custom.get('admin_password')
        computer_name = custom.get('computer_name')

        task = vapp.customize_guest_os(
            vapp_name,
            customization_script=script,
            computer_name=computer_name,
            admin_password=password
        )
        if task is None:
            raise cfy_exc.NonRecoverableError(
                "Could not set guest customization parameters. {0}".
                format(error_response(vapp)))
        wait_for_task(vca_client, task)
        if vapp.customize_on_next_poweron():
            ctx.logger.info("Customizations successful")
        else:
            raise cfy_exc.NonRecoverableError(
                "Can't run customization in next power on. {0}".
                format(error_response(vapp)))

    hardware = server.get('hardware')
    if hardware:
        cpu = hardware.get('cpu')
        memory = hardware.get('memory')
        _check_hardware(cpu, memory)
        vapp = vca_client.get_vapp(
            vca_client.get_vdc(config['vdc']), vapp_name
        )
        if memory:
            try:
                task = vapp.modify_vm_memory(vapp_name, memory)
                wait_for_task(vca_client, task)
                ctx.logger.info("Customize VM memory: '{0}'.".format(memory))
            except Exception:
                raise cfy_exc.NonRecoverableError(
                    "Customize VM memory failed: '{0}'. {1}".
                    format(task, error_response(vapp)))
        if cpu:
            try:
                task = vapp.modify_vm_cpu(vapp_name, cpu)
                wait_for_task(vca_client, task)
                ctx.logger.info("Customize VM cpu: '{0}'.".format(cpu))
            except Exception:
                raise cfy_exc.NonRecoverableError(
                    "Customize VM cpu failed: '{0}'. {1}".
                    format(task, error_response(vapp)))
开发者ID:jalopez11,项目名称:cloudify-dependencies,代码行数:59,代码来源:server.py


示例15: _floatingip_operation

def _floatingip_operation(operation, vca_client, ctx):
    """
        create/release floating ip by nat rules for this ip with
        relation to internal ip for current node,
        save selected public_ip in runtime properties
    """
    service_type = get_vcloud_config().get('service_type')
    gateway = get_gateway(
        vca_client, ctx.target.node.properties['floatingip']['edge_gateway'])
    internal_ip = get_vm_ip(vca_client, ctx, gateway)

    nat_operation = None
    public_ip = (ctx.target.instance.runtime_properties.get(PUBLIC_IP)
                 or ctx.target.node.properties['floatingip'].get(PUBLIC_IP))
    if operation == CREATE:
        CheckAssignedInternalIp(internal_ip, gateway)
        if public_ip:
            CheckAssignedExternalIp(public_ip, gateway)
        else:
            public_ip = get_public_ip(vca_client, gateway, service_type, ctx)

        nat_operation = _add_nat_rule
    elif operation == DELETE:
        if not public_ip:
            ctx.logger.info("Can't get external IP".format(public_ip))
            return True
        nat_operation = _del_nat_rule
    else:
        raise cfy_exc.NonRecoverableError(
            "Unknown operation {0}".format(operation)
        )

    external_ip = check_ip(public_ip)

    nat_operation(gateway, "SNAT", internal_ip, external_ip)
    nat_operation(gateway, "DNAT", external_ip, internal_ip)
    success = save_gateway_configuration(gateway, vca_client, ctx)
    if not success:
        return False
    if operation == CREATE:
        ctx.target.instance.runtime_properties[PUBLIC_IP] = external_ip
        save_ssh_parameters(ctx, '22', external_ip)
    else:
        if is_ondemand(service_type):
            if not ctx.target.node.properties['floatingip'].get(PUBLIC_IP):
                del_ondemand_public_ip(
                    vca_client,
                    gateway,
                    ctx.target.instance.runtime_properties[PUBLIC_IP],
                    ctx)
        if PUBLIC_IP in ctx.target.instance.runtime_properties:
            del ctx.target.instance.runtime_properties[PUBLIC_IP]
        if SSH_PUBLIC_IP in ctx.source.instance.runtime_properties:
            del ctx.source.instance.runtime_properties[SSH_PUBLIC_IP]
        if SSH_PORT in ctx.target.instance.runtime_properties:
            del ctx.source.instance.runtime_properties[SSH_PORT]
    return True
开发者ID:jalopez11,项目名称:tosca-vcloud-plugin,代码行数:57,代码来源:floatingip.py


示例16: get_network

def get_network(vca_client, network_name):
    if not network_name:
        raise cfy_exc.NonRecoverableError(
            "Network name is empty".format(network_name))
    network = vca_client.get_network(get_vcloud_config()['vdc'], network_name)
    if not network:
        raise cfy_exc.NonRecoverableError(
            "Network {0} could not be found".format(network_name))
    return network
开发者ID:nmishkin,项目名称:tosca-vcloud-plugin,代码行数:9,代码来源:__init__.py


示例17: _get_gateway_name

def _get_gateway_name(properties):
    """
        return geteway for current node from vcloud config or security
        group settings
    """
    security_group = properties.get('security_group')
    if security_group and 'edge_gateway' in security_group:
        getaway_name = security_group.get('edge_gateway')
    else:
        getaway_name = get_vcloud_config()['edge_gateway']
    return getaway_name
开发者ID:kemiz,项目名称:tosca-vcloud-plugin,代码行数:11,代码来源:security_group.py


示例18: _create_ip_range

def _create_ip_range(vca_client, gateway):
    network_name = ctx.source.instance.runtime_properties[VCLOUD_NETWORK_NAME]
    org_name = get_vcloud_config()['org']
    net = _get_network_ip_range(vca_client, org_name, network_name)
    gate = _get_gateway_ip_range(gateway, network_name)
    if not net:
        raise cfy_exc.NonRecoverableError(
            "Unknown network: {0}".format(network_name))
    if gate:
        return "{} - {}".format(min(net[0], gate[0]), max(net[1], gate[1]))
    else:
        return "{} - {}".format(min(net), max(net))
开发者ID:nmishkin,项目名称:tosca-vcloud-plugin,代码行数:12,代码来源:public_nat.py


示例19: creation_validation

def creation_validation(vca_client, **kwargs):
    floatingip = get_mandatory(ctx.node.properties, 'floatingip')
    edge_gateway = get_mandatory(floatingip, 'edge_gateway')
    gateway = get_gateway(vca_client, edge_gateway)
    service_type = get_vcloud_config().get('service_type')
    public_ip = floatingip.get(PUBLIC_IP)
    if public_ip:
        check_ip(public_ip)
        CheckAssignedExternalIp(public_ip, gateway)
    else:
        if is_subscription(service_type):
            getFreeIP(gateway)
开发者ID:nmishkin,项目名称:tosca-vcloud-plugin,代码行数:12,代码来源:floatingip.py


示例20: _isDhcpAvailable

def _isDhcpAvailable(vca_client, network_name):
    vdc_name = get_vcloud_config()['vdc']
    network = vca_client.get_network(vdc_name, network_name)
    if network.get_Configuration().get_FenceMode() == "bridged":
        # NOTE(nmishkin) Can't tell whether bridged networks have DHCP
        # so just hope for the best
        return True
    # TODO: Why not just get the gateway directly from the network?
    admin_href = vca_client.get_admin_network_href(vdc_name, network_name)
    for gate in vca_client.get_gateways(vdc_name):
        for pool in gate.get_dhcp_pools():
            if admin_href == pool.get_Network().get_href():
                return True
    return False
开发者ID:nmishkin,项目名称:tosca-vcloud-plugin,代码行数:14,代码来源:server.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python vcloud_plugin_common.wait_for_task函数代码示例发布时间:2022-05-26
下一篇:
Python vclib.check_path_access函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap