예제 #1
0
파일: manage.py 프로젝트: RibeiroAna/nova
    def list(self, host=None):
        """Lists all fixed ips (optionally by host)."""
        ctxt = context.get_admin_context()

        try:
            if host is None:
                fixed_ips = db.fixed_ip_get_all(ctxt)
            else:
                fixed_ips = db.fixed_ip_get_by_host(ctxt, host)

        except exception.NotFound as ex:
            print(_("error: %s") % ex)
            return(2)

        instances = db.instance_get_all(context.get_admin_context())
        instances_by_uuid = {}
        for instance in instances:
            instances_by_uuid[instance['uuid']] = instance

        print("%-18s\t%-15s\t%-15s\t%s" % (_('network'),
                                              _('IP address'),
                                              _('hostname'),
                                              _('host')))

        all_networks = {}
        try:
            # use network_get_all to retrieve all existing networks
            # this is to ensure that IPs associated with deleted networks
            # will not throw exceptions.
            for network in db.network_get_all(context.get_admin_context()):
                all_networks[network.id] = network
        except exception.NoNetworksFound:
            # do not have any networks, so even if there are IPs, these
            # IPs should have been deleted ones, so return.
            print(_('No fixed IP found.'))
            return

        has_ip = False
        for fixed_ip in fixed_ips:
            hostname = None
            host = None
            network = all_networks.get(fixed_ip['network_id'])
            if network:
                has_ip = True
                if fixed_ip.get('instance_uuid'):
                    instance = instances_by_uuid.get(fixed_ip['instance_uuid'])
                    if instance:
                        hostname = instance['hostname']
                        host = instance['host']
                    else:
                        print(_('WARNING: fixed ip %s allocated to missing'
                                ' instance') % str(fixed_ip['address']))
                print("%-18s\t%-15s\t%-15s\t%s" % (
                        network['cidr'],
                        fixed_ip['address'],
                        hostname, host))

        if not has_ip:
            print(_('No fixed IP found.'))
예제 #2
0
    def list(self, host=None):
        """Lists all fixed ips (optionally by host)."""
        ctxt = context.get_admin_context()

        try:
            if host is None:
                fixed_ips = db.fixed_ip_get_all(ctxt)
            else:
                fixed_ips = db.fixed_ip_get_all_by_instance_host(ctxt, host)
        except exception.NotFound as ex:
            print _("error: %s") % ex
            return(2)

        instances = db.instance_get_all(context.get_admin_context())
        instances_by_uuid = {}
        for instance in instances:
            instances_by_uuid[instance['uuid']] = instance

        print "%-18s\t%-15s\t%-15s\t%s" % (_('network'),
                                              _('IP address'),
                                              _('hostname'),
                                              _('host'))

        all_networks = {}
        try:
            # use network_get_all to retrieve all existing networks
            # this is to ensure that IPs associated with deleted networks
            # will not throw exceptions.
            for network in db.network_get_all(context.get_admin_context()):
                all_networks[network.id] = network
        except exception.NoNetworksFound:
            # do not have any networks, so even if there are IPs, these
            # IPs should have been deleted ones, so return.
            print _('No fixed IP found.')
            return

        has_ip = False
        for fixed_ip in fixed_ips:
            hostname = None
            host = None
            network = all_networks.get(fixed_ip['network_id'])
            if network:
                has_ip = True
                if fixed_ip.get('instance_uuid'):
                    instance = instances_by_uuid.get(fixed_ip['instance_uuid'])
                    if instance:
                        hostname = instance['hostname']
                        host = instance['host']
                    else:
                        print _('WARNING: fixed ip %s allocated to missing'
                                ' instance') % str(fixed_ip['address'])
                print "%-18s\t%-15s\t%-15s\t%s" % (
                        network['cidr'],
                        fixed_ip['address'],
                        hostname, host)

        if not has_ip:
            print _('No fixed IP found.')
예제 #3
0
 def test_instance_get_project_vpn(self):
     result = db.fixed_ip_get_all(self.context)
     values = {'instance_type_id': FLAGS.default_instance_type,
               'image_ref': FLAGS.vpn_image_id,
               'project_id': self.project.id
              }
     instance = db.instance_create(self.context, values)
     result = db.instance_get_project_vpn(self.context, self.project.id)
     self.assertEqual(instance.id, result.id)
예제 #4
0
 def test_instance_get_project_vpn_joins(self):
     result = db.fixed_ip_get_all(self.context)
     values = {'instance_type_id': FLAGS.default_instance_type,
               'image_ref': FLAGS.vpn_image_id,
               'project_id': self.project.id
              }
     instance = db.instance_create(self.context, values)
     _setup_networking(instance.id)
     result = db.instance_get_project_vpn(self.context, self.project.id)
     self.assertEqual(instance.id, result.id)
     self.assertEqual(result['fixed_ips'][0]['floating_ips'][0].address,
                      '1.2.1.2')
예제 #5
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
예제 #6
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
예제 #7
0
 def get_all(cls, context):
     db_fixedips = db.fixed_ip_get_all(context)
     return obj_base.obj_make_list(context, cls(context),
                                   objects.FixedIP, db_fixedips)