def _update_dns_db(self, dns_name, dns_domain, db_data, plugin_context, has_fixed_ips): dns_data_db = plugin_context.session.query( dns_db.PortDNS).filter_by(port_id=db_data['id']).one_or_none() if dns_data_db: is_dns_name_changed = (dns_name is not None and dns_data_db['current_dns_name'] != dns_name) if is_dns_name_changed or (has_fixed_ips and dns_data_db['current_dns_name']): dns_data_db['previous_dns_name'] = ( dns_data_db['current_dns_name']) dns_data_db['previous_dns_domain'] = ( dns_data_db['current_dns_domain']) if is_dns_name_changed: dns_data_db[dns.DNSNAME] = dns_name dns_data_db['current_dns_name'] = dns_name if dns_name: dns_data_db['current_dns_domain'] = dns_domain else: dns_data_db['current_dns_domain'] = '' return dns_data_db if dns_name: dns_data_db = dns_db.PortDNS(port_id=db_data['id'], current_dns_name=dns_name, current_dns_domain=dns_domain, previous_dns_name='', previous_dns_domain='', dns_name=dns_name) plugin_context.session.add(dns_data_db) return dns_data_db
def process_create_port(self, plugin_context, request_data, db_data): if not request_data[dns.DNSNAME]: return network = self._get_network(plugin_context, db_data['network_id']) if not network[dns.DNSDOMAIN]: return if self.external_dns_not_needed(plugin_context, network): return plugin_context.session.add( dns_db.PortDNS(port_id=db_data['id'], current_dns_name=request_data[dns.DNSNAME], current_dns_domain=network[dns.DNSDOMAIN], previous_dns_name='', previous_dns_domain=''))
def _process_only_dns_name_update(self, plugin_context, db_data, dns_name): dns_data_db = plugin_context.session.query( dns_db.PortDNS).filter_by(port_id=db_data['id']).one_or_none() if dns_data_db: dns_data_db['dns_name'] = dns_name return dns_data_db if dns_name: dns_data_db = dns_db.PortDNS(port_id=db_data['id'], current_dns_name='', current_dns_domain='', previous_dns_name='', previous_dns_domain='', dns_name=dns_name) plugin_context.session.add(dns_data_db) return dns_data_db
def process_create_port(self, plugin_context, request_data, db_data): if not request_data.get(dns.DNSNAME): return dns_name, is_dns_domain_default = self._get_request_dns_name( request_data) if is_dns_domain_default: return network = self._get_network(plugin_context, db_data['network_id']) if self.external_dns_not_needed( plugin_context, network) or not network[dns.DNSDOMAIN]: current_dns_name = '' current_dns_domain = '' else: current_dns_name = dns_name current_dns_domain = network[dns.DNSDOMAIN] plugin_context.session.add(dns_db.PortDNS( port_id=db_data['id'], current_dns_name=current_dns_name, current_dns_domain=current_dns_domain, previous_dns_name='', previous_dns_domain='', dns_name=dns_name))
def process_update_port(self, plugin_context, request_data, db_data): dns_name = request_data.get(dns.DNSNAME) has_fixed_ips = 'fixed_ips' in request_data if dns_name is None and not has_fixed_ips: return network = self._get_network(plugin_context, db_data['network_id']) if not network[dns.DNSDOMAIN]: return if self.external_dns_not_needed(plugin_context, network): return dns_domain = network[dns.DNSDOMAIN] dns_data_db = plugin_context.session.query( dns_db.PortDNS).filter_by(port_id=db_data['id']).one_or_none() if dns_data_db: is_dns_name_changed = (dns_name is not None and dns_data_db['current_dns_name'] != dns_name) if is_dns_name_changed or (has_fixed_ips and dns_data_db['current_dns_name']): dns_data_db['previous_dns_name'] = ( dns_data_db['current_dns_name']) dns_data_db['previous_dns_domain'] = ( dns_data_db['current_dns_domain']) if is_dns_name_changed: dns_data_db['current_dns_name'] = dns_name if dns_name: dns_data_db['current_dns_domain'] = dns_domain else: dns_data_db['current_dns_domain'] = '' return if dns_name: plugin_context.session.add( dns_db.PortDNS(port_id=db_data['id'], current_dns_name=dns_name, current_dns_domain=dns_domain, previous_dns_name='', previous_dns_domain=''))
def process_update_port(self, plugin_context, request_data, db_data): dns_name = request_data.get(dns.DNSNAME) if dns_name is None: return network = self._get_network(plugin_context, db_data['network_id']) if not network[dns.DNSDOMAIN]: return if self.external_dns_not_needed(plugin_context, network): return dns_domain = network[dns.DNSDOMAIN] dns_data_db = plugin_context.session.query( dns_db.PortDNS).filter_by(port_id=db_data['id']).one_or_none() if dns_data_db: if dns_name: if dns_data_db['current_dns_name'] != dns_name: dns_data_db['previous_dns_name'] = ( dns_data_db['current_dns_name']) dns_data_db['previous_dns_domain'] = ( dns_data_db['current_dns_domain']) dns_data_db['current_dns_name'] = dns_name dns_data_db['current_dns_domain'] = dns_domain return if dns_data_db['current_dns_name']: dns_data_db['previous_dns_name'] = ( dns_data_db['current_dns_name']) dns_data_db['previous_dns_domain'] = ( dns_data_db['current_dns_domain']) dns_data_db['current_dns_name'] = '' dns_data_db['current_dns_domain'] = '' return if dns_name: plugin_context.session.add( dns_db.PortDNS(port_id=db_data['id'], current_dns_name=dns_name, current_dns_domain=dns_domain, previous_dns_name='', previous_dns_domain=''))