Esempio n. 1
0
def setup_sdn_provider_vlan(network_config, keystone_session=None):
    """Perform setup for Software Defined Network, specifically a provider VLAN.

    :param network_config: Network configuration settings dictionary
    :type network_config: dict
    :param keystone_session: Keystone session object for overcloud
    :type keystone_session: keystoneauth1.session.Session object
    :returns: None
    :rtype: None
    """
    # If a session has not been provided, acquire one
    if not keystone_session:
        keystone_session = openstack_utils.get_overcloud_keystone_session()

    # Get authenticated clients
    keystone_client = openstack_utils.get_keystone_session_client(
        keystone_session)
    neutron_client = openstack_utils.get_neutron_session_client(
        keystone_session)

    admin_domain = None
    if openstack_utils.get_keystone_api_version() > 2:
        admin_domain = "admin_domain"
    # Resolve the project name from the overcloud openrc into a project id
    project_id = openstack_utils.get_project_id(
        keystone_client,
        "admin",
        domain_name=admin_domain,
    )

    logging.info("Configuring VLAN provider network")
    # Create the external network
    provider_vlan_network = openstack_utils.create_provider_network(
        neutron_client,
        project_id,
        net_name=network_config["provider_vlan_net_name"],
        external=False,
        shared=True,
        network_type='vlan',
        vlan_id=network_config["provider_vlan_id"])
    provider_vlan_subnet = openstack_utils.create_provider_subnet(
        neutron_client,
        project_id,
        provider_vlan_network,
        network_config["provider_vlan_subnet_name"],
        cidr=network_config["provider_vlan_cidr"],
        dhcp=True)
    openstack_utils.plug_subnet_into_router(neutron_client,
                                            network_config["router_name"],
                                            provider_vlan_network,
                                            provider_vlan_subnet)
    openstack_utils.add_neutron_secgroup_rules(neutron_client, project_id)
Esempio n. 2
0
def setup_sdn(network_config, keystone_session=None):
    """Perform setup for Software Defined Network.

    :param network_config: Network configuration settings dictionary
    :type network_config: dict
    :param keystone_session: Keystone session object for overcloud
    :type keystone_session: keystoneauth1.session.Session object
    :returns: None
    :rtype: None
    """
    # If a session has not been provided, acquire one
    if not keystone_session:
        keystone_session = openstack_utils.get_overcloud_keystone_session()

    # Get authenticated clients
    keystone_client = openstack_utils.get_keystone_session_client(
        keystone_session)
    neutron_client = openstack_utils.get_neutron_session_client(
        keystone_session)

    admin_domain = None
    if openstack_utils.get_keystone_api_version() > 2:
        admin_domain = "admin_domain"
    # Resolve the project name from the overcloud openrc into a project id
    project_id = openstack_utils.get_project_id(
        keystone_client,
        "admin",
        domain_name=admin_domain,
    )
    # Network Setup
    subnetpools = False
    if network_config.get("subnetpool_prefix"):
        subnetpools = True

    logging.info("Configuring overcloud network")
    # Create the external network
    ext_network = openstack_utils.create_provider_network(
        neutron_client, project_id, network_config["external_net_name"])
    openstack_utils.create_provider_subnet(
        neutron_client, project_id, ext_network,
        network_config["external_subnet_name"],
        network_config["default_gateway"], network_config["external_net_cidr"],
        network_config["start_floating_ip"], network_config["end_floating_ip"])
    provider_router = (openstack_utils.create_provider_router(
        neutron_client, project_id))
    openstack_utils.plug_extnet_into_router(neutron_client, provider_router,
                                            ext_network)
    ip_version = network_config.get("ip_version") or 4
    subnetpool = None
    if subnetpools:
        address_scope = openstack_utils.create_address_scope(
            neutron_client,
            project_id,
            network_config.get("address_scope"),
            ip_version=ip_version)
        subnetpool = openstack_utils.create_subnetpool(
            neutron_client, project_id, network_config.get("subnetpool_name"),
            network_config.get("subnetpool_prefix"), address_scope)
    project_network = openstack_utils.create_project_network(
        neutron_client,
        project_id,
        shared=False,
        network_type=network_config["network_type"])
    project_subnet = openstack_utils.create_project_subnet(
        neutron_client,
        project_id,
        project_network,
        network_config.get("private_net_cidr"),
        subnetpool=subnetpool,
        ip_version=ip_version)
    openstack_utils.update_subnet_dns(neutron_client, project_subnet,
                                      network_config["external_dns"])
    openstack_utils.plug_subnet_into_router(neutron_client,
                                            network_config["router_name"],
                                            project_network, project_subnet)
    openstack_utils.add_neutron_secgroup_rules(neutron_client, project_id)