def get_host(cls, cli, _id, force_create=False): if isinstance(_id, six.string_types) and ('.' in _id or ':' in _id): # it looks like an ip address, find or create the host address = converter.url_to_host(_id) netmask = converter.url_to_mask(_id) ports = UnityHostIpPortList(cli=cli, address=address) if len(ports) == 1: ret = ports[0].host elif force_create: log.info('cannot find an existing host with ip {}. ' 'create a new host "{}" to attach it.'.format( address, address)) host_type = (HostTypeEnum.SUBNET if netmask else HostTypeEnum.HOST_MANUAL) host_name = ('{}_{}'.format(address, netmask) if netmask else address) host = cls.create(cli, host_name, host_type=host_type) host.add_ip_port(address, netmask=netmask) ret = host else: ret = None else: ret = cls.get(cli=cli, _id=_id) return ret
def get_host(cls, cli, _id, force_create=False): if isinstance(_id, six.string_types) and ('.' in _id or ':' in _id): # it looks like an ip address, find or create the host address = converter.url_to_host(_id) netmask = converter.url_to_mask(_id) ports = UnityHostIpPortList(cli=cli, address=address) if len(ports) == 1: ret = ports[0].host elif force_create: log.info('cannot find an existing host with ip {}. ' 'create a new host "{}" to attach it.' .format(address, address)) host_type = (HostTypeEnum.SUBNET if netmask else HostTypeEnum.HOST_MANUAL) host_name = ('{}_{}'.format(address, netmask) if netmask else address) host = cls.create(cli, host_name, host_type=host_type) host.add_ip_port(address, netmask=netmask) ret = host else: ret = None else: ret = cls.get(cli=cli, _id=_id) return ret
def test_url_to_mask_7_bit(self): url = 'https://10.244.211.30/7' ret = converter.url_to_mask(url) assert_that(ret, equal_to('254.0.0.0'))
def test_url_to_mask_29_bit(self): url = 'https://10.244.211.30/30' ret = converter.url_to_mask(url) assert_that(ret, equal_to('255.255.255.252'))
def test_url_to_mask_normal(self): url = 'https://10.244.211.30/24' ret = converter.url_to_mask(url) assert_that(ret, equal_to('255.255.255.0'))