Пример #1
0
    def __init__(self, image_service=None, **kwargs):
        super(API, self).__init__(**kwargs)
        self.compute_api = compute.API()
        self.image_service = image_service if image_service is not None else image.ImageService(
        )
        self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
        self.CAPABILITIES = CAPABILITIES
        self.sg_api = sg_driver.get_openstack_security_group_driver()

        # Fixup an power-states related to blessed instances.
        elevated = context.get_admin_context()
        instances = self.compute_api.get_all(elevated, {'deleted': False})
        for instance in instances:
            if instance['power_state'] == None:
                # (dscannell) We need to update the power_state to something
                # valid. Since it is a blessed instance we simply update its
                # state to 'no state'.
                self.db.instance_update(elevated, instance['uuid'],
                                        {'power_state': power_state.NOSTATE})
            # (rui-lin) Host or nova-gc process failure during bless can cause
            # source instance to be undeletable and stuck in 'blessing' state,
            # so we clear state to default and allow it to be deleted if needed
            if instance['vm_state'] == vm_states.ACTIVE:
                if instance['task_state'] == "blessing":
                    self.db.instance_update(elevated, instance['uuid'], {
                        'disable_terminate': False,
                        'task_state': 'None'
                    })
Пример #2
0
    def _test_scheduler_api(self, method, rpc_method, **kwargs):
        ctxt = context.RequestContext('fake_user', 'fake_project')

        rpcapi = scheduler_rpcapi.SchedulerAPI()
        self.assertIsNotNone(rpcapi.client)
        self.assertEqual(rpcapi.client.target.topic, CONF.scheduler_topic)

        expected_retval = 'foo' if rpc_method == 'call' else None
        expected_version = kwargs.pop('version', None)
        expected_fanout = kwargs.pop('fanout', None)
        expected_kwargs = kwargs.copy()

        self.mox.StubOutWithMock(rpcapi, 'client')

        rpcapi.client.can_send_version(
            mox.IsA(str)).MultipleTimes().AndReturn(True)

        prepare_kwargs = {}
        if expected_fanout:
            prepare_kwargs['fanout'] = True
        if expected_version:
            prepare_kwargs['version'] = expected_version
        rpcapi.client.prepare(**prepare_kwargs).AndReturn(rpcapi.client)

        rpc_method = getattr(rpcapi.client, rpc_method)

        rpc_method(ctxt, method, **expected_kwargs).AndReturn('foo')

        self.mox.ReplayAll()

        # NOTE(markmc): MultipleTimes() is OnceOrMore() not ZeroOrMore()
        rpcapi.client.can_send_version('I fool you mox')

        retval = getattr(rpcapi, method)(ctxt, **kwargs)
        self.assertEqual(retval, expected_retval)
Пример #3
0
    def _test_scheduler_api(self, method, rpc_method, **kwargs):
        ctxt = context.RequestContext('fake_user', 'fake_project')
        rpcapi = scheduler_rpcapi.SchedulerAPI()
        expected_retval = 'foo' if method == 'call' else None
        expected_version = kwargs.pop('version', rpcapi.BASE_RPC_API_VERSION)
        expected_msg = rpcapi.make_msg(method, **kwargs)
        expected_msg['version'] = expected_version

        self.fake_args = None
        self.fake_kwargs = None

        def _fake_rpc_method(*args, **kwargs):
            self.fake_args = args
            self.fake_kwargs = kwargs
            if expected_retval:
                return expected_retval

        self.stubs.Set(rpc, rpc_method, _fake_rpc_method)

        retval = getattr(rpcapi, method)(ctxt, **kwargs)

        self.assertEqual(retval, expected_retval)
        expected_args = [ctxt, CONF.scheduler_topic, expected_msg]
        for arg, expected_arg in zip(self.fake_args, expected_args):
            self.assertEqual(arg, expected_arg)
Пример #4
0
def _list_hosts(req, service=None):
    """Returns a summary list of hosts, optionally filtering
    by service type.
    """
    context = req.environ['nova.context']
    rpcapi = scheduler_rpcapi.SchedulerAPI()
    hosts = rpcapi.get_host_list(context)
    if service:
        hosts = [host for host in hosts if host["service"] == service]
    return hosts
Пример #5
0
    def describe_resource(self, host):
        """Describes cpu/memory/hdd info for host.

        :param host: hostname.

        """
        rpcapi = scheduler_rpcapi.SchedulerAPI()
        result = rpcapi.show_host_resources(context.get_admin_context(),
                                            host=host)

        if not isinstance(result, dict):
            print _('An unexpected error has occurred.')
            print _('[Result]'), result
        else:
            # Printing a total and used_now
            # (NOTE)The host name width 16 characters
            print '%(a)-25s%(b)16s%(c)8s%(d)8s%(e)8s' % {"a": _('HOST'),
                                                         "b": _('PROJECT'),
                                                         "c": _('cpu'),
                                                         "d": _('mem(mb)'),
                                                         "e": _('hdd')}
            print ('%(a)-16s(total)%(b)26s%(c)8s%(d)8s' %
                   {"a": host,
                    "b": result['resource']['vcpus'],
                    "c": result['resource']['memory_mb'],
                    "d": result['resource']['local_gb']})

            print ('%(a)-16s(used_now)%(b)23s%(c)8s%(d)8s' %
                   {"a": host,
                    "b": result['resource']['vcpus_used'],
                    "c": result['resource']['memory_mb_used'],
                    "d": result['resource']['local_gb_used']})

            # Printing a used_max
            cpu_sum = 0
            mem_sum = 0
            hdd_sum = 0
            for p_id, val in result['usage'].items():
                cpu_sum += val['vcpus']
                mem_sum += val['memory_mb']
                hdd_sum += val['root_gb']
                hdd_sum += val['ephemeral_gb']
            print '%(a)-16s(used_max)%(b)23s%(c)8s%(d)8s' % {"a": host,
                                                             "b": cpu_sum,
                                                             "c": mem_sum,
                                                             "d": hdd_sum}

            for p_id, val in result['usage'].items():
                print '%(a)-25s%(b)16s%(c)8s%(d)8s%(e)8s' % {
                        "a": host,
                        "b": p_id,
                        "c": val['vcpus'],
                        "d": val['memory_mb'],
                        "e": val['root_gb'] + val['ephemeral_gb']}
Пример #6
0
 def __init__(self,
              image_api=None,
              network_api=None,
              volume_api=None,
              security_group_api=None,
              **kwargs):
     super(HuaweiAPI, self).__init__(image_api, network_api, volume_api,
                                     security_group_api, **kwargs)
     self.conductor_api = conductor.API()
     self.compute_rpcapi = hw_rpcapi.HuaweiComputeAPI()
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
Пример #7
0
    def _test_scheduler_api(self,
                            method,
                            rpc_method,
                            expected_args=None,
                            **kwargs):
        ctxt = context.RequestContext('fake_user', 'fake_project')

        rpcapi = scheduler_rpcapi.SchedulerAPI()
        self.assertIsNotNone(rpcapi.client)
        self.assertEqual(rpcapi.client.target.topic,
                         scheduler_rpcapi.RPC_TOPIC)

        expected_retval = 'foo' if rpc_method == 'call' else None
        expected_version = kwargs.pop('version', None)
        expected_fanout = kwargs.pop('fanout', None)
        expected_kwargs = kwargs.copy()

        if expected_args:
            expected_kwargs = expected_args

        prepare_kwargs = {}
        if method == 'select_destinations':
            prepare_kwargs.update({
                'call_monitor_timeout': CONF.rpc_response_timeout,
                'timeout': CONF.long_rpc_timeout
            })
        if expected_fanout:
            prepare_kwargs['fanout'] = True
        if expected_version:
            prepare_kwargs['version'] = expected_version

        # NOTE(sbauza): We need to persist the method before mocking it
        orig_prepare = rpcapi.client.prepare

        def fake_can_send_version(version=None):
            return orig_prepare(version=version).can_send_version()

        @mock.patch.object(rpcapi.client,
                           rpc_method,
                           return_value=expected_retval)
        @mock.patch.object(rpcapi.client,
                           'prepare',
                           return_value=rpcapi.client)
        @mock.patch.object(rpcapi.client,
                           'can_send_version',
                           side_effect=fake_can_send_version)
        def do_test(mock_csv, mock_prepare, mock_rpc_method):
            retval = getattr(rpcapi, method)(ctxt, **kwargs)
            self.assertEqual(retval, expected_retval)
            mock_prepare.assert_called_once_with(**prepare_kwargs)
            mock_rpc_method.assert_called_once_with(ctxt, method,
                                                    **expected_kwargs)

        do_test()
Пример #8
0
 def __init__(self, msg_runner):
     super(CellsScheduler, self).__init__()
     self.msg_runner = msg_runner
     self.state_manager = msg_runner.state_manager
     self.compute_api = compute.API()
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
     self.filter_handler = filters.CellFilterHandler()
     self.filter_classes = self.filter_handler.get_matching_classes(
         CONF.cells.scheduler_filter_classes)
     self.weight_handler = weights.CellWeightHandler()
     self.weigher_classes = self.weight_handler.get_matching_classes(
         CONF.cells.scheduler_weight_classes)
Пример #9
0
 def __init__(self, context, instance, destination, block_migration,
              disk_over_commit):
     self.context = context
     self.instance = instance
     self.destination = destination
     self.block_migration = block_migration
     self.disk_over_commit = disk_over_commit
     self.source = instance.host
     self.migrate_data = None
     self.compute_rpcapi = compute_rpcapi.ComputeAPI()
     self.servicegroup_api = servicegroup.API()
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
     self.image_service = glance.get_default_image_service()
Пример #10
0
 def __init__(self):
     self.data_path = tempfile.mkdtemp(prefix='nova-coverage_')
     self.compute_api = compute_api.API()
     self.network_api = network_api.API()
     self.conductor_api = conductor_api.API()
     self.consoleauth_api = consoleauth_api.ConsoleAuthAPI()
     self.console_api = console_api.API()
     self.scheduler_api = scheduler_api.SchedulerAPI()
     self.cert_api = cert_api.CertAPI()
     self.services = []
     self.combine = False
     self._cover_inst = None
     self.host = CONF.host
     super(CoverageController, self).__init__()
Пример #11
0
 def __init__(self):
     self.data_path = tempfile.mkdtemp(prefix='nova-coverage_')
     data_out = os.path.join(self.data_path, '.nova-coverage')
     self.coverInst = coverage.coverage(data_file=data_out)
     self.compute_api = compute_api.API()
     self.network_api = network_api.API()
     self.conductor_api = conductor_api.API()
     self.consoleauth_api = consoleauth_api.ConsoleAuthAPI()
     self.console_api = console_api.API()
     self.scheduler_api = scheduler_api.SchedulerAPI()
     self.cert_api = cert_api.CertAPI()
     self.services = []
     self.combine = False
     super(CoverageController, self).__init__()
Пример #12
0
 def test_select_destinations_old_with_new_params(self):
     self.flags(scheduler='4.4', group='upgrade_levels')
     fake_spec = objects.RequestSpec()
     ctxt = context.RequestContext('fake_user', 'fake_project')
     rpcapi = scheduler_rpcapi.SchedulerAPI()
     self.assertRaises(exc.SelectionObjectsWithOldRPCVersionNotSupported,
                       rpcapi.select_destinations,
                       ctxt,
                       fake_spec, ['fake_uuids'],
                       return_objects=True,
                       return_alternates=True)
     self.assertRaises(exc.SelectionObjectsWithOldRPCVersionNotSupported,
                       rpcapi.select_destinations,
                       ctxt,
                       fake_spec, ['fake_uuids'],
                       return_objects=False,
                       return_alternates=True)
     self.assertRaises(exc.SelectionObjectsWithOldRPCVersionNotSupported,
                       rpcapi.select_destinations,
                       ctxt,
                       fake_spec, ['fake_uuids'],
                       return_objects=True,
                       return_alternates=False)
Пример #13
0
 def __init__(self, host=None, db_driver=None, service_name='undefined'):
     self.last_capabilities = None
     self.service_name = service_name
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
     super(SchedulerDependentManager,
           self).__init__(host, db_driver, service_name)
Пример #14
0
 def __init__(self):
     super(ComputeTaskManager, self).__init__()
     self.compute_rpcapi = compute_rpcapi.ComputeAPI()
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
     self.image_api = image.API()
import pdb
import chardet

from oslo_log import log as logging

import nova.conf
from nova import config
from nova import objects
from nova import context
from nova.scheduler import rpcapi as scheduler_rpcapi
from nova.scheduler import utils as scheduler_utils
from nova import utils as nova_utils

CONF = nova.conf.CONF
argv = []
default_config_files = ['/etc/nova/nova.conf']
config.parse_args(argv, default_config_files=default_config_files)
objects.register_all()
context = context.get_admin_context()
inst = objects.Instance.get_by_uuid(context,
                                    'a62179e2-d00d-4a68-bd85-b0ff54e3c178')
filter_properties = {'ignore_hosts': [], 'rs_aggregate_id': 3}
system_metadata = nova_utils.instance_sys_meta(inst)
image = nova_utils.get_image_from_system_metadata(system_metadata)
request_spec = scheduler_utils.build_request_spec(context, image, [inst])
spec_obj = objects.RequestSpec.from_primitives(context, request_spec,
                                               filter_properties)
scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
destinations = scheduler_rpcapi.select_destinations(context, spec_obj)
print destinations
Пример #16
0
 def __init__(self, msg_runner):
     super(CellsScheduler, self).__init__()
     self.msg_runner = msg_runner
     self.state_manager = msg_runner.state_manager
     self.compute_api = compute.API()
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
Пример #17
0
 def __init__(self):
     super(ComputeTaskManager, self).__init__()
     self.compute_rpcapi = compute_rpcapi.ComputeAPI()
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
     self.image_service = glance.get_default_image_service()
     self.quotas = quota.QUOTAS
Пример #18
0
 def __init__(self):
     super(ComputeTaskManager, self).__init__()
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
Пример #19
0
Файл: api.py Проект: linets/nova
 def __init__(self, **kwargs):
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
     super(API, self).__init__(**kwargs)
Пример #20
0
 def __init__(self):
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
Пример #21
0
 def __init__(self, *args, **kwargs):
     super(AdminActionsController, self).__init__(*args, **kwargs)
     self.compute_api = compute.API()
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
Пример #22
0
 def __init__(self, image_service=None, **kwargs):
     self.image_service = (image_service or
                           glance.get_default_image_service())
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
     super(API, self).__init__(**kwargs)
Пример #23
0
 def __init__(self, ext_mgr):
     self.host_api = compute.HostAPI()
     self.servicegroup_api = servicegroup.API()
     self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()
     super(HypervisorsController, self).__init__()
     self.ext_mgr = ext_mgr