Ejemplo n.º 1
0
def add_routes(neutron_client, args, **kwargs):

    # Since routes is part of router and not single API resource for routes
    # "router" resource is used
    router = use_external_resource(ctx, neutron_client, ROUTER_OPENSTACK_TYPE)
    if router:
        # Update routes as part of runtime properties
        ctx.instance.runtime_properties[ROUTES_OPENSTACK_TYPE]\
            = router[ROUTES_OPENSTACK_TYPE]
        # Update type to match it as routes types
        ctx.instance.runtime_properties[OPENSTACK_TYPE_PROPERTY]\
            = ROUTES_OPENSTACK_TYPE
        return

    routes = ctx.node.properties.get(ROUTES_OPENSTACK_TYPE, {})

    if not routes:
        raise NonRecoverableError('routes param is required and must be '
                                  'provided when creating static routes !!')

    # Force to pass only the "routes" provided by the node properties
    routes_args = {'routes': routes}

    # This will update the router and add new static routes based on the
    # routes param provided by the "cloudify.openstack.nodes.Routes"
    r = _update_router_routes(neutron_client, routes_args, **kwargs)
    router = r.get(ROUTER_OPENSTACK_TYPE)
    if r and router:
        set_neutron_runtime_properties(ctx, router, ROUTES_OPENSTACK_TYPE)
        ctx.instance.runtime_properties[ROUTES_OPENSTACK_TYPE] = routes
    else:
        raise NonRecoverableError(
            'Failed while trying to retrieve router instance')
Ejemplo n.º 2
0
def create(neutron_client, args, **kwargs):

    if use_external_resource(ctx, neutron_client, ROUTER_OPENSTACK_TYPE):
        try:
            ext_net_id_by_rel = _get_connected_ext_net_id(neutron_client)

            if ext_net_id_by_rel:
                router_id = get_openstack_id(ctx)

                router = neutron_client.show_router(router_id)['router']
                if not (router['external_gateway_info']
                        and 'network_id' in router['external_gateway_info']
                        and router['external_gateway_info']['network_id']
                        == ext_net_id_by_rel):
                    raise NonRecoverableError(
                        'Expected external resources router {0} and '
                        'external network {1} to be connected'.format(
                            router_id, ext_net_id_by_rel))
            return
        except Exception:
            delete_runtime_properties(ctx, RUNTIME_PROPERTIES_KEYS)
            raise

    router = create_object_dict(ctx, ROUTER_OPENSTACK_TYPE, args, {})
    ctx.logger.info('router: {0}'.format(router))

    _handle_external_network_config(router, neutron_client)

    r = neutron_client.create_router({ROUTER_OPENSTACK_TYPE:
                                      router})[ROUTER_OPENSTACK_TYPE]

    set_neutron_runtime_properties(ctx, r, ROUTER_OPENSTACK_TYPE)
Ejemplo n.º 3
0
def create(neutron_client, args, **kwargs):

    if use_external_resource(ctx, neutron_client, SUBNET_OPENSTACK_TYPE):
        try:
            net_id = \
                get_openstack_id_of_single_connected_node_by_openstack_type(
                    ctx, NETWORK_OPENSTACK_TYPE, True)

            if net_id:
                subnet_id = get_openstack_id(ctx)

                if neutron_client.show_subnet(
                        subnet_id)[SUBNET_OPENSTACK_TYPE][NETWORK_ID] \
                        != net_id:
                    raise NonRecoverableError(
                        'Expected external resources subnet {0} and network'
                        ' {1} to be connected'.format(subnet_id, net_id))
            return
        except Exception:
            delete_runtime_properties(ctx, RUNTIME_PROPERTIES_KEYS)
            raise

    net_id = get_openstack_id_of_single_connected_node_by_openstack_type(
        ctx, NETWORK_OPENSTACK_TYPE)
    subnet = create_object_dict(ctx,
                                SUBNET_OPENSTACK_TYPE,
                                args,
                                {NETWORK_ID: net_id})

    s = neutron_client.create_subnet(
        {SUBNET_OPENSTACK_TYPE: subnet})[SUBNET_OPENSTACK_TYPE]
    set_neutron_runtime_properties(ctx, s, SUBNET_OPENSTACK_TYPE)
Ejemplo n.º 4
0
def create(neutron_client, args, **kwargs):

    if use_external_resource(ctx, neutron_client, NETWORK_OPENSTACK_TYPE):
        return
    network = create_object_dict(ctx, NETWORK_OPENSTACK_TYPE, args,
                                 {ADMIN_STATE_UP: True})

    net = neutron_client.create_network({NETWORK_OPENSTACK_TYPE:
                                         network})[NETWORK_OPENSTACK_TYPE]
    set_neutron_runtime_properties(ctx, net, NETWORK_OPENSTACK_TYPE)
Ejemplo n.º 5
0
def create(neutron_client, args, **kwargs):

    ext_port = use_external_resource(ctx, neutron_client, PORT_OPENSTACK_TYPE)
    if ext_port:
        try:
            net_id = \
                get_openstack_id_of_single_connected_node_by_openstack_type(
                    ctx, NETWORK_OPENSTACK_TYPE, True)

            if net_id:
                port_id = get_openstack_id(ctx)

                if neutron_client.show_port(
                        port_id)[PORT_OPENSTACK_TYPE]['network_id'] != net_id:
                    raise NonRecoverableError(
                        'Expected external resources port {0} and network {1} '
                        'to be connected'.format(port_id, net_id))

            ctx.instance.runtime_properties[FIXED_IP_ADDRESS_PROPERTY] = \
                _get_fixed_ip(ext_port)
            ctx.instance.runtime_properties[MAC_ADDRESS_PROPERTY] = \
                ext_port['mac_address']
            return
        except Exception:
            delete_runtime_properties(ctx, RUNTIME_PROPERTIES_KEYS)
            raise

    net_id = ctx.node.properties.get(PORT_OPENSTACK_TYPE, {}).get('network_id')
    if not net_id:
        net_id = \
            get_openstack_id_of_single_connected_node_by_openstack_type(
                ctx, NETWORK_OPENSTACK_TYPE)

    port = create_object_dict(ctx, PORT_OPENSTACK_TYPE, args,
                              {'network_id': net_id})
    _handle_fixed_ips(port, neutron_client)
    _handle_security_groups(port)

    p = neutron_client.create_port({PORT_OPENSTACK_TYPE:
                                    port})[PORT_OPENSTACK_TYPE]

    set_neutron_runtime_properties(ctx, p, PORT_OPENSTACK_TYPE)
    ctx.instance.runtime_properties[FIXED_IP_ADDRESS_PROPERTY] = \
        _get_fixed_ip(p)
    ctx.instance.runtime_properties[MAC_ADDRESS_PROPERTY] = p['mac_address']