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])
示例#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])
        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:
    pm = params.PowerManagement()
    pm.set_type('xvm')
    # Note: Fencing type xvm is for nested HV
    # Note: And this needs to be added to RHEV first
    pm.set_enabled(True)
    pm.set_address(PM_ADDRESS)
    pm.set_username('root')
    pm.set_password('Secret')
    pm.set_options(params.Options(option=[
                   params.Option(name='domain', value='rhev-h-3')]))
    pm.set_kdump_detection(True)

    if api.hosts.add(params.Host(name=HOST_NAME,
                     address=HOST_ADDRESS,
                     cluster=api.clusters.get(CLUSTER_NAME),
                     root_password=ROOT_PASSWORD,
                     power_management=pm)):
        print 'Host was added successfully'
        print 'Waiting for host to install and reach the Up status'
        while api.hosts.get(HOST_NAME).status.state != 'up':
            time.sleep(1)
        print "Host is up"
    if api.hosts.get(HOST_NAME).deactivate():
        print 'Setting Host to maintenance'
        print 'Waiting for host to reach maintenance status'
示例#4
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
示例#5
0
                                   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=[
                           params.Option(name='miimon', value='100'),
                           params.Option(name='mode', value='1'),
                           params.Option(name='primary', value='eth1')
                       ]))

# management network on top of the bond
backendNetwork = params.HostNIC(name='bond0',
                                boot_protocol='none',
                                override_configuration=True,
                                bonding=bond0)

# Now apply the rhevm network configuration
try:
    host = api.hosts.get(HOST_NAME)
    host.nics.setupnetworks(
        params.Action(
            force=False,