def _init_vcmp_hosts(self): '''Initialize the data structures for vCMP Hosts and their Guests.''' vcmp_hostnames = self.driver.conf.icontrol_vcmp_hostname.split(',') for vcmp_hostname in vcmp_hostnames: vcmp_host = {} vcmp_host['bigip'] = ManagementRoot( vcmp_hostname, self.driver.conf.icontrol_username, self.driver.conf.icontrol_password) vcmp_host['guests'] = [] try: guests = list( vcmp_host['bigip'].tm.vcmp.guests.get_collection()) except iControlUnexpectedHTTPError as ex: if ex.response.status_code == 400 and \ 'One of the following features must be licensed/' \ 'provisioned for the URI vcmp : vcmp' in ex.message: msg = 'VcmpManager::_init_vcmp_hosts: Given vCMP host ' \ '{0} is not licensed for vCMP. Device returned '\ 'exception: {1}'.format(vcmp_hostname, ex) raise BigIPNotLicensedForVcmp(msg) else: raise(ex) except Exception as ex: raise(ex) for guest in guests: if utils.strip_cidr_netmask( guest.managementIp) in self.driver.get_bigip_hosts(): vcmp_host['guests'].append(guest) self.vcmp_hosts.append(vcmp_host) self._check_vcmp_host_assignments() for vcmp_host in self.vcmp_hosts: for vcmp_guest in vcmp_host['guests']: LOG.debug(('VcmpManager::_init_vcmp_hosts: vCMPHost[%s] ' 'vCMPGuest[%s] - mgmt: %s' % ( vcmp_host['bigip'].hostname, vcmp_guest.name, utils.strip_cidr_netmask( vcmp_guest.managementIp))))
def _init_vcmp_hosts(self): '''Initialize the data structures for vCMP Hosts and their Guests.''' vcmp_hostnames = self.driver.conf.icontrol_vcmp_hostname.split(',') for vcmp_hostname in vcmp_hostnames: vcmp_host = {} vcmp_host['bigip'] = ManagementRoot( vcmp_hostname, self.driver.conf.icontrol_username, self.driver.conf.icontrol_password) vcmp_host['guests'] = [] try: guests = list( vcmp_host['bigip'].tm.vcmp.guests.get_collection()) except iControlUnexpectedHTTPError as ex: if ex.response.status_code == 400 and \ 'One of the following features must be licensed/' \ 'provisioned for the URI vcmp : vcmp' in ex.message: msg = 'VcmpManager::_init_vcmp_hosts: Given vCMP host {0} ' \ 'is not licensed for vCMP. Device returned exception: ' \ '{1}'.format(vcmp_hostname, ex) raise BigIPNotLicensedForVcmp(msg) else: raise(ex) except Exception as ex: raise(ex) for guest in guests: if utils.strip_cidr_netmask( guest.managementIp) in self.driver.get_bigip_hosts(): vcmp_host['guests'].append(guest) self.vcmp_hosts.append(vcmp_host) self._check_vcmp_host_assignments() for vcmp_host in self.vcmp_hosts: for vcmp_guest in vcmp_host['guests']: LOG.debug(('VcmpManager::_init_vcmp_hosts: vCMPHost[%s] ' 'vCMPGuest[%s] - mgmt: %s' % ( vcmp_host['bigip'].hostname, vcmp_guest.name, utils.strip_cidr_netmask( vcmp_guest.managementIp))))
def get_vcmp_host(self, bigip): '''Find host for a particular bigip :param bigip: ManagementRoot object -- bigip to find in guests :returns: dict or None ''' for vcmp_host in self.vcmp_hosts: for vcmp_guest in vcmp_host['guests']: if utils.strip_cidr_netmask( vcmp_guest.managementIp) == bigip.hostname: vcmp_host['bigip'].tm.refresh() return vcmp_host return None
def get_vcmp_guest(self, vcmp_host, bigip): '''Find the appropriate guest object for a given bigip. :param vcmp_host: dict -- dict of vCMP host and guests :param bigip: ManagementRoot object -- bigip object to find in guests :returns: ManagementRoot object or None ''' for vcmp_guest in vcmp_host['guests']: if utils.strip_cidr_netmask( vcmp_guest.managementIp) == bigip.hostname: vcmp_guest.refresh() return vcmp_guest return None
def test_strip_cidr_netmask_exception(self): with pytest.raises(IpNotInCidrNotation) as ex: utils.strip_cidr_netmask('10.1.1.1') assert '' in ex.value.message
def test_strip_cidr_netmask(self): addy = utils.strip_cidr_netmask('10.1.1.1/21') assert addy == '10.1.1.1'