コード例 #1
0
ファイル: service.py プロジェクト: 2Exception/patron
 def __init__(self, host, binary, topic, manager, report_interval=None,
              periodic_enable=None, periodic_fuzzy_delay=None,
              periodic_interval_max=None, db_allowed=True,
              *args, **kwargs):
     super(Service, self).__init__()
     self.host = host
     self.binary = binary
     self.topic = topic
     self.manager_class_name = manager
     # NOTE(russellb) We want to make sure to create the servicegroup API
     # instance early, before creating other things such as the manager,
     # that will also create a servicegroup API instance.  Internally, the
     # servicegroup only allocates a single instance of the driver API and
     # we want to make sure that our value of db_allowed is there when it
     # gets created.  For that to happen, this has to be the first instance
     # of the servicegroup API.
     self.servicegroup_api = servicegroup.API(db_allowed=db_allowed)
     manager_class = importutils.import_class(self.manager_class_name)
     self.manager = manager_class(host=self.host, *args, **kwargs)
     self.rpcserver = None
     self.report_interval = report_interval
     self.periodic_enable = periodic_enable
     self.periodic_fuzzy_delay = periodic_fuzzy_delay
     self.periodic_interval_max = periodic_interval_max
     self.saved_args, self.saved_kwargs = args, kwargs
     self.backdoor_port = None
     self.conductor_api = conductor.API(use_local=db_allowed)
     self.conductor_api.wait_until_ready(context.get_admin_context())
コード例 #2
0
    def test_compute_manager(self):
        was = {'called': False}

        def fake_get_all_by_filters(context, *args, **kwargs):
            was['called'] = True
            instances = []
            for x in xrange(2):
                instances.append(
                    fake_instance.fake_db_instance(image_ref='1',
                                                   uuid=x,
                                                   name=x,
                                                   vm_state='',
                                                   task_state=''))
            return instances

        with utils.tempdir() as tmpdir:
            self.flags(instances_path=tmpdir)

            self.stubs.Set(db, 'instance_get_all_by_filters',
                           fake_get_all_by_filters)
            compute = importutils.import_object(CONF.compute_manager)
            self.flags(use_local=True, group='conductor')
            compute.conductor_api = conductor.API()
            compute._run_image_cache_manager_pass(None)
            self.assertTrue(was['called'])
コード例 #3
0
ファイル: db.py プロジェクト: 2Exception/patron
    def __init__(self, *args, **kwargs):
        """Creates an instance of the DB-based servicegroup driver.

        Valid kwargs are:

        db_allowed - Boolean. False if direct db access is not allowed and
                     alternative data access (conductor) should be used
                     instead.
        """
        self.db_allowed = kwargs.get('db_allowed', True)
        self.conductor_api = conductor.API(use_local=self.db_allowed)
        self.service_down_time = CONF.service_down_time
コード例 #4
0
ファイル: resource_tracker.py プロジェクト: 2Exception/patron
 def __init__(self, host, driver, nodename):
     self.host = host
     self.driver = driver
     self.pci_tracker = None
     self.pci_filter = pci_whitelist.get_pci_devices_filter()
     self.nodename = nodename
     self.compute_node = None
     self.stats = importutils.import_object(CONF.compute_stats_class)
     self.tracked_instances = {}
     self.tracked_migrations = {}
     self.conductor_api = conductor.API()
     monitor_handler = monitors.ResourceMonitorHandler()
     self.monitors = monitor_handler.choose_monitors(self)
     self.ext_resources_handler = \
         ext_resources.ResourceHandler(CONF.compute_resources)
     self.old_resources = {}
     self.scheduler_client = scheduler_client.SchedulerClient()
コード例 #5
0
ファイル: base.py プロジェクト: 2Exception/patron
 def conductor(self):
     if not hasattr(self, '_conductor'):
         from patron import conductor
         self._conductor = conductor.API()
     return self._conductor
コード例 #6
0
ファイル: handler.py プロジェクト: 2Exception/patron
 def __init__(self):
     self._cache = memorycache.get_client()
     self.conductor_api = conductor.API()
コード例 #7
0
ファイル: mc.py プロジェクト: 2Exception/patron
 def __init__(self, *args, **kwargs):
     if not CONF.memcached_servers:
         raise RuntimeError(_('memcached_servers not defined'))
     self.mc = memorycache.get_client()
     self.db_allowed = kwargs.get('db_allowed', True)
     self.conductor_api = conductor.API(use_local=self.db_allowed)
コード例 #8
0
    def __init__(self, instance, address=None, content=None, extra_md=None,
                 conductor_api=None, network_info=None, vd_driver=None):
        """Creation of this object should basically cover all time consuming
        collection.  Methods after that should not cause time delays due to
        network operations or lengthy cpu operations.

        The user should then get a single instance and make multiple method
        calls on it.
        """
        if not content:
            content = []

        ctxt = context.get_admin_context()

        # The default value of mimeType is set to MIME_TYPE_TEXT_PLAIN
        self.set_mimetype(MIME_TYPE_TEXT_PLAIN)
        self.instance = instance
        self.extra_md = extra_md

        if conductor_api:
            capi = conductor_api
        else:
            capi = conductor.API()

        self.availability_zone = az.get_instance_availability_zone(ctxt,
                                                                   instance)

        self.security_groups = objects.SecurityGroupList.get_by_instance(
            ctxt, instance)

        self.mappings = _format_instance_mapping(ctxt, instance)

        if instance.user_data is not None:
            self.userdata_raw = base64.b64decode(instance.user_data)
        else:
            self.userdata_raw = None

        self.ec2_ids = capi.get_ec2_ids(ctxt,
                                        obj_base.obj_to_primitive(instance))

        self.address = address

        # expose instance metadata.
        self.launch_metadata = utils.instance_meta(instance)

        self.password = password.extract_password(instance)

        self.uuid = instance.uuid

        self.content = {}
        self.files = []

        # get network info, and the rendered network template
        if network_info is None:
            network_info = instance.info_cache.network_info

        self.ip_info = \
                ec2utils.get_ip_info_for_instance_from_nw_info(network_info)

        self.network_config = None
        cfg = netutils.get_injected_network_template(network_info)

        if cfg:
            key = "%04i" % len(self.content)
            self.content[key] = cfg
            self.network_config = {"name": "network_config",
                'content_path': "/%s/%s" % (CONTENT_DIR, key)}

        # 'content' is passed in from the configdrive code in
        # patron/virt/libvirt/driver.py.  That's how we get the injected files
        # (personalities) in. AFAIK they're not stored in the db at all,
        # so are not available later (web service metadata time).
        for (path, contents) in content:
            key = "%04i" % len(self.content)
            self.files.append({'path': path,
                'content_path': "/%s/%s" % (CONTENT_DIR, key)})
            self.content[key] = contents

        if vd_driver is None:
            vdclass = importutils.import_class(CONF.vendordata_driver)
        else:
            vdclass = vd_driver

        self.vddriver = vdclass(instance=instance, address=address,
                                extra_md=extra_md, network_info=network_info)

        self.route_configuration = None