Ejemplo n.º 1
0
def prepare_route_table_for_delete(network_client, rt_id):
    """
    Prepares a DefaultRouteTable for deletion by deleting all RouteRules.

    :param network_client: OCI VirtualNetworkClient client
    :type network_client: oci.core.VirtualNetworkClient

    :param rt_id: The OCID of the RouteTable to clean.
    :type rt_id: str
    """
    update = core_models.UpdateRouteTableDetails(route_rules=[])
    network_client.update_route_table(rt_id, update)
    print('Cleaned Default Route Table Rules: {}'.format(rt_id))
Ejemplo n.º 2
0
def configure_ig(network_client, compartment_id, vcn_id, ig_id, display_name):
    """
    Configures a Vcn's default RoutingTable to add a RouteRule that provides
    Internet access via the specified InternetGateway.

    :param network_client: OCI VirtualNetworkClient client
    :type network_client: oci.core.VirtualNetworkClient

    :param compartment_id: The OCID of the compartment which owns the Vcn.
    :type compartment_id: str

    :param vcn_id: The OCID of the Vcn which will own the subnet.
    :type vcn_id: str

    :param ig_id: The OCID of the Vcn which will own the subnet.
    :type ig_id: str

    :param display_name: The display name of the RoutingTable to configure.
    :type display_name: str
    """
    # Get the default route table for the Vcn.
    rt = get_unique_route_table_by_name(network_client, compartment_id, vcn_id,
                                        display_name)
    route_rules = rt.route_rules
    if len(route_rules) == 0:
        # Create a global access routing rule.
        destination_cidr = "0.0.0.0/0"
        access = core_models.RouteRule(cidr_block=destination_cidr,
                                       destination=destination_cidr,
                                       destination_type="CIDR_BLOCK",
                                       network_entity_id=ig_id)
        route_rules.append(access)
        # Update the route table with the new access rule.
        update = core_models.UpdateRouteTableDetails(route_rules=route_rules)
        network_client.update_route_table(rt.id, update)
        print(
            'Configured Internet Gateway Default Route Table Rules: {}'.format(
                display_name))