def add_labeled_network(api):
    """
    Creates a labeled network
    """

    # create network
    labeled_net = params.Network(
        name=LABELED_NET_NAME,
        data_center=params.DataCenter(name=DC_NAME, ),
        description='Labeled network on VLAN {}'.format(LABELED_NET_VLAN_ID),
        usages=params.Usages(),
        # because only one non-VLAN network, here 'ovirtmgmt', can be assigned to each nic,
        # this additional network has to be a VLAN network
        vlan=params.VLAN(id=LABELED_NET_VLAN_ID, ),
    )
    net = api.networks.add(labeled_net)
    nt.assert_true(net)

    # assign label to the network
    nt.assert_true(net.labels.add(params.Label(id=NETWORK_LABEL)))
    nt.assert_equal(len(net.labels.list(id=NETWORK_LABEL)), 1)
 def _assign_host_network_label(host):
     nics = host.nics.list()
     nt.assert_greater_equal(len(nics), 1)
     nic = nics[0]
     return nic.labels.add(params.Label(id=NETWORK_LABEL, host_nic=nic))
Ejemplo n.º 3
0
# Now apply the rhevm network configuration
try:
    host = api.hosts.get(HOST_NAME)
    host.nics.setupnetworks(
        params.Action(
            force=False,
            check_connectivity=True,
            host_nics=params.HostNics(host_nic=[nic0, backendNetwork])))

except Exception as err:
    print "Setup Network failed: %s" % err

# Finally add the labels
try:
    host.nics.get('bond0').labels.add(params.Label(id='Backend'))

except Exception as err:
    print "Add Label failed: %s" % err

# This only works in case a Virtual Network
# with VLAN ID 110 gets assigned with the Label 'Backend'.
# This Network is not defined in here.

try:
    nic = host.nics.get(name='bond0.110')
    nic.set_boot_protocol('static')
    nic.set_ip(params.IP(address=MOVE_IP, netmask=NETMASK, gateway=None))
    nic.update()
    # Also save the networkconfig to the host
    # Otherwise there will be an "action marker"
Ejemplo n.º 4
0
#! /usr/bin/python

from ovirtsdk.api import API
from ovirtsdk.xml import params

VERSION = params.Version(major='3', minor='5')

URL = 'https://rhevm.example.com/ovirt-engine/api'
CA = '/etc/pki/ovirt-engine/ca.pem'
USERNAME = '******'
PASSWORD = '******'

HOST_NAME = 'rhevh1'

try:
    api = API(url=URL, username=USERNAME, password=PASSWORD, ca_file=CA)
    print "Connected to %s successfully!" % api.get_product_info().name

except Exception as err:
    print "Connection failed: %s" % err

try:
    host = api.hosts.get(HOST_NAME)
    for nic in host.nics.list():
        print nic.name
        nic.labels.add(params.Label(id=nic.name))
    host.nics.get('eth1').labels.add(params.Label(id='Test'))

except Exception as err:
    print "Add Label failed: %s" % err
Ejemplo n.º 5
0
 def _assign_host_network_label(host):
     nics = sorted(host.nics.list(), key=lambda n: n.get_name())
     nt.assert_greater_equal(len(nics), 1)
     nic = nics[0]
     return nic.labels.add(params.Label(id=NETWORK_LABEL, host_nic=nic))