def _from_network_info(network, mapping, tenant_id): vif_uuid = mapping.get('vif_uuid') if not vif_uuid: LOG.debug("vif_uuid is None") return None ctxt = context.get_admin_context() vif_ref = db.virtual_interface_get_by_uuid(ctxt, vif_uuid) if not vif_ref: LOG.debug("vif_ref is None") return None network_ref = vif_ref.network if not network_ref: LOG.debug("network_ref is None") return None network_uuid = network_ref.uuid if not network_uuid: LOG.debug("network_uuid is None") return None vifinfo_uuid = _get_vifinfo_uuid(tenant_id, network_uuid, vif_uuid) if not vifinfo_uuid: LOG.debug("vifinfo_uuid is None") return None LOG.debug("ips = %s", mapping.get('ips', [])) ips = [] for i in mapping.get('ips', []): ips.append(i['ip']) return (vifinfo_uuid, network_uuid, ips)
def _from_network_info(network, mapping, tenant_id): vif_uuid = mapping.get('vif_uuid') if not vif_uuid: LOG.debug("vif_uuid is None") return None ctxt = context.get_admin_context() vif_ref = db.virtual_interface_get_by_uuid(ctxt, vif_uuid) if not vif_ref: LOG.debug("vif_ref is None") return None network_ref = vif_ref.network if not network_ref: LOG.debug("network_ref is None") return None network_uuid = network_ref.uuid if not network_uuid: LOG.debug("network_uuid is None") return None vifinfo_uuid = _get_vifinfo_uuid(tenant_id, network_uuid, vif_uuid) if not vifinfo_uuid: LOG.debug("vifinfo_uuid is None") return None LOG.debug("ips = %s", mapping.get('ips', [])) ips = [] for i in mapping.get('ips', []): ips.append(i['ip']) return (vifinfo_uuid, network_uuid, ips)
def get_v4_ips_by_interface(self, context, net_id, vif_id, project_id): """Returns a list of IPv4 address strings associated with the specified virtual interface, based on the fixed_ips table. """ vif_rec = db.virtual_interface_get_by_uuid(context, vif_id) fixed_ips = db.fixed_ips_by_virtual_interface(context, vif_rec['id']) return [fixed_ip['address'] for fixed_ip in fixed_ips]
def get_v4_ips_by_interface(self, context, net_id, vif_id, project_id): """Returns a list of IPv4 address strings associated with the specified virtual interface, based on the fixed_ips table. """ vif_rec = db.virtual_interface_get_by_uuid(context, vif_id) fixed_ips = db.fixed_ips_by_virtual_interface(context, vif_rec["id"]) return [fixed_ip["address"] for fixed_ip in fixed_ips]
def get_v4_ips_by_interface(self, context, net_id, vif_id, project_id): """Returns a list of IPv4 address strings associated with the specified virtual interface, based on the fixed_ips table. """ # TODO(tr3buchet): link fixed_ips to vif by uuid so only 1 db call vif_rec = db.virtual_interface_get_by_uuid(context, vif_id) fixed_ips = db.fixed_ips_by_virtual_interface(context, vif_rec['id']) return [fixed_ip['address'] for fixed_ip in fixed_ips]
def get_v4_ips_by_interface(self, context, net_id, vif_id, project_id): """Returns a list of IPv4 address strings associated with the specified virtual interface, based on the fixed_ips table. """ # TODO(tr3buchet): link fixed_ips to vif by uuid so only 1 db call vif_rec = db.virtual_interface_get_by_uuid(context, vif_id) if not vif_rec or not vif_rec['id']: return [] fixed_ips = db.fixed_ips_by_virtual_interface(context, vif_rec['id']) return [fixed_ip['address'] for fixed_ip in fixed_ips]
def get_v6_ips_by_interface(self, context, net_id, vif_id, project_id): """Returns a list containing a single IPv6 address strings associated with the specified virtual interface. """ admin_context = context.elevated() network = db.network_get_by_uuid(admin_context, net_id) vif_rec = db.virtual_interface_get_by_uuid(context, vif_id) if network["cidr_v6"]: ip = ipv6.to_global(network["cidr_v6"], vif_rec["address"], project_id) return [ip] return []
def get_dhcp_hosts_text(self, context, subnet_id, project_id=None): ips = self.ipam.get_allocated_ips(context, subnet_id, project_id) hosts_text = "" admin_context = context.elevated() for ip in ips: address, vif_id = ip vif = db.virtual_interface_get_by_uuid(admin_context, vif_id) mac_address = vif["address"] text = "%s,%s.%s,%s\n" % (mac_address, "host-" + address, FLAGS.dhcp_domain, address) hosts_text += text LOG.debug("DHCP hosts: %s" % hosts_text) return hosts_text
def get_v6_ips_by_interface(self, context, net_id, vif_id, project_id): """Returns a list containing a single IPv6 address strings associated with the specified virtual interface. """ admin_context = context.elevated() network = db.network_get_by_uuid(admin_context, net_id) vif_rec = db.virtual_interface_get_by_uuid(context, vif_id) if network['cidr_v6']: ip = ipv6.to_global(network['cidr_v6'], vif_rec['address'], project_id) return [ip] return []
def get_dhcp_hosts_text(self, context, subnet_id, project_id=None): ips = self.ipam.get_allocated_ips(context, subnet_id, project_id) hosts_text = "" admin_context = context.elevated() for ip in ips: address, vif_id = ip vif = db.virtual_interface_get_by_uuid(admin_context, vif_id) mac_address = vif['address'] text = "%s,%s.%s,%s\n" % (mac_address, "host-" + address, FLAGS.dhcp_domain, address) hosts_text += text LOG.debug("DHCP hosts: %s" % hosts_text) return hosts_text
def get_dhcp_leases(self, context, network_ref): """Return a network's hosts config in dnsmasq leasefile format.""" subnet_id = network_ref["uuid"] project_id = network_ref["project_id"] ips = self.ipam.get_allocated_ips(context, subnet_id, project_id) leases_text = "" admin_context = context.elevated() for ip in ips: address, vif_id = ip vif = db.virtual_interface_get_by_uuid(admin_context, vif_id) mac_address = vif["address"] text = "%s %s %s %s *\n" % (int(time.time()) - FLAGS.dhcp_lease_time, mac_address, address, "*") leases_text += text LOG.debug("DHCP leases: %s" % leases_text) return leases_text
def get_dhcp_leases(self, context, network_ref): """Return a network's hosts config in dnsmasq leasefile format.""" subnet_id = network_ref['uuid'] project_id = network_ref['project_id'] ips = self.ipam.get_allocated_ips(context, subnet_id, project_id) leases_text = "" admin_context = context.elevated() for ip in ips: address, vif_id = ip vif = db.virtual_interface_get_by_uuid(admin_context, vif_id) mac_address = vif['address'] text = "%s %s %s %s *\n" % \ (int(time.time()) - FLAGS.dhcp_lease_time, mac_address, address, '*') leases_text += text LOG.debug("DHCP leases: %s" % leases_text) return leases_text
def get_by_uuid(cls, context, vif_uuid): db_vif = db.virtual_interface_get_by_uuid(context, vif_uuid) if db_vif: return cls._from_db_object(context, cls(), db_vif)
def get_by_uuid(cls, context, vif_uuid): db_vif = db.virtual_interface_get_by_uuid(context, vif_uuid) if db_vif: return cls._from_db_object(context, cls(), db_vif)