Example #1
0
 def get_allocated_ips(self, context, subnet_id, project_id):
     """Returns a list of (ip, vif_id) pairs"""
     admin_context = context.elevated()
     ips = db.fixed_ip_get_all(admin_context)
     allocated_ips = []
     # Get all allocated IPs that are part of this subnet
     network = db.network_get_by_uuid(admin_context, subnet_id)
     for ip in ips:
         # Skip unallocated IPs
         if not ip["allocated"] == 1:
             continue
         if ip["network_id"] == network["id"]:
             vif = db.virtual_interface_get(admin_context, ip["virtual_interface_id"])
             allocated_ips.append((ip["address"], vif["uuid"]))
     return allocated_ips
Example #2
0
 def get_allocated_ips(self, context, subnet_id, project_id):
     """Returns a list of (ip, vif_id) pairs"""
     admin_context = context.elevated()
     ips = db.fixed_ip_get_all(admin_context)
     allocated_ips = []
     # Get all allocated IPs that are part of this subnet
     network = db.network_get_by_uuid(admin_context, subnet_id)
     for ip in ips:
         # Skip unallocated IPs
         if not ip['allocated'] == 1:
             continue
         if ip['network_id'] == network['id']:
             vif = db.virtual_interface_get(admin_context,
                                            ip['virtual_interface_id'])
             allocated_ips.append((ip['address'], vif['uuid']))
     return allocated_ips
Example #3
0
def get_dhcp_hosts(context, network_ref):
    """Get network's hosts config in dhcp-host format."""
    hosts = []
    for fixed_ref in db.network_get_associated_fixed_ips(context, network_ref["id"]):
        vif_id = fixed_ref["virtual_interface_id"]
        # NOTE(jkoelker) We need a larger refactor to happen to prevent
        #                looking these up here
        vif_ref = db.virtual_interface_get(context, vif_id)
        instance_id = fixed_ref["instance_id"]
        try:
            instance_ref = db.instance_get(context, instance_id)
        except exception.InstanceNotFound:
            msg = _("Instance %(instance_id)s not found")
            LOG.debug(msg % {"instance_id": instance_id})
            continue
        if network_ref["multi_host"] and FLAGS.host != instance_ref["host"]:
            continue
        hosts.append(_host_dhcp(fixed_ref, vif_ref, instance_ref))
    return "\n".join(hosts)
Example #4
0
def get_dhcp_leases(context, network_ref):
    """Return a network's hosts config in dnsmasq leasefile format."""
    hosts = []
    for fixed_ref in db.network_get_associated_fixed_ips(context,
                                                         network_ref['id']):
        vif_id = fixed_ref['virtual_interface_id']
        # NOTE(jkoelker) We need a larger refactor to happen to prevent
        #                looking these up here
        vif_ref = db.virtual_interface_get(context, vif_id)
        instance_id = fixed_ref['instance_id']
        try:
            instance_ref = db.instance_get(context, instance_id)
        except exception.InstanceNotFound:
            msg = _("Instance %(instance_id)s not found")
            LOG.debug(msg % {'instance_id': instance_id})
            continue
        if network_ref['multi_host'] and FLAGS.host != instance_ref['host']:
            continue
        hosts.append(_host_lease(fixed_ref, vif_ref, instance_ref))
    return '\n'.join(hosts)
Example #5
0
def get_dhcp_hosts(context, network_ref):
    """Get network's hosts config in dhcp-host format."""
    hosts = []
    for fixed_ref in db.network_get_associated_fixed_ips(
            context, network_ref['id']):
        vif_id = fixed_ref['virtual_interface_id']
        # NOTE(jkoelker) We need a larger refactor to happen to prevent
        #                looking these up here
        vif_ref = db.virtual_interface_get(context, vif_id)
        instance_id = fixed_ref['instance_id']
        try:
            instance_ref = db.instance_get(context, instance_id)
        except exception.InstanceNotFound:
            msg = _("Instance %(instance_id)s not found")
            LOG.debug(msg % {'instance_id': instance_id})
            continue
        if network_ref['multi_host'] and FLAGS.host != instance_ref['host']:
            continue
        hosts.append(_host_dhcp(fixed_ref, vif_ref, instance_ref))
    return '\n'.join(hosts)
 def get_by_id(cls, context, vif_id):
     db_vif = db.virtual_interface_get(context, vif_id)
     if db_vif:
         return cls._from_db_object(context, cls(), db_vif)
 def get_by_id(cls, context, vif_id):
     db_vif = db.virtual_interface_get(context, vif_id)
     if db_vif:
         return cls._from_db_object(context, cls(), db_vif)