def test_is_valid_ip(self): ips = ('192.168.0.1', '8.8.8.8', 'fffe::1') for ip in ips: self.assertEqual(True, utils.is_valid_ip(ip)) # test negative cases ips = ('192.data.0.1', 'text', None, '192.168.159.658') for ip in ips: self.assertEqual(False, utils.is_valid_ip(ip))
def update_nameservers(self, dhcp_port_ip): # if user provies nameservers, no need to do anything nameservers = self.subnet.get('dns_nameservers') or [] if nameservers: return if (self.grid_config.relay_support is False or utils.is_valid_ip(dhcp_port_ip) is False): return cidr = self.subnet['cidr'] ib_network = self.ibom.get_network(self.mapping.network_view, cidr) if not ib_network: LOG.error("Infoblox network with %s does not exist.", cidr) return opt_dns = [ opt for opt in ib_network.options if opt.name == 'domain-name-servers' ] if not opt_dns: ib_network.options.append( ib_objects.DhcpOption(name='domain-name-servers', value=dhcp_port_ip)) else: opt_dns[0].value = dhcp_port_ip ib_network.update()
def update_nameservers(self, dhcp_port_ip): # if user provies nameservers, no need to do anything nameservers = self.subnet.get('dns_nameservers') or [] if nameservers: return if (self.grid_config.relay_support is False or utils.is_valid_ip(dhcp_port_ip) is False): return cidr = self.subnet['cidr'] ib_network = self.ibom.get_network(self.mapping.network_view, cidr) if not ib_network: LOG.error("Infoblox network with %s does not exist.", cidr) return opt_dns = [opt for opt in ib_network.options if opt.name == 'domain-name-servers'] if not opt_dns: ib_network.options.append( ib_objects.DhcpOption(name='domain-name-servers', value=dhcp_port_ip)) else: opt_dns[0].value = dhcp_port_ip ib_network.update()
def _get_gm_info(self): """Get detail GM info. 'grid_master_host' configuration accepts host IP or name of GM, so we need to figure whether hostname is used or ip address for either ipv4 or ipv6. """ gm_ipv4 = None gm_ipv6 = None gm_hostname = None gm_host = self._grid_config.grid_master_host if utils.is_valid_ip(gm_host): ip_version = utils.get_ip_version(gm_host) if ip_version == 4: gm_ipv4 = gm_host else: gm_ipv6 = gm_host else: gm_hostname = gm_host return {'ipv4': gm_ipv4, 'ipv6': gm_ipv6, 'host': gm_hostname}