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
def _assign_host_network_label(host): host_service = engine.hosts_service().host_service(id=host.id) nics = sorted(host_service.nics_service().list(), key=lambda n: n.name) nt.assert_greater_equal(len(nics), 1) nic = nics[0] nic_service = host_service.nics_service().nic_service(id=nic.id) labels_service = nic_service.network_labels_service() return labels_service.add(NetworkLabel(id=NETWORK_LABEL, host_nic=nic))
def _assign_host_network_label(host): host_service = hosts_service.host_service(id=host.id) nics_service = host_service.nics_service() nics = sorted(nics_service.list(), key=lambda n: n.name) assert len(nics) >= 1 nic = nics[0] nic_service = nics_service.nic_service(id=nic.id) labels_service = nic_service.network_labels_service() return labels_service.add(NetworkLabel(id=NETWORK_LABEL, host_nic=nic))
def _attach_label(host_id, nic, label): logging.info('Attaching label %s to nic %s', label, nic.name) _get_nic_label_service(host_id, nic.id).add(NetworkLabel(id=label))