Esempio n. 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
Esempio n. 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
    )
Esempio n. 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