How to use the nova.db function in nova

To help you get started, we’ve selected a few nova examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nii-cloud / dodai-compute / nova / api / ec2 / cloud.py View on Github external
if not group_name and not group_id:
            err = "Not enough parameters, need group_name or group_id"
            raise exception.ApiError(_(err))
        notfound = exception.SecurityGroupNotFound
        if group_name:
            security_group = db.security_group_get_by_name(context,
                                                           context.project_id,
                                                           group_name)
            if not security_group:
                raise notfound(security_group_id=group_name)
        elif group_id:
            security_group = db.security_group_get(context, group_id)
            if not security_group:
                raise notfound(security_group_id=group_id)
        LOG.audit(_("Delete security group %s"), group_name, context=context)
        db.security_group_destroy(context, security_group.id)
        return True
github openstack / nova / nova / service_eventlet.py View on Github external
def start(self):
        manager_class = utils.import_class(self.manager_class_name)
        self.manager = manager_class(host=self.host, *self.saved_args,
                                                     **self.saved_kwargs)
        self.manager.init_host()
        self.model_disconnected = False
        ctxt = context.get_admin_context()
        try:
            service_ref = db.service_get_by_args(ctxt,
                                                 self.host,
                                                 self.binary)
            self.service_id = service_ref['id']
        except exception.NotFound:
            self._create_service_ref(ctxt)

        conn1 = rpc.Connection.instance(new=True)
        conn2 = rpc.Connection.instance(new=True)
        if self.report_interval:
            consumer_all = rpc.AdapterConsumer(
                    connection=conn1,
                    topic=self.topic,
                    proxy=self)
            consumer_node = rpc.AdapterConsumer(
                    connection=conn2,
                    topic='%s.%s' % (self.topic, self.host),
github openstack / nova / nova / db / sqlalchemy / api.py View on Github external
filter_by(project_id=project_filter).\
                           with_lockmode('update').\
                           first()

        if not force:
            # find out if project has a network
            network_ref = network_query(project_id)

        if force or not network_ref:
            # in force mode or project doesn't have a network so associate
            # with a new network

            # get new network
            network_ref = network_query(None)
            if not network_ref:
                raise db.NoMoreNetworks()

            # associate with network
            # NOTE(vish): if with_lockmode isn't supported, as in sqlite,
            #             then this has concurrency issues
            network_ref['project_id'] = project_id
            session.add(network_ref)
    return network_ref
github openstack / nova / nova / network / linux_net.py View on Github external
def get_dhcp_hosts(context, network_id):
    """Get a string containing a network's hosts config in dnsmasq format"""
    hosts = []
    for fixed_ip_ref in db.network_get_associated_fixed_ips(context,
                                                            network_id):
        hosts.append(_host_dhcp(fixed_ip_ref))
    return '\n'.join(hosts)
github nii-cloud / dodai-compute / nova / api / ec2 / cloud.py View on Github external
def _describe_availability_zones(self, context, **kwargs):
        ctxt = context.elevated()
        enabled_services = db.service_get_all(ctxt, False)
        disabled_services = db.service_get_all(ctxt, True)
        available_zones = []
        for zone in [service.availability_zone for service
                     in enabled_services]:
            if not zone in available_zones:
                available_zones.append(zone)
        not_available_zones = []
        for zone in [service.availability_zone for service in disabled_services
                     if not service['availability_zone'] in available_zones]:
            if not zone in not_available_zones:
                not_available_zones.append(zone)
        result = []
        for zone in available_zones:
            result.append({'zoneName': zone,
                           'zoneState': "available"})
        for zone in not_available_zones:
            result.append({'zoneName': zone,
github openstack / nova / nova / api / openstack / flavors.py View on Github external
def _get_flavors(self, req, is_detail=True):
        """Helper function that returns a list of flavor dicts."""
        ctxt = req.environ['nova.context']
        try:
            flavors = db.api.instance_type_get_all(ctxt)
        except exception.NoInstanceTypesFound:
            flavors = {}
        builder = self._get_view_builder(req)
        items = [builder.build(flavor, is_detail=is_detail)
                 for flavor in flavors.values()]
        return items
github openstack / nova / nova / api / ec2 / admin.py View on Github external
def _vpn_for(self, context, project_id):
        """Get the VPN instance for a project ID."""
        for instance in db.instance_get_all_by_project(context, project_id):
            if (instance['image_id'] == str(FLAGS.vpn_image_id)
                and not instance['vm_state'] in [vm_states.DELETED]):
                return instance
github openstack / nova / nova / objects / fixed_ip.py View on Github external
def get_by_id(cls, context, id, expected_attrs=None):
        if expected_attrs is None:
            expected_attrs = []
        get_network = 'network' in expected_attrs
        db_fixedip = db.fixed_ip_get(context, id, get_network=get_network)
        return cls._from_db_object(context, cls(context), db_fixedip,
                                   expected_attrs)
github openstack / nova / nova / objects / compute_node.py View on Github external
def get_all(cls, context):
        db_computes = db.compute_node_get_all(context)
        return base.obj_make_list(context, cls(context), objects.ComputeNode,
                                  db_computes)
github gc3-uzh-ch / openstack-tools / bin / openstack_check_spurious_vms.py View on Github external
def main(args):
    ctxt = context.get_admin_context()
    instances = db.instance_get_all(ctxt)

    # Get a list of all running instances
    instances_by_hosts = defaultdict(list)
    for instance in instances:
        host = instance.host[:instance.host.find('.')]
        instances_by_hosts[instance.host].append(instance.id)

    # Get a list of all the compute nodes
    compute_nodes = []
    for s in db.service_get_all(ctxt):
        if not s.disabled:
            compute_nodes.extend(s.compute_node)

    # Get a list of all the vms running on each compute node
    vms_on_host = {}
    queue = mp.Queue()
    jobs = []
    for node in compute_nodes:
        hostname = node.hypervisor_hostname
        job = RunVirsh(hostname, args.sshopts, queue)
        jobs.append(job)
        job.start()

    # Wait until all of them are done.
    print("Waiting until all the jobs are done")
    for job in jobs: