def _bond_nics(number, host):
        slaves = params.Slaves(host_nic=[
            params.HostNIC(name=nic)
            for nic in _nics_to_bond(prefix, host.name)
        ])

        options = params.Options(option=[
            params.Option(name='mode', value='active-backup'),
            params.Option(name='miimon', value='200'),
        ])

        bond = params.HostNIC(name=BOND_NAME,
                              bonding=params.Bonding(slaves=slaves,
                                                     options=options))

        ip_configuration = network_utils.create_static_ip_configuration(
            VLAN200_NET_IPv4_ADDR % number, VLAN200_NET_IPv4_MASK,
            VLAN200_NET_IPv6_ADDR % number, VLAN200_NET_IPv6_MASK)

        network_utils.attach_network_to_host(api, host, BOND_NAME, VLAN200_NET,
                                             ip_configuration, [bond])
Example #2
0
    def _bond_nics(number, host):
        slaves = params.Slaves(host_nic=[
            params.HostNIC(name=nic) for nic in _host_vm_nics(
                prefix, host.name, LIBVIRT_NETWORK_FOR_BONDING)])  # eth2, eth3

        options = params.Options(option=[
            params.Option(name='mode', value='active-backup'),
            params.Option(name='miimon', value='200'),
            ])

        bond = params.HostNIC(
            name=BOND_NAME,
            bonding=params.Bonding(slaves=slaves, options=options))

        ip_configuration = network_utils_v3.create_static_ip_configuration(
            MIGRATION_NETWORK_IPv4_ADDR.format(number),
            MIGRATION_NETWORK_IPv4_MASK,
            MIGRATION_NETWORK_IPv6_ADDR.format(number),
            MIGRATION_NETWORK_IPv6_MASK)

        network_utils_v3.attach_network_to_host(
            api, host, BOND_NAME, MIGRATION_NETWORK, ip_configuration, [bond])
def attach_network_to_host(api, host, nic_name, network_name,
                           ip_configuration, bonds=[]):
    network_attachment = params.NetworkAttachment(
        network=params.Network(name=network_name),
        host_nic=params.HostNIC(name=nic_name),
        ip_address_assignments=ip_configuration)

    attachment_action = params.Action(
        modified_bonds=params.HostNics(host_nic=bonds),
        modified_network_attachments=params.NetworkAttachments(
            network_attachment=[network_attachment]),
        check_connectivity=True)

    return host.setupnetworks(attachment_action)
def _attach_vlan_to_host(api, host, ip_configuration):
    mgmt_attachment = _get_mgmt_attachment(api, host)
    mgmt_nic_id = mgmt_attachment.get_host_nic().id
    mgmt_nic_name = host.nics.get(id=mgmt_nic_id).name

    vlan_network_attachment = params.NetworkAttachment(
        network=params.Network(name=VLAN100_NET),
        host_nic=params.HostNIC(name=mgmt_nic_name),
        ip_address_assignments=ip_configuration)

    attachment_action = params.Action(
        modified_network_attachments=params.NetworkAttachments(
            network_attachment=[vlan_network_attachment]),
        check_connectivity=True)

    host.setupnetworks(attachment_action)
Example #5
0
    def set_Host(self, host_name, cluster, ifaces):
        HOST = self.get_Host(host_name)
        CLUSTER = self.get_cluster(cluster)

        if HOST is None:
            setMsg("Host does not exist.")
            ifacelist = dict()
            networklist = []
            manageip = ''

            try:
                for iface in ifaces:
                    try:
                        setMsg('creating host interface ' + iface['name'])
                        if 'management' in iface:
                            manageip = iface['ip']
                        if 'boot_protocol' not in iface:
                            if 'ip' in iface:
                                iface['boot_protocol'] = 'static'
                            else:
                                iface['boot_protocol'] = 'none'
                        if 'ip' not in iface:
                            iface['ip'] = ''
                        if 'netmask' not in iface:
                            iface['netmask'] = ''
                        if 'gateway' not in iface:
                            iface['gateway'] = ''

                        if 'network' in iface:
                            if 'bond' in iface:
                                bond = []
                                for slave in iface['bond']:
                                    bond.append(ifacelist[slave])
                                try:
                                    tmpiface = params.Bonding(
                                        slaves=params.Slaves(host_nic=bond),
                                        options=params.Options(
                                            option=[
                                                params.Option(name='miimon', value='100'),
                                                params.Option(name='mode', value='4')
                                            ]
                                        )
                                    )
                                except Exception as e:
                                    setMsg('Failed to create the bond for  ' + iface['name'])
                                    setFailed()
                                    setMsg(str(e))
                                    return False
                                try:
                                    tmpnetwork = params.HostNIC(
                                        network=params.Network(name=iface['network']),
                                        name=iface['name'],
                                        boot_protocol=iface['boot_protocol'],
                                        ip=params.IP(
                                            address=iface['ip'],
                                            netmask=iface['netmask'],
                                            gateway=iface['gateway']
                                        ),
                                        override_configuration=True,
                                        bonding=tmpiface)
                                    networklist.append(tmpnetwork)
                                    setMsg('Applying network ' + iface['name'])
                                except Exception as e:
                                    setMsg('Failed to set' + iface['name'] + ' as network interface')
                                    setFailed()
                                    setMsg(str(e))
                                    return False
                            else:
                                tmpnetwork = params.HostNIC(
                                    network=params.Network(name=iface['network']),
                                    name=iface['name'],
                                    boot_protocol=iface['boot_protocol'],
                                    ip=params.IP(
                                        address=iface['ip'],
                                        netmask=iface['netmask'],
                                        gateway=iface['gateway']
                                    ))
                                networklist.append(tmpnetwork)
                                setMsg('Applying network ' + iface['name'])
                        else:
                            tmpiface = params.HostNIC(
                                name=iface['name'],
                                network=params.Network(),
                                boot_protocol=iface['boot_protocol'],
                                ip=params.IP(
                                    address=iface['ip'],
                                    netmask=iface['netmask'],
                                    gateway=iface['gateway']
                                ))
                        ifacelist[iface['name']] = tmpiface
                    except Exception as e:
                        setMsg('Failed to set ' + iface['name'])
                        setFailed()
                        setMsg(str(e))
                        return False
            except Exception as e:
                setMsg('Failed to set networks')
                setMsg(str(e))
                setFailed()
                return False

            if manageip == '':
                setMsg('No management network is defined')
                setFailed()
                return False

            try:
                HOST = params.Host(name=host_name, address=manageip, cluster=CLUSTER, ssh=params.SSH(authentication_method='publickey'))
                if self.conn.hosts.add(HOST):
                    setChanged()
                    HOST = self.get_Host(host_name)
                    state = HOST.status.state
                    while (state != 'non_operational' and state != 'up'):
                        HOST = self.get_Host(host_name)
                        state = HOST.status.state
                        time.sleep(1)
                        if state == 'non_responsive':
                            setMsg('Failed to add host to RHEVM')
                            setFailed()
                            return False

                    setMsg('status host: up')
                    time.sleep(5)

                    HOST = self.get_Host(host_name)
                    state = HOST.status.state
                    setMsg('State before setting to maintenance: ' + str(state))
                    HOST.deactivate()
                    while state != 'maintenance':
                        HOST = self.get_Host(host_name)
                        state = HOST.status.state
                        time.sleep(1)
                    setMsg('status host: maintenance')

                    try:
                        HOST.nics.setupnetworks(params.Action(
                            force=True,
                            check_connectivity=False,
                            host_nics=params.HostNics(host_nic=networklist)
                        ))
                        setMsg('nics are set')
                    except Exception as e:
                        setMsg('Failed to apply networkconfig')
                        setFailed()
                        setMsg(str(e))
                        return False

                    try:
                        HOST.commitnetconfig()
                        setMsg('Network config is saved')
                    except Exception as e:
                        setMsg('Failed to save networkconfig')
                        setFailed()
                        setMsg(str(e))
                        return False
            except Exception as e:
                if 'The Host name is already in use' in str(e):
                    setMsg("Host already exists")
                else:
                    setMsg("Failed to add host")
                    setFailed()
                    setMsg(str(e))
                return False

            HOST.activate()
            while state != 'up':
                HOST = self.get_Host(host_name)
                state = HOST.status.state
                time.sleep(1)
                if state == 'non_responsive':
                    setMsg('Failed to apply networkconfig.')
                    setFailed()
                    return False
            setMsg('status host: up')
        else:
            setMsg("Host exists.")

        return True
Example #6
0
# Add ovirtmgmt to host
try:
    #data_center=api.datacenters.get(DC_NAME),
    #host = api.hosts.get(HOST_NAME),
    #ovirtmgmt = data_center.networks.get(name='ovirtmgmt')
    #eth = host.nics.get(name=ETH)
    print 'Adding ovirtmgmt to host'
    hostNics = api.hosts.get(HOST_NAME).nics
    # sync
    hostNicsParam = hostNics.list()
    for nic in hostNicsParam:
        nic.set_override_configuration(True)
    attachnic = params.HostNIC(network=params.Network(name='ovirtmgmt'),
                               name='eth0',
                               boot_protocol='static',
                               ip=params.IP(address=IP_ADDRESS,
                                            netmask=IP_NETMASK,
                                            gateway=IP_GATEWAY),
                               override_configuration=1)
    hostNics.setupnetworks(
        params.Action(force=0,
                      check_connectivity=1,
                      host_nics=params.HostNics(host_nic=[attachnic])))
    # Active host
    host = api.hosts.get(HOST_NAME)
    host.activate()
    print 'Waiting for host to reach the Up status'
    while api.hosts.get(HOST_NAME).status.state != 'up':
        sleep(10)
    print "Host is up"
except Exception as e:
Example #7
0
IP_ADDRESS = '192.168.100.11'
MOVE_IP = '192.168.101.11'
NETMASK = '255.255.255.0'
GATEWAY = '192.168.100.1'

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

nic0 = params.HostNIC(network=params.Network(name='rhevm'),
                      name='eth0',
                      boot_protocol='static',
                      ip=params.IP(address=IP_ADDRESS,
                                   netmask=NETMASK,
                                   gateway=GATEWAY),
                      override_configuration=False)
nic1 = params.HostNIC(name='eth1',
                      network=params.Network(),
                      boot_protocol='none',
                      ip=params.IP(address=None, netmask=None, gateway=None))
nic2 = params.HostNIC(name='eth2',
                      network=params.Network(),
                      boot_protocol='none',
                      ip=params.IP(address=None, netmask=None, gateway=None))

# bond
bond0 = params.Bonding(slaves=params.Slaves(host_nic=[nic1, nic2]),
                       options=params.Options(option=[