Example #1
0
 def get_all(cls, context, disabled=None, set_zones=False):
     db_services = db.service_get_all(context, disabled=disabled)
     if set_zones:
         db_services = availability_zones.set_availability_zones(
             context, db_services)
     return base.obj_make_list(context, cls(context), objects.Service,
                               db_services)
Example #2
0
 def get_all(cls, context, inactive=False, filters=None,
             sort_key='flavorid', sort_dir='asc', limit=None, marker=None):
     db_flavors = db.flavor_get_all(context, inactive=inactive,
                                    filters=filters, sort_key=sort_key,
                                    sort_dir=sort_dir, limit=limit,
                                    marker=marker)
     return base.obj_make_list(context, cls(context), objects.Flavor,
                               db_flavors, expected_attrs=['extra_specs'])
Example #3
0
 def _get_by_service(cls, context, service_id, use_slave=False):
     try:
         db_computes = db.compute_nodes_get_by_service_id(
             context, service_id)
     except exception.ServiceNotFound:
         # NOTE(sbauza): Previous behaviour was returning an empty list
         # if the service was created with no computes, we need to keep it.
         db_computes = []
     return base.obj_make_list(context, cls(context), objects.ComputeNode,
                               db_computes)
Example #4
0
    def service_get_all(self, context, filters=None, set_zones=False):
        if filters is None:
            filters = {}
        if 'availability_zone' in filters:
            zone_filter = filters.pop('availability_zone')
            set_zones = True
        else:
            zone_filter = None
        services = self.cells_rpcapi.service_get_all(context,
                                                     filters=filters)
        if set_zones:
            # TODO(sbauza): set_availability_zones returns flat dicts,
            # we should rather modify the RPC API to amend service_get_all by
            # adding a set_zones argument
            services = availability_zones.set_availability_zones(context,
                                                                 services)
            if zone_filter is not None:
                services = [s for s in services
                            if s['availability_zone'] == zone_filter]

            # NOTE(sbauza): As services is a list of flat dicts, we need to
            # rehydrate the corresponding ServiceProxy objects
            cell_paths = []
            for service in services:
                cell_path, id = cells_utils.split_cell_and_item(service['id'])
                cell_path, host = cells_utils.split_cell_and_item(
                    service['host'])
                service['id'] = id
                service['host'] = host
                cell_paths.append(cell_path)
            services = obj_base.obj_make_list(context,
                                              objects.ServiceList(),
                                              objects.Service,
                                              services)
            services = [cells_utils.ServiceProxy(s, c)
                        for s, c in zip(services, cell_paths)]

        return services
Example #5
0
 def get_all_by_host(cls, context, host, use_slave=False):
     try:
         db_computes = db.compute_node_get_all_by_host(context, host,
                                                       use_slave)
     except exception.ComputeHostNotFound:
         # FIXME(sbauza): Some old computes can still have no host record
         # We need to provide compatibility by using the old service_id
         # record.
         # We assume the compatibility as an extra penalty of one more DB
         # call but that's necessary until all nodes are upgraded.
         try:
             service = objects.Service.get_by_compute_host(context, host,
                                                           use_slave)
             db_computes = db.compute_nodes_get_by_service_id(
                 context, service.id)
         except exception.ServiceNotFound:
             # We need to provide the same exception upstream
             raise exception.ComputeHostNotFound(host=host)
         # We can avoid an extra call to Service object in _from_db_object
         for db_compute in db_computes:
             db_compute['host'] = service.host
     return base.obj_make_list(context, cls(context), objects.ComputeNode,
                               db_computes)
Example #6
0
 def _from_db_object(context, fixedip, db_fixedip, expected_attrs=None):
     if expected_attrs is None:
         expected_attrs = []
     for field in fixedip.fields:
         if field == 'default_route':
             # NOTE(danms): This field is only set when doing a
             # FixedIPList.get_by_network() because it's a relatively
             # special-case thing, so skip it here
             continue
         if field not in FIXED_IP_OPTIONAL_ATTRS:
             fixedip[field] = db_fixedip[field]
     # NOTE(danms): Instance could be deleted, and thus None
     if 'instance' in expected_attrs:
         fixedip.instance = objects.Instance._from_db_object(
             context,
             objects.Instance(context),
             db_fixedip['instance']) if db_fixedip['instance'] else None
     if 'network' in expected_attrs:
         fixedip.network = objects.Network._from_db_object(
             context,
             objects.Network(context),
             db_fixedip['network']) if db_fixedip['network'] else None
     if 'virtual_interface' in expected_attrs:
         db_vif = db_fixedip['virtual_interface']
         vif = objects.VirtualInterface._from_db_object(
             context,
             objects.VirtualInterface(context),
             db_fixedip['virtual_interface']) if db_vif else None
         fixedip.virtual_interface = vif
     if 'floating_ips' in expected_attrs:
         fixedip.floating_ips = obj_base.obj_make_list(
                 context, objects.FloatingIPList(context),
                 objects.FloatingIP, db_fixedip['floating_ips'])
     fixedip._context = context
     fixedip.obj_reset_changes()
     return fixedip
Example #7
0
 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)
Example #8
0
def block_device_make_list(context, db_list, **extra_args):
    return base.obj_make_list(context,
                              objects.BlockDeviceMappingList(context),
                              objects.BlockDeviceMapping, db_list,
                              **extra_args)
Example #9
0
 def get_by_action(cls, context, action_id):
     db_events = db.action_events_get(context, action_id)
     return base.obj_make_list(context, cls(context),
                               objects.InstanceActionEvent, db_events)
Example #10
0
 def get_all(cls, context):
     groups = db.security_group_get_all(context)
     return base.obj_make_list(context, cls(context), objects.SecurityGroup,
                               groups)
Example #11
0
 def get_by_topic(cls, context, topic):
     db_services = db.service_get_all_by_topic(context, topic)
     return base.obj_make_list(context, cls(context), objects.Service,
                               db_services)
Example #12
0
 def get_by_fixed_ip_id(cls, context, fixed_ip_id):
     db_floatingips = db.floating_ip_get_by_fixed_ip_id(context,
                                                        fixed_ip_id)
     return obj_base.obj_make_list(context, cls(), FloatingIP,
                                   db_floatingips)
Example #13
0
 def get_in_progress_by_host_and_node(cls, context, host, node):
     db_migrations = db.migration_get_in_progress_by_host_and_node(
         context, host, node)
     return base.obj_make_list(context, cls(context), objects.Migration,
                               db_migrations)
Example #14
0
 def get_all(cls, context):
     db_vifs = db.virtual_interface_get_all(context)
     return base.obj_make_list(context, cls(context),
                               objects.VirtualInterface, db_vifs)
Example #15
0
 def get_by_instance_uuid(cls, context, instance_uuid, use_slave=False):
     db_vifs = db.virtual_interface_get_by_instance(context,
                                                    instance_uuid,
                                                    use_slave=use_slave)
     return base.obj_make_list(context, cls(context),
                               objects.VirtualInterface, db_vifs)
Example #16
0
 def create(cls, context, resource_id, tags):
     db_tags = db.instance_tag_set(context, resource_id, tags)
     return base.obj_make_list(context, cls(), objects.Tag, db_tags)
Example #17
0
 def get_by_uuids(cls, context, uuids, start_period=None, use_slave=False):
     db_bw_usages = db.bw_usage_get_by_uuids(context, uuids=uuids,
                                             start_period=start_period,
                                             use_slave=use_slave)
     return base.obj_make_list(context, cls(), BandwidthUsage, db_bw_usages)
Example #18
0
 def get_by_resource_id(cls, context, resource_id):
     db_tags = db.instance_tag_get_by_instance_uuid(context, resource_id)
     return base.obj_make_list(context, cls(), objects.Tag, db_tags)
Example #19
0
 def get_by_user(cls, context, user_id):
     db_keypairs = db.key_pair_get_all_by_user(context, user_id)
     return base.obj_make_list(context, cls(context), objects.KeyPair,
                               db_keypairs)
Example #20
0
def block_device_make_list(context, db_list, **extra_args):
    return base.obj_make_list(context, objects.BlockDeviceMappingList(context),
                              objects.BlockDeviceMapping, db_list,
                              **extra_args)
Example #21
0
 def get_all(cls, context):
     db_domains = db.dnsdomain_get_all(context)
     return base.obj_make_list(context, cls(context), objects.DNSDomain,
                               db_domains)
Example #22
0
 def get_all(cls, context):
     db_aggregates = db.aggregate_get_all(context)
     return base.obj_make_list(context, cls(context), objects.Aggregate,
                               db_aggregates)
Example #23
0
 def get_by_instance_uuid(cls, context, instance_uuid, use_slave=False):
     db_bdms = db.block_device_mapping_get_all_by_instance(
         context, instance_uuid, use_slave=use_slave)
     return base.obj_make_list(context, cls(), objects.BlockDeviceMapping,
                               db_bdms or [])
Example #24
0
 def get_by_host(cls, context, host, key=None):
     db_aggregates = db.aggregate_get_by_host(context, host, key=key)
     return base.obj_make_list(context, cls(context), objects.Aggregate,
                               db_aggregates)
Example #25
0
    def get_by_project_id(cls, context, project_id):
        db_mappings = cls._get_by_project_id_from_db(context, project_id)

        return base.obj_make_list(context, cls(), objects.InstanceMapping,
                                  db_mappings)
Example #26
0
 def get_by_metadata_key(cls, context, key, hosts=None):
     db_aggregates = db.aggregate_get_by_metadata_key(context, key=key)
     if hosts:
         db_aggregates = cls._filter_db_aggregates(db_aggregates, hosts)
     return base.obj_make_list(context, cls(context), objects.Aggregate,
                               db_aggregates)
Example #27
0
 def get_by_instance(cls, context, instance):
     groups = db.security_group_get_by_instance(context, instance.uuid)
     return base.obj_make_list(context, cls(context), objects.SecurityGroup,
                               groups)
Example #28
0
 def get_by_filters(cls, context, filters):
     db_migrations = db.migration_get_all_by_filters(context, filters)
     return base.obj_make_list(context, cls(context), objects.Migration,
                               db_migrations)
Example #29
0
 def get_by_project(cls, context, project_id):
     groups = db.security_group_get_by_project(context, project_id)
     return base.obj_make_list(context, cls(context), objects.SecurityGroup,
                               groups)
Example #30
0
 def get_by_uuids(cls, context, network_uuids, project_only='allow_none'):
     db_networks = db.network_get_all_by_uuids(context, network_uuids,
                                               project_only)
     return obj_base.obj_make_list(context, cls(context), objects.Network,
                                   db_networks)
Example #31
0
 def get_by_instance_uuid(cls, context, instance_uuid, use_slave=False):
     db_bdms = db.block_device_mapping_get_all_by_instance(
             context, instance_uuid, use_slave=use_slave)
     return base.obj_make_list(
             context, cls(), objects.BlockDeviceMapping, db_bdms or [])
Example #32
0
 def get_by_compute_node(cls, context, node_id):
     db_dev_list = db.pci_device_get_all_by_node(context, node_id)
     return base.obj_make_list(context, cls(context), objects.PciDevice,
                               db_dev_list)
Example #33
0
 def get_by_instance_uuid(cls, context, instance_uuid):
     db_actions = db.actions_get(context, instance_uuid)
     return base.obj_make_list(context, cls(), InstanceAction, db_actions)
Example #34
0
 def get_by_security_group_id(cls, context, secgroup_id):
     db_rules = db.security_group_rule_get_by_security_group(
         context, secgroup_id, columns_to_join=['grantee_group'])
     return base.obj_make_list(context, cls(context),
                               objects.SecurityGroupRule, db_rules,
                               expected_attrs=['grantee_group'])
Example #35
0
 def get_by_user(cls, context, user_id):
     db_keypairs = db.key_pair_get_all_by_user(context, user_id)
     return base.obj_make_list(context, cls(context), objects.KeyPair,
                               db_keypairs)
Example #36
0
 def get_by_filters(cls, context, filters):
     db_migrations = db.migration_get_all_by_filters(context, filters)
     return base.obj_make_list(context, cls(context), objects.Migration,
                               db_migrations)
Example #37
0
 def get_by_hypervisor(cls, context, hypervisor_match):
     db_computes = db.compute_node_search_by_hypervisor(context,
                                                        hypervisor_match)
     return base.obj_make_list(context, cls(context), objects.ComputeNode,
                               db_computes)
Example #38
0
 def get_by_project(cls, context, project_id):
     db_floatingips = db.floating_ip_get_all_by_project(context, project_id)
     return obj_base.obj_make_list(context, cls(context),
                                   objects.FloatingIP, db_floatingips)
Example #39
0
 def get_by_host(cls, context, host):
     db_networks = db.network_get_all_by_host(context, host)
     return obj_base.obj_make_list(context, cls(context), objects.Network,
                                   db_networks)
Example #40
0
    'source_node': 'node10',
    'dest_node': 'node20',
    'source_compute': 'compute10',
    'dest_compute': 'compute20',
    'dest_host': '5.6.7.8',
    'status': 'Done',
    'instance_uuid': 'instance_id_456',
    'old_instance_type_id': 5,
    'new_instance_type_id': 6,
    'created_at': datetime.datetime(2013, 10, 22, 13, 42, 2),
    'updated_at': datetime.datetime(2013, 10, 22, 13, 42, 2),
    'deleted_at': None,
    'deleted': False
}]

migrations_obj = base.obj_make_list('fake-context', objects.MigrationList(),
                                    objects.Migration, fake_migrations)


class FakeRequest(object):
    environ = {
        "patron.context":
        context.RequestContext('fake_user', 'fake', is_admin=True)
    }
    GET = {}


class MigrationsTestCaseV21(test.NoDBTestCase):
    migrations = migrations_v21

    def setUp(self):
        """Run before each test."""
Example #41
0
 def get_by_instance_uuid(cls, context, uuid):
     db_dev_list = db.pci_device_get_all_by_instance_uuid(context, uuid)
     return base.obj_make_list(context, cls(context), objects.PciDevice,
                               db_dev_list)
Example #42
0
 def get_by_project(cls, context, project_id, associate=True):
     db_networks = db.project_get_networks(context, project_id,
                                           associate=associate)
     return obj_base.obj_make_list(context, cls(context), objects.Network,
                                   db_networks)
Example #43
0
 def get_in_progress_by_host_and_node(cls, context, host, node):
     db_migrations = db.migration_get_in_progress_by_host_and_node(
         context, host, node)
     return base.obj_make_list(context, cls(context), objects.Migration,
                               db_migrations)
Example #44
0
 def get_by_host(cls, context, host):
     db_fixedips = db.fixed_ip_get_by_host(context, host)
     return obj_base.obj_make_list(context, cls(context),
                                   objects.FixedIP, db_fixedips)
Example #45
0
 def get_unconfirmed_by_dest_compute(cls, context, confirm_window,
                                     dest_compute, use_slave=False):
     db_migrations = db.migration_get_unconfirmed_by_dest_compute(
         context, confirm_window, dest_compute, use_slave=use_slave)
     return base.obj_make_list(context, cls(context), objects.Migration,
                               db_migrations)
Example #46
0
 def get_by_virtual_interface_id(cls, context, vif_id):
     expected_attrs = ['network', 'floating_ips']
     db_fixedips = db.fixed_ips_by_virtual_interface(context, vif_id)
     return obj_base.obj_make_list(context, cls(context),
                                   objects.FixedIP, db_fixedips,
                                   expected_attrs=expected_attrs)
Example #47
0
 def get_by_fixed_address(cls, context, fixed_address):
     db_floatingips = db.floating_ip_get_by_fixed_address(
         context, str(fixed_address))
     return obj_base.obj_make_list(context, cls(context),
                                   objects.FloatingIP, db_floatingips)
Example #48
0
 def get_by_host(cls, context, host):
     db_services = db.service_get_all_by_host(context, host)
     return base.obj_make_list(context, cls(context), objects.Service,
                               db_services)
Example #49
0
 def create(cls, context, ip_info, want_result=False):
     db_floatingips = db.floating_ip_bulk_create(context, ip_info,
                                                 want_result=want_result)
     if want_result:
         return obj_base.obj_make_list(context, cls(), FloatingIP,
                                       db_floatingips)
Example #50
0
 def get_all(cls, context, hypervisor=None):
     db_agents = db.agent_build_get_all(context, hypervisor=hypervisor)
     return base.obj_make_list(context, cls(), objects.Agent, db_agents)