Пример #1
0
def add_labeled_network(api):
    """
    Creates a labeled network
    """
    # create network
    labeled_net = Network(
        name=LABELED_NET_NAME,
        data_center=DataCenter(name=DC_NAME, ),
        description='Labeled network on VLAN {}'.format(LABELED_NET_VLAN_ID),
        usages=[],
        # because only one non-VLAN network, here 'ovirtmgmt', can be assigned
        # to each nic, this additional network has to be a VLAN network
        # NOTE: we have added three more NICs since creating this test
        vlan=Vlan(id=LABELED_NET_VLAN_ID, ),
    )
    networks_service = api.system_service().networks_service()
    net = networks_service.add(labeled_net)
    nt.assert_true(net)

    network_service = networks_service.network_service(id=net.id)
    labels_service = network_service.network_labels_service()

    # assign label to the network
    nt.assert_true(labels_service.add(NetworkLabel(id=NETWORK_LABEL)))
    nt.assert_equal(
        len(
            list(label for label in labels_service.list()
                 if label.id == NETWORK_LABEL)), 1)
def test_add_labeled_network(networks_service, ost_dc_name):
    """
    Creates a labeled network
    """
    # create network
    labeled_net = Network(
        name=LABELED_NET_NAME,
        data_center=DataCenter(name=ost_dc_name),
        description='Labeled network on VLAN {}'.format(LABELED_NET_VLAN_ID),
        usages=[],
        # because only one non-VLAN network, here 'ovirtmgmt', can be assigned
        # to each nic, this additional network has to be a VLAN network
        # NOTE: we have added three more NICs since creating this test
        vlan=Vlan(id=LABELED_NET_VLAN_ID),
    )
    net = networks_service.add(labeled_net)
    assert net

    network_service = networks_service.network_service(id=net.id)
    labels_service = network_service.network_labels_service()

    # assign label to the network
    assert labels_service.add(NetworkLabel(id=NETWORK_LABEL))
    assert len([label for label in labels_service.list()
                if label.id == NETWORK_LABEL]) == 1
Пример #3
0
def create_network_params(network_name, dc_name, **net_params):
    return Network(
        name=network_name,
        data_center=DataCenter(
            name=dc_name,
        ),
        **net_params
    )
Пример #4
0
def add_networks(engine, dc_name, cluster_name, network_names):
    networks_service = engine.networks_service()
    networks = list()
    for net_name in network_names:
        network = networks_service.add(
            network=Network(name=net_name,
                            data_center=DataCenter(name=dc_name),
                            cluster=Cluster(name=cluster_name)))
        networks.append(network)
    return networks
Пример #5
0
def attach_network_to_host(host, nic_name, network_name, ip_configuration,
                           bonds=[]):
    attachment = NetworkAttachment(
        network=Network(name=network_name),
        host_nic=HostNic(name=nic_name),
        ip_address_assignments=ip_configuration)

    return host.setup_networks(
        modified_bonds=bonds,
        modified_network_attachments=[attachment],
        check_connectivity=True)
Пример #6
0
def attach_network_to_host(host, nic_name, network_name, ip_configuration,
                           bonds=[]):
    attachment = NetworkAttachment(
        network=Network(name=network_name),
        host_nic=HostNic(name=nic_name),
        ip_address_assignments=ip_configuration)

    testlib.assert_equals_within_short(
        lambda:
        _setup_host_networks_without_conflict(
            host=host,
            modified_bonds=bonds,
            modified_network_attachments=[attachment],
            check_connectivity=True), True, [])
Пример #7
0
def assign_networks_to_cluster(engine, cluster_name, networks, required):
    service = _get_cluster_network_service(engine, cluster_name)
    for network in networks:
        service.add(network=Network(id=network.id, required=required))
Пример #8
0
 def _create_mapping_target_id(self, from_name, to_id):
     return RegistrationVnicProfileMapping(
         from_=VnicProfile(name=from_name, network=Network(name=from_name)),
         to=VnicProfile(id=to_id),
     )
Пример #9
0
 def _create_mapping_no_target(self, from_name):
     return RegistrationVnicProfileMapping(
         from_=VnicProfile(name=from_name, network=Network(name=from_name)),
         to=None,
     )
Пример #10
0
 def _create_mapping_no_source(self, to_name):
     return RegistrationVnicProfileMapping(
         from_=None,
         to=VnicProfile(name=to_name, network=Network(name=to_name)),
     )
Пример #11
0
 def _create_mapping(self, from_name, to_name):
     return RegistrationVnicProfileMapping(
         from_=VnicProfile(name=from_name, network=Network(name=from_name)),
         to=VnicProfile(name=to_name, network=Network(name=to_name)))