问题导读
1.nova下的service.py的源码主要完成什么任务?
2.driver.py位于哪个目录下?
nova下的service.py的源码,有些地方不好或者是错了,希望大家帮我指出!
- import inspect
- import os
-
- import eventlet
- import greenlet
-
- from nova import context
- from nova import db
- from nova import exception
- from nova import flags
- from nova import log as logging
- from nova import rpc
- from nova import utils
- from nova import version
- from nova import wsgi
-
-
- LOG = logging.getLogger('nova.service')
-
- FLAGS = flags.FLAGS#flags.py中有一句 FLAGS = FlagValues(),那么直接查看FlagValues()这个类,会发现这个类是继承于gflags.FlagValues.
-
- flags.DEFINE_integer('report_interval', 10,
- 'seconds between nodes reporting state to datastore',
- lower_bound=1)#参数名称,默认值和简短说明
- flags.DEFINE_integer('periodic_interval', 60,
- 'seconds between running periodic tasks',
- lower_bound=1)
- flags.DEFINE_string('ec2_listen', "0.0.0.0",
- 'IP address for EC2 API to listen')
- flags.DEFINE_integer('ec2_listen_port', 8773, 'port for ec2 api to listen')
- flags.DEFINE_string('osapi_listen', "0.0.0.0",
- 'IP address for OpenStack API to listen')
- flags.DEFINE_integer('osapi_listen_port', 8774, 'port for os api to listen')
- flags.DEFINE_string('api_paste_config', "api-paste.ini",
- 'File name for the paste.deploy config for nova-api')
-
- #Launcher 类 包含run_server ,launch_server,stop,wait 4个函数,其实功能非常简单,首先初始化Launcher将self_services弄成一个空列表
- #run_server就是开始和等待一个server的完成,launcher_server就是将该server加入到该类初始化的列表中,
- #stop 就是for循环遍历self_services列表中的服务然后一个一个的kill掉
- #wait 函数就是 Waits until all services have been stopped
- class Launcher(object):
- """Launch one or more services and wait for them to complete."""
-
- def __init__(self):
- """Initialize the service launcher.
-
- :returns: None
-
- """
- self._services = []
-
- @staticmethod
- def run_server(server):
- """Start and wait for a server to finish.
-
- :param service: Server to run and wait for.
- :returns: None
-
- """
- server.start()
- server.wait()
-
- def launch_server(self, server):#在360行被调用
- """Load and start the given server.
-
- :param server: The server you would like to start.
- :returns: None
-
- """
- gt = eventlet.spawn(self.run_server, server)
- self._services.append(gt)
-
- def stop(self):
- """Stop all services which are currently running.
-
- :returns: None
-
- """
- for service in self._services:
- service.kill()
-
- def wait(self):
- """Waits until all services have been stopped, and then returns.
-
- :returns: None
-
- """
- for service in self._services:
- try:
- service.wait()
- except greenlet.GreenletExit:
- pass
-
-
- class Service(object):
- """Service object for binaries running on hosts.
-
- A service takes a manager and enables rpc by listening to queues based
- on topic. It also periodically runs tasks on the manager and reports
- it state to the database services table."""
-
- def __init__(self, host, binary, topic, manager, report_interval=None,
- periodic_interval=None, *args, **kwargs):
- self.host = host
- self.binary = binary
- self.topic = topic
- #动态的生成manager类,并动态生成实例
- self.manager_class_name = manager#在create函数中指定
- manager_class = utils.import_class(self.manager_class_name)#动态的import该类
- self.manager = manager_class(host=self.host, *args, **kwargs)#动态的生成实例
- # 设置参数:应该是服务间隔时间之类的。
- self.report_interval = report_interval
- self.periodic_interval = periodic_interval
- #设置多出来的一些参数。
- super(Service, self).__init__(*args, **kwargs)
- self.saved_args, self.saved_kwargs = args, kwargs
- #设置一个列表 不知道是不是后面有需要用的地方 果然在185行 发现了
- self.timers = []
-
- def start(self):
- #设置版本
- vcs_string = version.version_string_with_vcs()
- logging.audit(_('Starting %(topic)s node (version %(vcs_string)s)'),
- {'topic': self.topic, 'vcs_string': vcs_string})
- #初始化host
- 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)#该函数位于187行
-
- if 'nova-compute' == self.binary:
- self.manager.update_available_resource(ctxt)
-
- self.conn = rpc.create_connection(new=True)
- logging.debug("Creating Consumer connection for Service %s" %
- self.topic)
-
- # Share this same connection for these Consumers
- self.conn.create_consumer(self.topic, self, fanout=False)
-
- node_topic = '%s.%s' % (self.topic, self.host)#节点的topic 包括了topic 和 host
- self.conn.create_consumer(node_topic, self, fanout=False)
-
- self.conn.create_consumer(self.topic, self, fanout=True)
-
- # Consume from all consumers in a thread
- self.conn.consume_in_thread()
-
- if self.report_interval:
- pulse = utils.LoopingCall(self.report_state)#在265中可以找到report_state 他的作用是在存储中更新服务的状态
- pulse.start(interval=self.report_interval, now=False)
- self.timers.append(pulse)
-
- if self.periodic_interval:
- periodic = utils.LoopingCall(self.periodic_tasks)#在260行发现 Periodic_tasks任务在一个周期性间隔跑
- periodic.start(interval=self.periodic_interval, now=False)
- self.timers.append(periodic)
-
- def _create_service_ref(self, context):
- zone = FLAGS.node_availability_zone
- service_ref = db.service_create(context,
- {'host': self.host,
- 'binary': self.binary,
- 'topic': self.topic,
- 'report_count': 0,
- 'availability_zone': zone})
- self.service_id = service_ref['id']#猜测应该是获取当前服务的id
-
- def __getattr__(self, key):
- manager = self.__dict__.get('manager', None)
- return getattr(manager, key)
-
- @classmethod
- def create(cls, host=None, binary=None, topic=None, manager=None,
- report_interval=None, periodic_interval=None):
- """Instantiates class and passes back application object.
-
- :param host: defaults to FLAGS.host
- :param binary: defaults to basename of executable
- :param topic: defaults to bin_name - 'nova-' part
- :param manager: defaults to FLAGS.<topic>_manager
- :param report_interval: defaults to FLAGS.report_interval
- :param periodic_interval: defaults to FLAGS.periodic_interval
-
- """
- if not host:
- host = FLAGS.host
- if not binary:
- binary = os.path.basename(inspect.stack()[-1][1])
- if not topic:
- topic = binary.rpartition('nova-')[2]
- if not manager:
- manager = FLAGS.get('%s_manager' % topic, None)
- if not report_interval:
- report_interval = FLAGS.report_interval
- if not periodic_interval:
- periodic_interval = FLAGS.periodic_interval
- service_obj = cls(host, binary, topic, manager,
- report_interval, periodic_interval)#此处 调用的是该类的init的默认函数
-
- return service_obj
-
- def kill(self):
- """Destroy the service object in the datastore."""
- self.stop()
- try:
- db.service_destroy(context.get_admin_context(), self.service_id)
- except exception.NotFound:
- logging.warn(_('Service killed that has no database entry'))
-
- def stop(self):
- # Try to shut the connection down, but if we get any sort of
- # errors, go ahead and ignore them.. as we're shutting down anyway
- try:
- self.conn.close()
- except Exception:
- pass
- for x in self.timers: #遍历曾经添加到self.timers中的每一个“间隔”(不是很清楚) 然后将其stop
- try:
- x.stop()
- except Exception:
- pass
- self.timers = [] #重新将self.timers置空
-
- def wait(self):
- for x in self.timers:
- try:
- x.wait()
- except Exception:
- pass
-
- def periodic_tasks(self):
- """Tasks to be run at a periodic interval."""
- #任务在一个周期性间隔跑
- self.manager.periodic_tasks(context.get_admin_context())
-
- def report_state(self):
- """Update the state of this service in the datastore."""
- #在数据存储更新服务的状态。
- ctxt = context.get_admin_context()
- try:
- try:
- service_ref = db.service_get(ctxt, self.service_id)
- except exception.NotFound:
- logging.debug(_('The service database object disappeared, '
- 'Recreating it.'))
- self._create_service_ref(ctxt)
- service_ref = db.service_get(ctxt, self.service_id)
-
- db.service_update(ctxt,
- self.service_id,
- {'report_count': service_ref['report_count'] + 1})
-
- # TODO(termie): make this pattern be more elegant.
- if getattr(self, 'model_disconnected', False):
- self.model_disconnected = False
- logging.error(_('Recovered model server connection!'))
-
- # TODO(vish): this should probably only catch connection errors
- except Exception: # pylint: disable=W0702
- if not getattr(self, 'model_disconnected', False):
- self.model_disconnected = True
- logging.exception(_('model server went away'))
-
-
- class WSGIService(object):
- """Provides ability to launch API from a 'paste' configuration."""
- #提供能够从一个‘paste’配置启动api的服务
-
- def __init__(self, name, loader=None):
- """Initialize, but do not start the WSGI server.
-
- :param name: The name of the WSGI server given to the loader.
- :param loader: Loads the WSGI application using the given name.
- :returns: None
-
- """
- #初始化 但是并没有开是wsgi的服务。
- self.name = name
- self.loader = loader or wsgi.Loader()
- self.app = self.loader.load_app(name)#将wsgi服务的名字给到self.loader,然后用那名字将其 装载到wsgi application
- self.host = getattr(FLAGS, '%s_listen' % name, "0.0.0.0") #返回主机host getattr Found at: __builtin__
- #getattr(object, name[, default]) -> value得知返回的是value
-
-
- self.port = getattr(FLAGS, '%s_listen_port' % name, 0)#端口 port
- self.server = wsgi.Server(name,
- self.app,
- host=self.host,
- port=self.port)
-
- def start(self):
- """Start serving this service using loaded configuration.
-
- Also, retrieve updated port number in case '0' was passed in, which
- indicates a random port should be used.
-
- :returns: None
-
- """
- self.server.start()
- self.port = self.server.port
-
- def stop(self):
- """Stop serving this API.
-
- :returns: None
-
- """
- self.server.stop()
-
- def wait(self):
- """Wait for the service to stop serving this API.
-
- :returns: None
-
- """
- self.server.wait()
-
-
- # NOTE(vish): the global launcher is to maintain the existing
- # functionality of calling service.serve +
- # service.wait
- _launcher = None
-
-
- def serve(*servers):
- global _launcher
- if not _launcher:
- _launcher = Launcher() #s实例化Launcher
- for server in servers:
- _launcher.launch_server(server)
-
-
- def wait():
- # After we've loaded up all our dynamic bits, check
- # whether we should print help
-
-
- #flags.py中 有一句
- #FLAGS = FlagValues(),那么直接查看FlagValues()这个类,这个类是继承于gflags.FlagValues.
-
-
- flags.DEFINE_flag(flags.HelpFlag())
- flags.DEFINE_flag(flags.HelpshortFlag())
- flags.DEFINE_flag(flags.HelpXMLFlag())
- FLAGS.ParseNewFlags()
- logging.debug(_('Full set of FLAGS:'))
- for flag in FLAGS:
- flag_get = FLAGS.get(flag, None)
- logging.debug('%(flag)s : %(flag_get)s' % locals())
- try:
- _launcher.wait()
- except KeyboardInterrupt:
- _launcher.stop()
复制代码
这个文件位于\nova\virt,是一个底层的driver.py,源代码如下(我 觉得比较重要的computerDriver类列出来 了,并将下面的每个函数分离 加以注释《见下面图片》!我看见后面好多函数都是继承的ComputerDriver比如nova\virt\libvirt下面的connection.py里面的class LibvirtConnection(driver.ComputeDriver):):
- """
- Driver base-classes:
-
- (Beginning of) the contract that compute drivers must follow, and shared
- types that support that contract
- """
-
- from nova.compute import power_state
-
-
- class InstanceInfo(object):
- def __init__(self, name, state):
- self.name = name
- assert state in power_state.valid_states(), "Bad state: %s" % state
- self.state = state
-
-
- def block_device_info_get_root(block_device_info):
- block_device_info = block_device_info or {}
- return block_device_info.get('root_device_name')
-
-
- def block_device_info_get_swap(block_device_info):
- block_device_info = block_device_info or {}
- return block_device_info.get('swap') or {'device_name': None,
- 'swap_size': 0}
-
-
- def swap_is_usable(swap):
- return swap and swap['device_name'] and swap['swap_size'] > 0
-
-
- def block_device_info_get_ephemerals(block_device_info):
- block_device_info = block_device_info or {}
- ephemerals = block_device_info.get('ephemerals') or []
- return ephemerals
-
-
- def block_device_info_get_mapping(block_device_info):
- block_device_info = block_device_info or {}
- block_device_mapping = block_device_info.get('block_device_mapping') or []
- return block_device_mapping
-
-
- class ComputeDriver(object):
- """Base class for compute drivers.
-
- The interface to this class talks in terms of 'instances' (Amazon EC2 and
- internal Nova terminology), by which we mean 'running virtual machine'
- (XenAPI terminology) or domain (Xen or libvirt terminology).
-
- An instance has an ID, which is the identifier chosen by Nova to represent
- the instance further up the stack. This is unfortunately also called a
- 'name' elsewhere. As far as this layer is concerned, 'instance ID' and
- 'instance name' are synonyms.
-
- Note that the instance ID or name is not human-readable or
- customer-controlled -- it's an internal ID chosen by Nova. At the
- nova.virt layer, instances do not have human-readable names at all -- such
- things are only known higher up the stack.
-
- Most virtualization platforms will also have their own identity schemes,
- to uniquely identify a VM or domain. These IDs must stay internal to the
- platform-specific layer, and never escape the connection interface. The
- platform-specific layer is responsible for keeping track of which instance
- ID maps to which platform-specific ID, and vice versa.
-
- In contrast, the list_disks and list_interfaces calls may return
- platform-specific IDs. These identify a specific virtual disk or specific
- virtual network interface, and these IDs are opaque to the rest of Nova.
-
- Some methods here take an instance of nova.compute.service.Instance. This
- is the datastructure used by nova.compute to store details regarding an
- instance, and pass them into this layer. This layer is responsible for
- translating that generic datastructure into terms that are specific to the
- virtualization platform.
-
- """
- #此处为了让大家看的明白 将 ComputerDriver的类图 列出来
-
- def init_host(self, host):
- """Initialize anything that is necessary for the driver to function,
- including catching up with currently running VM's on the given host."""
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def get_info(self, instance_name):
- """Get the current status of an instance, by name (not ID!)
-
- Returns a dict containing:
-
- :state: the running state, one of the power_state codes
- :max_mem: (int) the maximum memory in KBytes allowed
- :mem: (int) the memory in KBytes used by the domain
- :num_cpu: (int) the number of virtual CPUs for the domain
- :cpu_time: (int) the CPU time used in nanoseconds
- """
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def list_instances(self):
- """
- Return the names of all the instances known to the virtualization
- layer, as a list.
- """
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def list_instances_detail(self):
- """Return a list of InstanceInfo for all registered VMs"""
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def spawn(self, context, instance,
- network_info=None, block_device_info=None):
- """
- Create a new instance/VM/domain on the virtualization platform.
-
- Once this successfully completes, the instance should be
- running (power_state.RUNNING).
-
- If this fails, any partial instance should be completely
- cleaned up, and the virtualization platform should be in the state
- that it was before this call began.
-
- :param context: security context
- :param instance: Instance object as returned by DB layer.
- This function should use the data there to guide
- the creation of the new instance.
- :param network_info:
- :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
- :param block_device_info:
- """
- raise NotImplementedError()
-
- def destroy(self, instance, network_info, cleanup=True):
- """Destroy (shutdown and delete) the specified instance.
-
- If the instance is not found (for example if networking failed), this
- function should still succeed. It's probably a good idea to log a
- warning in that case.
-
- :param instance: Instance object as returned by DB layer.
- :param network_info:
- :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
- :param cleanup:
-
- """
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def reboot(self, instance, network_info):
- """Reboot the specified instance.
-
- :param instance: Instance object as returned by DB layer.
- :param network_info:
- :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
- """
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def snapshot_instance(self, context, instance_id, image_id):
- raise NotImplementedError()
-
- def get_console_pool_info(self, console_type):
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def get_console_output(self, instance):
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def get_ajax_console(self, instance):
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def get_diagnostics(self, instance):
- """Return data about VM diagnostics"""
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def get_host_ip_addr(self):
- """
- Retrieves the IP address of the dom0
- """
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def attach_volume(self, context, instance_id, volume_id, mountpoint):
- """Attach the disk at device_path to the instance at mountpoint"""
- raise NotImplementedError()
-
- def detach_volume(self, context, instance_id, volume_id):
- """Detach the disk attached to the instance at mountpoint"""
- raise NotImplementedError()
-
- def compare_cpu(self, cpu_info):
- """Compares given cpu info against host 确保vm能运行
-
- Before attempting to migrate a VM to this host,
- compare_cpu is called to ensure that the VM will
- actually run here.
-
- :param cpu_info: (str) JSON structure describing the source CPU.
- :returns: None if migration is acceptable
- :raises: :py:class:`~nova.exception.InvalidCPUInfo` if migration
- is not acceptable.
- """
- raise NotImplementedError()
-
- def migrate_disk_and_power_off(self, instance, dest):
- """
- Transfers the disk of a running instance in multiple phases, turning
- off the instance before the end.
- """
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def snapshot(self, context, instance, image_id):
- """
- Snapshots the specified instance.
-
- :param context: security context
- :param instance: Instance object as returned by DB layer.
- :param image_id: Reference to a pre-created image that will
- hold the snapshot.
- """
- raise NotImplementedError()
-
- def finish_migration(self, context, instance, disk_info, network_info,
- resize_instance):
- #打开一个迁移的实例,完成一个调整
- """Completes a resize, turning on the migrated instance
-
- :param network_info:
- :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
- """
- raise NotImplementedError()
-
- def revert_migration(self, instance):
- #返回一个调整,推动回到实例?
- """Reverts a resize, powering back on the instance"""
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def pause(self, instance, callback):
- """Pause the specified instance."""
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def unpause(self, instance, callback):
- """Unpause paused VM instance"""
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def suspend(self, instance, callback):
- # 挂起指定的实例
- """suspend the specified instance"""
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def resume(self, instance, callback):
- """resume the specified instance"""
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def rescue(self, context, instance, callback, network_info):
- #恢复指定的实例
- """Rescue the specified instance"""
- raise NotImplementedError()
-
- def unrescue(self, instance, callback, network_info):
- """Unrescue the specified instance"""
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def update_available_resource(self, ctxt, host):
- #在computeNode表中更新电脑资源管理的信息
- """Updates compute manager resource info on ComputeNode table.
-
- This method is called when nova-compute launches, and
- whenever admin executes "nova-manage service update_resource".
-
- :param ctxt: security context
- :param host: hostname that compute manager is currently running
-
- """
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def live_migration(self, ctxt, instance_ref, dest,
- post_method, recover_method):
- #分发处理高负荷,当有高负荷操作时候,大量生成 live_mirgration
- """Spawning live_migration operation for distributing high-load.
-
- :param ctxt: security context
- :param instance_ref:
- nova.db.sqlalchemy.models.Instance object
- instance object that is migrated.
- :param dest: destination host
- :param post_method:
- post operation method.
- expected nova.compute.manager.post_live_migration.
- :param recover_method:
- recovery method when any exception occurs.
- expected nova.compute.manager.recover_live_migration.
-
- """
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def refresh_security_group_rules(self, security_group_id):
- #改变安全组之后调用
- """This method is called after a change to security groups.
-
- All security groups and their associated rules live in the datastore,
- and calling this method should apply the updated rules to instances
- running the specified security group.
-
- An error should be raised if the operation cannot complete.
-
- """
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def refresh_security_group_members(self, security_group_id):
- #当一个安全组被添加到一个实例,这个方法被调用
- """This method is called when a security group is added to an instance.
-
- This message is sent to the virtualization drivers on hosts that are
- running an instance that belongs to a security group that has a rule
- that references the security group identified by `security_group_id`.
- It is the responsiblity of this method to make sure any rules
- that authorize traffic flow with members of the security group are
- updated and any new members can communicate, and any removed members
- cannot.
-
- Scenario:
- * we are running on host 'H0' and we have an instance 'i-0'.
- * instance 'i-0' is a member of security group 'speaks-b'
- * group 'speaks-b' has an ingress rule that authorizes group 'b'
- * another host 'H1' runs an instance 'i-1'
- * instance 'i-1' is a member of security group 'b'
-
- When 'i-1' launches or terminates we will recieve the message
- to update members of group 'b', at which time we will make
- any changes needed to the rules for instance 'i-0' to allow
- or deny traffic coming from 'i-1', depending on if it is being
- added or removed from the group.
-
- In this scenario, 'i-1' could just as easily have been running on our
- host 'H0' and this method would still have been called. The point was
- that this method isn't called on the host where instances of that
- group are running (as is the case with
- :method:`refresh_security_group_rules`) but is called where references
- are made to authorizing those instances.
-
- An error should be raised if the operation cannot complete.
-
- """
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def refresh_provider_fw_rules(self, security_group_id):
- #这触发一个基于数据库改变的防火墙的更新
- """This triggers a firewall update based on database changes.
-
- When this is called, rules have either been added or removed from the
- datastore. You can retrieve rules with
- :method:`nova.db.api.provider_fw_rule_get_all`.
-
- Provider rules take precedence over security group rules. If an IP
- would be allowed by a security group ingress rule, but blocked by
- a provider rule, then packets from the IP are dropped. This includes
- intra-project traffic in the case of the allow_project_net_traffic
- flag for the libvirt-derived classes.
-
- """
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def reset_network(self, instance):
- """reset networking for specified instance"""
- # TODO(Vek): Need to pass context in for access to auth_token
- pass
-
- def ensure_filtering_rules_for_instance(self, instance_ref, network_info):
- #设置过滤规则,并等待它完成
- """Setting up filtering rules and waiting for its completion.
-
- To migrate an instance, filtering rules to hypervisors
- and firewalls are inevitable on destination host.
- ( Waiting only for filtering rules to hypervisor,
- since filtering rules to firewall rules can be set faster).
-
- Concretely, the below method must be called.
- - setup_basic_filtering (for nova-basic, etc.)
- - prepare_instance_filter(for nova-instance-instance-xxx, etc.)
-
- to_xml may have to be called since it defines PROJNET, PROJMASK.
- but libvirt migrates those value through migrateToURI(),
- so , no need to be called.
-
- Don't use thread for this method since migration should
- not be started when setting-up filtering rules operations
- are not completed.
-
- :params instance_ref: nova.db.sqlalchemy.models.Instance object
-
- """
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def unfilter_instance(self, instance, network_info):
- """Stop filtering instance"""
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def set_admin_password(self, context, instance_id, new_pass=None):
- """
- Set the root password on the specified instance.
-
- The first parameter is an instance of nova.compute.service.Instance,
- and so the instance is being specified as instance.name. The second
- parameter is the value of the new password.
- """
- raise NotImplementedError()
-
- def inject_file(self, instance, b64_path, b64_contents):
- """在指定的实例上写文件
- Writes a file on the specified instance.
-
- The first parameter is an instance of nova.compute.service.Instance,
- and so the instance is being specified as instance.name. The second
- parameter is the base64-encoded path to which the file is to be
- written on the instance; the third is the contents of the file, also
- base64-encoded.
- """
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def agent_update(self, instance, url, md5hash):
- #在指定的实例中更新代理
- """
- Update agent on the specified instance.
-
- The first parameter is an instance of nova.compute.service.Instance,
- and so the instance is being specified as instance.name. The second
- parameter is the URL of the agent to be fetched and updated on the
- instance; the third is the md5 hash of the file for verification
- purposes.
- """
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def inject_network_info(self, instance, nw_info):
- #为指定的实例注入网络信息
- """inject network info for specified instance"""
- # TODO(Vek): Need to pass context in for access to auth_token
- pass
-
- def poll_rescued_instances(self, timeout):
- #轮询已经恢复的实例
- """Poll for rescued instances"""
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def host_power_action(self, host, action):
- """Reboots, shuts down or powers up the host."""
- raise NotImplementedError()
-
- def set_host_enabled(self, host, enabled):
- #设置指定的主机有能力接受新的实例
- """Sets the specified host's ability to accept new instances."""
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def plug_vifs(self, instance, network_info):
- """Plugs in VIFs to networks."""
- # TODO(Vek): Need to pass context in for access to auth_token
- raise NotImplementedError()
-
- def update_host_status(self):
- """Refresh host stats"""
- raise NotImplementedError()
-
- def get_host_stats(self, refresh=False):
- """Return currently known host stats"""
- raise NotImplementedError()
-
- def list_disks(self, instance_name):
- """
- Return the IDs of all the virtual disks attached to the specified
- instance, as a list. These IDs are opaque to the caller (they are
- only useful for giving back to this layer as a parameter to
- disk_stats). These IDs only need to be unique for a given instance.
-
- Note that this function takes an instance ID.
- """
- raise NotImplementedError()
-
- def list_interfaces(self, instance_name):
- """
- Return the IDs of all the virtual network interfaces attached to the
- specified instance, as a list. These IDs are opaque to the caller
- (they are only useful for giving back to this layer as a parameter to
- interface_stats). These IDs only need to be unique for a given
- instance.
-
- Note that this function takes an instance ID.
- """
- raise NotImplementedError()
-
- def resize(self, instance, flavor):
- """
- Resizes/Migrates the specified instance.
-
- The flavor parameter determines whether or not the instance RAM and
- disk space are modified, and if so, to what size.
- """
- raise NotImplementedError()
-
- def block_stats(self, instance_name, disk_id):
- """
- Return performance counters associated with the given disk_id on the
- given instance_name. These are returned as [rd_req, rd_bytes, wr_req,
- wr_bytes, errs], where rd indicates read, wr indicates write, req is
- the total number of I/O requests made, bytes is the total number of
- bytes transferred, and errs is the number of requests held up due to a
- full pipeline.
-
- All counters are long integers.
-
- This method is optional. On some platforms (e.g. XenAPI) performance
- statistics can be retrieved directly in aggregate form, without Nova
- having to do the aggregation. On those platforms, this method is
- unused.
-
- Note that this function takes an instance ID.
- """
- raise NotImplementedError()
-
- def interface_stats(self, instance_name, iface_id):
- """
- Return performance counters associated with the given iface_id on the
- given instance_id. These are returned as [rx_bytes, rx_packets,
- rx_errs, rx_drop, tx_bytes, tx_packets, tx_errs, tx_drop], where rx
- indicates receive, tx indicates transmit, bytes and packets indicate
- the total num
-
- ber of bytes or packets transferred, and errs and dropped
- is the total number of packets failed / dropped.
-
- All counters are long integers.
-
- This method is optional. On some platforms (e.g. XenAPI) performance
- statistics can be retrieved directly in aggregate form, without Nova
- having to do the aggregation. On those platforms, this method is
- unused.
-
- Note that this function takes an instance ID.
- """
- raise NotImplementedError()
复制代码
相关内容:
openstack nova 源码分析1-setup脚本
http://www.aboutyun.com/thread-10090-1-1.html
openstack nova 源码分析2之nova-api,nova-compute
http://www.aboutyun.com/thread-10091-1-1.html
openstack nova 源码分析4-1 -nova/virt/libvirt目录下的connection.py
http://www.aboutyun.com/thread-10094-1-1.html
openstack nova 源码分析4-2 -nova/virt/libvirt目录下的connection.py
http://www.aboutyun.com/thread-10095-1-1.html
|