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))
def net_disconnect_from_nat(vca_client, **kwargs):
    """
        drop nat rule for current node
    """
    if ctx.target.node.properties.get('use_external_resource', False):
        ctx.logger.info("Using existing Public NAT.")
        return
    if not prepare_network_operation(vca_client, DELETE):
        return set_retry(ctx)
Beispiel #3
0
def net_disconnect_from_nat(vca_client, **kwargs):
    """
        drop nat rule for current node
    """
    if ctx.target.node.properties.get('use_external_resource', False):
        ctx.logger.info("Using existing Public NAT.")
        return
    if not prepare_network_operation(vca_client, DELETE):
        return set_retry(ctx)
def create(vca_client, **kwargs):
    """
        create new vcloud air network, e.g.:
        {
            'use_external_resource': False,
            'resource_id': 'secret_network',
            'network': {
                'dhcp': {
                    'dhcp_range': "10.1.1.128-10.1.1.255"
                },
                'static_range':  "10.1.1.2-10.1.1.127",
                'gateway_ip': "10.1.1.1",
                'edge_gateway': 'gateway',
                'name': 'secret_network',
                "netmask": '255.255.255.0',
                "dns": ["8.8.8.8", "4.4.4.4"]
            }
        }
    """
    vdc_name = get_vcloud_config()['vdc']
    if ctx.node.properties['use_external_resource']:
        network_name = ctx.node.properties['resource_id']
        if not is_network_exists(vca_client, network_name):
            raise cfy_exc.NonRecoverableError(
                "Can't find external resource: {0}".format(network_name))
        ctx.instance.runtime_properties[VCLOUD_NETWORK_NAME] = network_name
        ctx.logger.info(
            "External resource {0} has been used".format(network_name))
        return
    network_name = get_network_name(ctx.node.properties)
    if not ctx.instance.runtime_properties.get(SKIP_CREATE_NETWORK):
        net_prop = ctx.node.properties["network"]
        if network_name in _get_network_list(vca_client,
                                             get_vcloud_config()['vdc']):
            raise cfy_exc.NonRecoverableError(
                "Network {0} already exists, but parameter "
                "'use_external_resource' is 'false' or absent"
                .format(network_name))

        ip = _split_adresses(net_prop['static_range'])
        gateway_name = net_prop['edge_gateway']
        get_gateway(vca_client, gateway_name)
        start_address = ip.start
        end_address = ip.end
        gateway_ip = net_prop["gateway_ip"]
        netmask = net_prop["netmask"]
        dns1 = ""
        dns2 = ""
        dns_list = net_prop.get("dns")
        if dns_list:
            dns1 = dns_list[0]
            if len(dns_list) > 1:
                dns2 = dns_list[1]
        dns_suffix = net_prop.get("dns_suffix")
        ctx.logger.info("Create network {0}."
                        .format(network_name))
        success, result = vca_client.create_vdc_network(
            vdc_name, network_name, gateway_name, start_address,
            end_address, gateway_ip, netmask, dns1, dns2, dns_suffix)
        if success:
            wait_for_task(vca_client, result)
            ctx.logger.info("Network {0} has been successfully created."
                            .format(network_name))
        else:
            raise cfy_exc.NonRecoverableError(
                "Could not create network {0}: {1}".
                format(network_name, result))
        ctx.instance.runtime_properties[VCLOUD_NETWORK_NAME] = network_name
    if not _dhcp_operation(vca_client, network_name, ADD_POOL):
        ctx.instance.runtime_properties[SKIP_CREATE_NETWORK] = True
        return set_retry(ctx)
def delete(vca_client, **kwargs):
    """
        drop firewall rules for node
    """
    if not _rule_operation(DELETE_RULE, vca_client):
        return set_retry(ctx)
def create(vca_client, **kwargs):
    """
        create firewall rules for node
    """
    if not _rule_operation(CREATE_RULE, vca_client):
        return set_retry(ctx)
def delete(vca_client, **kwargs):
    """
        drop firewall rules for node
    """
    if not _rule_operation(DELETE_RULE, vca_client):
        return set_retry(ctx)
def create(vca_client, **kwargs):
    """
        create firewall rules for node
    """
    if not _rule_operation(CREATE_RULE, vca_client):
        return set_retry(ctx)
def disconnect_floatingip(vca_client, **kwargs):
    """
        release floating ip
    """
    if not _floatingip_operation(DELETE, vca_client, ctx):
        return set_retry(ctx)
def connect_floatingip(vca_client, **kwargs):
    """
        create new floating ip for node
    """
    if not _floatingip_operation(CREATE, vca_client, ctx):
        return set_retry(ctx)
def server_disconnect_from_nat(vca_client, **kwargs):
    """
        drop nat rules for server
    """
    if not prepare_server_operation(vca_client, DELETE):
        return set_retry(ctx)
def server_connect_to_nat(vca_client, **kwargs):
    """
        create nat rules for server
    """
    if not prepare_server_operation(vca_client, CREATE):
        return set_retry(ctx)
Beispiel #13
0
def server_disconnect_from_nat(vca_client, **kwargs):
    """
        drop nat rules for server
    """
    if not prepare_server_operation(vca_client, DELETE):
        return set_retry(ctx)
Beispiel #14
0
def server_connect_to_nat(vca_client, **kwargs):
    """
        create nat rules for server
    """
    if not prepare_server_operation(vca_client, CREATE):
        return set_retry(ctx)