def test_get_ea_for_network(self): network = {'id': mock.Mock(), 'name': mock.Mock(), 'provider:network_type': mock.Mock(), 'provider:physical_network': mock.Mock(), 'provider:segmentation_id': mock.Mock(), 'router:external': True, 'shared': True} subnet = {'id': mock.Mock(), 'name': mock.Mock()} mapping = {'Subnet ID': subnet['id'], 'Subnet Name': subnet['name'], 'Network ID': network['id'], 'Network Name': network['name'], 'Network Encap': network['provider:network_type'], 'Segmentation ID': network['provider:segmentation_id'], 'Physical Network Name': ( network['provider:physical_network']), 'Tenant ID': self.tenant_id, 'Tenant Name': self.tenant_name, 'Account': self.user_id, 'Is External': str(True), 'Is Shared': str(True), 'Cloud API Owned': str(False)} ea = ea_manager.get_ea_for_network(self.user_id, self.tenant_id, self.tenant_name, network, subnet) for key, value in mapping.items(): self.assertEqual(mapping[key], ea.get(key))
def update_subnet_details(self, ib_network): ea_network = eam.get_ea_for_network(self.ib_cxt.user_id, self.ib_cxt.tenant_id, self.ib_cxt.tenant_name, self.ib_cxt.network, self.ib_cxt.subnet) nameservers = self.ib_cxt.mapping.ib_nameservers if nameservers: nameservers_option_val = ','.join(nameservers) opt_dns = [ opt for opt in ib_network.options if opt.name == 'domain-name-servers' ] if opt_dns: opt_dns[0].value = nameservers_option_val else: ib_network.options.append( ib_objects.DhcpOption(name='domain-name-servers', value=nameservers_option_val)) else: ib_network.options = [ opt for opt in ib_network.options if opt.name != 'domain-name-servers' ] self.ib_cxt.ibom.update_network_options(ib_network, ea_network) self._restart_services()
def test_get_ea_for_network(self): network = { 'id': mock.Mock(), 'name': mock.Mock(), 'provider:network_type': mock.Mock(), 'provider:physical_network': mock.Mock(), 'provider:segmentation_id': mock.Mock(), 'router:external': True, 'shared': True } subnet = {'id': mock.Mock(), 'name': mock.Mock()} mapping = { 'Subnet ID': subnet['id'], 'Subnet Name': subnet['name'], 'Network ID': network['id'], 'Network Name': network['name'], 'Network Encap': network['provider:network_type'], 'Segmentation ID': network['provider:segmentation_id'], 'Physical Network Name': (network['provider:physical_network']), 'Tenant ID': self.tenant_id, 'Tenant Name': self.tenant_name, 'Account': self.user_id, 'Is External': str(True), 'Is Shared': str(True), 'Cloud API Owned': str(False) } ea = ea_manager.get_ea_for_network(self.user_id, self.tenant_id, self.tenant_name, network, subnet) for key, value in list(mapping.items()): self.assertEqual(mapping[key], ea.get(key))
def _create_ib_network(self): network_view = self.ib_cxt.mapping.network_view network = self.ib_cxt.network subnet = self.ib_cxt.subnet cidr = subnet.get('cidr') gateway_ip = subnet.get('gateway_ip') ea_network = eam.get_ea_for_network(self.ib_cxt.user_id, self.ib_cxt.tenant_id, self.ib_cxt.tenant_name, network, subnet) network_template = self.grid_config.network_template # check if network already exists ib_network = ib_objects.Network.search(self.ib_cxt.connector, network_view=network_view, cidr=cidr) if ib_network: if self.ib_cxt.network_is_shared_or_external: self.ib_cxt.reserve_service_members(ib_network) self.ib_cxt.ibom.update_network_options(ib_network, ea_network) LOG.info("ib network already exists so updated options: %s", ib_network) return ib_network, False raise exc.InfobloxPrivateSubnetAlreadyExist() # network creation using template if network_template: ib_network = self.ib_cxt.ibom.create_network_from_template( self.ib_cxt.mapping.network_view, cidr, network_template, ea_network) self._register_mapping_member() self.ib_cxt.reserve_service_members(ib_network) self.ib_cxt.ibom.update_network_options(ib_network, ea_network) LOG.info("ib network created from template %s: %s", network_template, ib_network) return ib_network, True # network creation starts self.ib_cxt.reserve_service_members() relay_trel_ip = None ib_network = self.ib_cxt.ibom.create_network( self.ib_cxt.mapping.network_view, cidr, self.ib_cxt.mapping.ib_nameservers, self.ib_cxt.mapping.ib_dhcp_members, gateway_ip, relay_trel_ip, ea_network) self._register_mapping_member() LOG.info("ib network has been created: %s", ib_network) self._restart_services() return ib_network, True
def _create_ib_network(self): network_view = self.ib_cxt.mapping.network_view network = self.ib_cxt.network subnet = self.ib_cxt.subnet cidr = subnet.get('cidr') gateway_ip = subnet.get('gateway_ip') ea_network = eam.get_ea_for_network(self.ib_cxt.user_id, self.ib_cxt.tenant_id, self.ib_cxt.tenant_name, network, subnet) network_template = self.grid_config.network_template # check if network already exists ib_network = ib_objects.Network.search(self.ib_cxt.connector, network_view=network_view, cidr=cidr) if ib_network: if self.ib_cxt.network_is_shared_or_external: self.ib_cxt.reserve_service_members(ib_network) self.ib_cxt.ibom.update_network_options(ib_network, ea_network) LOG.info("ib network already exists so updated options: %s", ib_network) return ib_network, False raise exc.InfobloxPrivateSubnetAlreadyExist() # network creation using template if network_template: ib_network = self.ib_cxt.ibom.create_network_from_template( self.ib_cxt.mapping.network_view, cidr, network_template, ea_network) self._register_mapping_member() self.ib_cxt.reserve_service_members(ib_network) self.ib_cxt.ibom.update_network_options(ib_network, ea_network) LOG.info("ib network created from template %s: %s", network_template, ib_network) return ib_network, True # network creation starts self.ib_cxt.reserve_service_members() relay_trel_ip = None ib_network = self.ib_cxt.ibom.create_network( self.ib_cxt.mapping.network_view, cidr, self.ib_cxt.mapping.ib_nameservers, self.ib_cxt.mapping.ib_dhcp_members, gateway_ip, relay_trel_ip, ea_network) self._register_mapping_member() LOG.info("ib network has been created: %s", ib_network) self._restart_services() return ib_network, True
def update_network_sync(self, need_new_zones=False): """Updates EAs for each subnet that belongs to the updated network.""" session = self.ib_cxt.context.session network = self.ib_cxt.network network_id = network.get('id') subnets = dbi.get_subnets_by_network_id(session, network_id) for subnet in subnets: network_view = None cidr = subnet.get('cidr') subnet_id = subnet.get('id') netview_mappings = dbi.get_network_view_mappings( session, network_id=network_id, subnet_id=subnet_id) if netview_mappings: netview_row = utils.find_one_in_list( 'id', netview_mappings[0].network_view_id, self.ib_cxt.discovered_network_views) network_view = netview_row.network_view ib_network = None if network_view: ib_network = self.ib_cxt.ibom.get_network(network_view, cidr) ea_network = eam.get_ea_for_network(self.ib_cxt.user_id, self.ib_cxt.tenant_id, self.ib_cxt.tenant_name, network, subnet) self.ib_cxt.ibom.update_network_options(ib_network, ea_network) if need_new_zones: # Need context with ib_network to create zones ib_cxt = context.InfobloxContext(self.ib_cxt.context, self.ib_cxt.user_id, network, subnet, self.grid_config, self.ib_cxt.plugin, ib_network=ib_network) dns_controller = dns.DnsController(ib_cxt) rollback_list = [] dns_controller.create_dns_zones(rollback_list) else: self.ib_cxt.subnet = subnet dns_controller = dns.DnsController(self.ib_cxt) dns_controller.update_dns_zones()
def update_network_sync(self, need_new_zones=False): """Updates EAs for each subnet that belongs to the updated network.""" session = self.ib_cxt.context.session network = self.ib_cxt.network network_id = network.get('id') subnets = dbi.get_subnets_by_network_id(session, network_id) for subnet in subnets: network_view = None cidr = subnet.get('cidr') subnet_id = subnet.get('id') netview_mappings = dbi.get_network_view_mappings( session, network_id=network_id, subnet_id=subnet_id) if netview_mappings: netview_row = utils.find_one_in_list( 'id', netview_mappings[0].network_view_id, self.ib_cxt.discovered_network_views) network_view = netview_row.network_view ib_network = None if network_view: ib_network = self.ib_cxt.ibom.get_network(network_view, cidr) ea_network = eam.get_ea_for_network(self.ib_cxt.user_id, self.ib_cxt.tenant_id, self.ib_cxt.tenant_name, network, subnet) self.ib_cxt.ibom.update_network_options(ib_network, ea_network) if need_new_zones: # Need context with ib_network to create zones ib_cxt = context.InfobloxContext( self.ib_cxt.context, self.ib_cxt.user_id, network, subnet, self.grid_config, self.ib_cxt.plugin, ib_network=ib_network) dns_controller = dns.DnsController(ib_cxt) rollback_list = [] dns_controller.create_dns_zones(rollback_list) else: self.ib_cxt.subnet = subnet dns_controller = dns.DnsController(self.ib_cxt) dns_controller.update_dns_zones()
def update_subnet_details(self, ib_network): ea_network = eam.get_ea_for_network(self.ib_cxt.user_id, self.ib_cxt.tenant_id, self.ib_cxt.tenant_name, self.ib_cxt.network, self.ib_cxt.subnet) nameservers = self.ib_cxt.mapping.ib_nameservers if nameservers: nameservers_option_val = ','.join(nameservers) 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=nameservers_option_val)) else: opt_dns[0].value = nameservers_option_val self.ib_cxt.ibom.update_network_options(ib_network, ea_network) self._restart_services()