desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Is it time to sync the DB against our memory cache?'
def _time_to_sync(self):
diff = (timeutils.utcnow() - self.last_cell_db_check) return (diff.seconds >= CONF.cells.db_check_interval)
'Update our capacity in the self.my_cell_state CellState. This will add/update 2 entries in our CellState.capacities, \'ram_free\' and \'disk_free\'. The values of these are both dictionaries with the following format: {\'total_mb\': <total_memory_free_in_the_cell>, \'units_by_mb: <units_dictionary>} <units_dictionary>...
def _update_our_capacity(self, context):
reserve_level = (CONF.cells.reserve_percent / 100.0) compute_hosts = {} def _get_compute_hosts(): compute_nodes = self.db.compute_node_get_all(context) for compute in compute_nodes: service = compute['service'] if ((not service) or service['disabled']): ...
'Update status for all cells if it\'s time. Most calls to this are from the check_for_update() decorator that checks the time, but it checks outside of a lock. The duplicate check here is to prevent multiple threads from pulling the information simultaneously.'
@lockutils.synchronized('cell-db-sync', 'nova-') def _cell_db_sync(self):
if self._time_to_sync(): LOG.debug(_('Updating cell cache from db.')) self.last_cell_db_check = timeutils.utcnow() ctxt = context.get_admin_context() self._refresh_cells_from_db(ctxt) self._update_our_capacity(ctxt)
'Return cell information for all neighbor cells.'
@sync_from_db def get_cell_info_for_neighbors(self):
cell_list = [cell.get_cell_info() for cell in self.child_cells.itervalues()] cell_list.extend([cell.get_cell_info() for cell in self.parent_cells.itervalues()]) return cell_list
'Return information for my (this) cell.'
@sync_from_db def get_my_state(self):
return self.my_cell_state
'Return list of child cell_infos.'
@sync_from_db def get_child_cells(self):
return self.child_cells.values()
'Return list of parent cell_infos.'
@sync_from_db def get_parent_cells(self):
return self.parent_cells.values()
'Update capabilities for a cell.'
@sync_from_db def update_cell_capabilities(self, cell_name, capabilities):
cell = self.child_cells.get(cell_name) if (not cell): cell = self.parent_cells.get(cell_name) if (not cell): LOG.error(_("Unknown cell '%(cell_name)s' when trying to update capabilities"), locals()) return for (capab_name, values) in capabilities.items(): ...
'Update capacities for a cell.'
@sync_from_db def update_cell_capacities(self, cell_name, capacities):
cell = self.child_cells.get(cell_name) if (not cell): cell = self.parent_cells.get(cell_name) if (not cell): LOG.error(_("Unknown cell '%(cell_name)s' when trying to update capacities"), locals()) return cell.update_capacities(capacities)
'Make a cast to a compute API method in a certain cell.'
def cast_compute_api_method(self, ctxt, cell_name, method, *args, **kwargs):
method_info = {'method': method, 'method_args': args, 'method_kwargs': kwargs} self.cast(ctxt, self.make_msg('run_compute_api_method', cell_name=cell_name, method_info=method_info, call=False))
'Make a call to a compute API method in a certain cell.'
def call_compute_api_method(self, ctxt, cell_name, method, *args, **kwargs):
method_info = {'method': method, 'method_args': args, 'method_kwargs': kwargs} return self.call(ctxt, self.make_msg('run_compute_api_method', cell_name=cell_name, method_info=method_info, call=True))
'Schedule a new instance for creation.'
def schedule_run_instance(self, ctxt, **kwargs):
self.cast(ctxt, self.make_msg('schedule_run_instance', host_sched_kwargs=kwargs))
'Update instance at API level.'
def instance_update_at_top(self, ctxt, instance):
if (not CONF.cells.enable): return instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('instance_update_at_top', instance=instance_p))
'Destroy instance at API level.'
def instance_destroy_at_top(self, ctxt, instance):
if (not CONF.cells.enable): return instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('instance_destroy_at_top', instance=instance_p))
'Delete instance everywhere. delete_type may be \'soft\' or \'hard\'. This is generally only used to resolve races when API cell doesn\'t know to what cell an instance belongs.'
def instance_delete_everywhere(self, ctxt, instance, delete_type):
if (not CONF.cells.enable): return instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('instance_delete_everywhere', instance=instance_p, delete_type=delete_type))
'Create an instance fault at the top.'
def instance_fault_create_at_top(self, ctxt, instance_fault):
if (not CONF.cells.enable): return instance_fault_p = jsonutils.to_primitive(instance_fault) self.cast(ctxt, self.make_msg('instance_fault_create_at_top', instance_fault=instance_fault_p))
'Broadcast upwards that bw_usage was updated.'
def bw_usage_update_at_top(self, ctxt, uuid, mac, start_period, bw_in, bw_out, last_ctr_in, last_ctr_out, last_refreshed=None):
if (not CONF.cells.enable): return bw_update_info = {'uuid': uuid, 'mac': mac, 'start_period': start_period, 'bw_in': bw_in, 'bw_out': bw_out, 'last_ctr_in': last_ctr_in, 'last_ctr_out': last_ctr_out, 'last_refreshed': last_refreshed} self.cast(ctxt, self.make_msg('bw_usage_update_at_top', bw_update...
'Broadcast up that an instance\'s info_cache has changed.'
def instance_info_cache_update_at_top(self, ctxt, instance_info_cache):
if (not CONF.cells.enable): return iicache = jsonutils.to_primitive(instance_info_cache) instance = {'uuid': iicache['instance_uuid'], 'info_cache': iicache} self.cast(ctxt, self.make_msg('instance_update_at_top', instance=instance))
'Get information about our neighbor cells from the manager.'
def get_cell_info_for_neighbors(self, ctxt):
if (not CONF.cells.enable): return [] return self.call(ctxt, self.make_msg('get_cell_info_for_neighbors'), version='1.1')
'Ask all cells to sync instance data.'
def sync_instances(self, ctxt, project_id=None, updated_since=None, deleted=False):
if (not CONF.cells.enable): return return self.cast(ctxt, self.make_msg('sync_instances', project_id=project_id, updated_since=updated_since, deleted=deleted), version='1.1')
'Ask all cells for their list of services.'
def service_get_all(self, ctxt, filters=None):
return self.call(ctxt, self.make_msg('service_get_all', filters=filters), version='1.2')
'Get the service entry for a host in a particular cell. The cell name should be encoded within the host_name.'
def service_get_by_compute_host(self, ctxt, host_name):
return self.call(ctxt, self.make_msg('service_get_by_compute_host', host_name=host_name), version='1.2')
'Proxy RPC to a compute manager. The host in the topic should be encoded with the target cell name.'
def proxy_rpc_to_manager(self, ctxt, rpc_message, topic, call=False, timeout=None):
return self.call(ctxt, self.make_msg('proxy_rpc_to_manager', topic=topic, rpc_message=rpc_message, call=call, timeout=timeout), timeout=timeout, version='1.2')
'Get the task logs from the DB in child cells.'
def task_log_get_all(self, ctxt, task_name, period_beginning, period_ending, host=None, state=None):
return self.call(ctxt, self.make_msg('task_log_get_all', task_name=task_name, period_beginning=period_beginning, period_ending=period_ending, host=host, state=state), version='1.3')
'Get a compute node by ID in a specific cell.'
def compute_node_get(self, ctxt, compute_id):
return self.call(ctxt, self.make_msg('compute_node_get', compute_id=compute_id), version='1.4')
'Return list of compute nodes in all cells, optionally filtering by hypervisor host.'
def compute_node_get_all(self, ctxt, hypervisor_match=None):
return self.call(ctxt, self.make_msg('compute_node_get_all', hypervisor_match=hypervisor_match), version='1.4')
'Return compute node stats from all cells.'
def compute_node_stats(self, ctxt):
return self.call(ctxt, self.make_msg('compute_node_stats'), version='1.4')
'Delete consoleauth tokens for an instance in API cells.'
def consoleauth_delete_tokens(self, ctxt, instance_uuid):
self.cast(ctxt, self.make_msg('consoleauth_delete_tokens', instance_uuid=instance_uuid), version='1.6')
'Validate console port with child cell compute node.'
def validate_console_port(self, ctxt, instance_uuid, console_port, console_type):
return self.call(ctxt, self.make_msg('validate_console_port', instance_uuid=instance_uuid, console_port=console_port, console_type=console_type), version='1.6')
'Holds a reference to the "parent" network manager, used to take advantage of various FlatManager methods to avoid code duplication.'
def __init__(self, net_manager):
self.net_manager = net_manager
'Returns information about the IPv4 and IPv6 subnets associated with a Quantum Network UUID.'
def get_subnets_by_net_id(self, context, tenant_id, net_id, _vif_id=None):
n = db.network_get_by_uuid(context.elevated(), net_id) subnet_v4 = {'network_id': n['uuid'], 'cidr': n['cidr'], 'gateway': n['gateway'], 'broadcast': n['broadcast'], 'netmask': n['netmask'], 'version': 4, 'dns1': n['dns1'], 'dns2': n['dns2']} subnet_v6 = {'network_id': n['uuid'], 'cidr': n['cidr_v6'], 'gate...
'Returns the list of routes for the IP block.'
def get_routes_by_ip_block(self, context, block_id, project_id):
return []
'Returns a list of IPv4 address strings associated with the specified virtual interface, based on the fixed_ips table.'
def get_v4_ips_by_interface(self, context, net_id, vif_id, project_id):
vif_rec = db.virtual_interface_get_by_uuid(context, vif_id) fixed_ips = db.fixed_ips_by_virtual_interface(context, vif_rec['id']) return [fixed_ip['address'] for fixed_ip in fixed_ips]
'Returns a list containing a single IPv6 address strings associated with the specified virtual interface.'
def get_v6_ips_by_interface(self, context, net_id, vif_id, project_id):
admin_context = context.elevated() network = db.network_get_by_uuid(admin_context, net_id) vif_rec = db.virtual_interface_get_by_uuid(context, vif_id) if network['cidr_v6']: ip = ipv6.to_global(network['cidr_v6'], vif_rec['address'], project_id) return [ip] return []
'Adds (allocates) a floating ip to a project from a pool.'
@wrap_check_policy def allocate_floating_ip(self, context, pool=None):
return self.network_rpcapi.allocate_floating_ip(context, context.project_id, pool, False)
'Removes (deallocates) a floating ip with address from a project.'
@wrap_check_policy def release_floating_ip(self, context, address, affect_auto_assigned=False):
args = (context, address, affect_auto_assigned) return self.network_rpcapi.deallocate_floating_ip(*args)
'Associates a floating ip with a fixed ip. ensures floating ip is allocated to the project in context'
@wrap_check_policy @refresh_cache def associate_floating_ip(self, context, instance, floating_address, fixed_address, affect_auto_assigned=False):
args = (context, floating_address, fixed_address, affect_auto_assigned) orig_instance_uuid = self.network_rpcapi.associate_floating_ip(*args) if orig_instance_uuid: msg_dict = dict(address=floating_address, instance_id=orig_instance_uuid) LOG.info((_('re-assign floating IP %(address...
'Disassociates a floating ip from fixed ip it is associated with.'
@wrap_check_policy @refresh_cache def disassociate_floating_ip(self, context, instance, address, affect_auto_assigned=False):
self.network_rpcapi.disassociate_floating_ip(context, address, affect_auto_assigned)
'Allocates all network structures for an instance. TODO(someone): document the rest of these parameters. :param macs: None or a set of MAC addresses that the instance should use. macs is supplied by the hypervisor driver (contrast with requested_networks which is user supplied). NB: macs is ignored by nova-network. :re...
@wrap_check_policy @refresh_cache def allocate_for_instance(self, context, instance, vpn, requested_networks, macs=None, conductor_api=None, security_groups=None, **kwargs):
instance_type = instance_types.extract_instance_type(instance) args = {} args['vpn'] = vpn args['requested_networks'] = requested_networks args['instance_id'] = instance['uuid'] args['project_id'] = instance['project_id'] args['host'] = instance['host'] args['rxtx_factor'] = instance_typ...
'Deallocates all network structures related to instance.'
@wrap_check_policy def deallocate_for_instance(self, context, instance, **kwargs):
args = {} args['instance_id'] = instance['id'] args['project_id'] = instance['project_id'] args['host'] = instance['host'] self.network_rpcapi.deallocate_for_instance(context, **args)
'Adds a fixed ip to instance from specified network.'
@wrap_check_policy @refresh_cache def add_fixed_ip_to_instance(self, context, instance, network_id, conductor_api=None, **kwargs):
args = {'instance_id': instance['uuid'], 'host': instance['host'], 'network_id': network_id, 'rxtx_factor': None} self.network_rpcapi.add_fixed_ip_to_instance(context, **args)
'Removes a fixed ip from instance from specified network.'
@wrap_check_policy @refresh_cache def remove_fixed_ip_from_instance(self, context, instance, address, conductor=None, **kwargs):
args = {'instance_id': instance['uuid'], 'host': instance['host'], 'address': address, 'rxtx_factor': None} self.network_rpcapi.remove_fixed_ip_from_instance(context, **args)
'Force adds another network to a project.'
@wrap_check_policy def add_network_to_project(self, context, project_id, network_uuid=None):
self.network_rpcapi.add_network_to_project(context, project_id, network_uuid)
'Associate or disassociate host or project to network.'
@wrap_check_policy def associate(self, context, network_uuid, host=_sentinel, project=_sentinel):
associations = {} if (host is not API._sentinel): associations['host'] = host if (project is not API._sentinel): associations['project'] = project self.network_rpcapi.associate(context, network_uuid, associations)
'Returns all network info related to an instance.'
@wrap_check_policy def get_instance_nw_info(self, context, instance, conductor_api=None, **kwargs):
result = self._get_instance_nw_info(context, instance) update_instance_cache_with_nw_info(self, context, instance, result, conductor_api) return result
'Returns all network info related to an instance.'
def _get_instance_nw_info(self, context, instance):
instance_type = instance_types.extract_instance_type(instance) args = {'instance_id': instance['uuid'], 'rxtx_factor': instance_type['rxtx_factor'], 'host': instance['host'], 'project_id': instance['project_id']} nw_info = self.network_rpcapi.get_instance_nw_info(context, **args) return network_model.Ne...
'validate the networks passed at the time of creating the server'
@wrap_check_policy def validate_networks(self, context, requested_networks):
return self.network_rpcapi.validate_networks(context, requested_networks)
'Returns a list of dicts in the form of {\'instance_uuid\': uuid, \'ip\': ip} that matched the ip_filter'
@wrap_check_policy def get_instance_uuids_by_ip_filter(self, context, filters):
return self.network_rpcapi.get_instance_uuids_by_ip_filter(context, filters)
'Returns a list of available dns domains. These can be used to create DNS entries for floating ips.'
@wrap_check_policy def get_dns_domains(self, context):
return self.network_rpcapi.get_dns_domains(context)
'Create specified DNS entry for address.'
@wrap_check_policy def add_dns_entry(self, context, address, name, dns_type, domain):
args = {'address': address, 'name': name, 'dns_type': dns_type, 'domain': domain} return self.network_rpcapi.add_dns_entry(context, **args)
'Create specified DNS entry for address.'
@wrap_check_policy def modify_dns_entry(self, context, name, address, domain):
args = {'address': address, 'name': name, 'domain': domain} return self.network_rpcapi.modify_dns_entry(context, **args)
'Delete the specified dns entry.'
@wrap_check_policy def delete_dns_entry(self, context, name, domain):
args = {'name': name, 'domain': domain} return self.network_rpcapi.delete_dns_entry(context, **args)
'Delete the specified dns domain.'
@wrap_check_policy def delete_dns_domain(self, context, domain):
return self.network_rpcapi.delete_dns_domain(context, domain=domain)
'Get entries for address and domain.'
@wrap_check_policy def get_dns_entries_by_address(self, context, address, domain):
args = {'address': address, 'domain': domain} return self.network_rpcapi.get_dns_entries_by_address(context, **args)
'Get entries for name and domain.'
@wrap_check_policy def get_dns_entries_by_name(self, context, name, domain):
args = {'name': name, 'domain': domain} return self.network_rpcapi.get_dns_entries_by_name(context, **args)
'Create a private DNS domain with nova availability zone.'
@wrap_check_policy def create_private_dns_domain(self, context, domain, availability_zone):
args = {'domain': domain, 'av_zone': availability_zone} return self.network_rpcapi.create_private_dns_domain(context, **args)
'Create a public DNS domain with optional nova project.'
@wrap_check_policy def create_public_dns_domain(self, context, domain, project=None):
args = {'domain': domain, 'project': project} return self.network_rpcapi.create_public_dns_domain(context, **args)
'Setup or teardown the network structures on hosts related to instance'
@wrap_check_policy def setup_networks_on_host(self, context, instance, host=None, teardown=False):
host = (host or instance['host']) args = {'instance_id': instance['id'], 'host': host, 'teardown': teardown} self.network_rpcapi.setup_networks_on_host(context, **args)
'Start to migrate the network of an instance.'
@wrap_check_policy def migrate_instance_start(self, context, instance, migration):
instance_type = instance_types.extract_instance_type(instance) args = dict(instance_uuid=instance['uuid'], rxtx_factor=instance_type['rxtx_factor'], project_id=instance['project_id'], source_compute=migration['source_compute'], dest_compute=migration['dest_compute'], floating_addresses=None) if self._is_mul...
'Finish migrating the network of an instance.'
@wrap_check_policy def migrate_instance_finish(self, context, instance, migration):
instance_type = instance_types.extract_instance_type(instance) args = dict(instance_uuid=instance['uuid'], rxtx_factor=instance_type['rxtx_factor'], project_id=instance['project_id'], source_compute=migration['source_compute'], dest_compute=migration['dest_compute'], floating_addresses=None) if self._is_mul...
'Adds a named chain to the table. The chain name is wrapped to be unique for the component creating it, so different components of Nova can safely create identically named chains without interfering with one another. At the moment, its wrapped name is <binary name>-<chain name>, so if nova-compute creates a chain named...
def add_chain(self, name, wrap=True):
if wrap: self.chains.add(name) else: self.unwrapped_chains.add(name)
'Remove named chain. This removal "cascades". All rule in the chain are removed, as are all rules in other chains that jump to it. If the chain is not found, this is merely logged.'
def remove_chain(self, name, wrap=True):
if wrap: chain_set = self.chains else: chain_set = self.unwrapped_chains if (name not in chain_set): LOG.warn(_('Attempted to remove chain %s which does not exist'), name) return if (not wrap): self.remove_chains.add(name) chain_set.rem...
'Add a rule to the table. This is just like what you\'d feed to iptables, just without the \'-A <chain name>\' bit at the start. However, if you need to jump to one of your wrapped chains, prepend its name with a \'$\' which will ensure the wrapping is applied correctly.'
def add_rule(self, chain, rule, wrap=True, top=False):
if (wrap and (chain not in self.chains)): raise ValueError((_('Unknown chain: %r') % chain)) if ('$' in rule): rule = ' '.join(map(self._wrap_target_chain, rule.split(' '))) self.rules.append(IptablesRule(chain, rule, wrap, top))
'Remove a rule from a chain. Note: The rule must be exactly identical to the one that was added. You cannot switch arguments around like you can with the iptables CLI tool.'
def remove_rule(self, chain, rule, wrap=True, top=False):
try: self.rules.remove(IptablesRule(chain, rule, wrap, top)) if (not wrap): self.remove_rules.append(IptablesRule(chain, rule, wrap, top)) except ValueError: LOG.warn(_('Tried to remove rule that was not there: %(chain)r %(rule)r %(wrap)r %(to...
'Remove all rules matching regex.'
def remove_rules_regex(self, regex):
if isinstance(regex, basestring): regex = re.compile(regex) num_rules = len(self.rules) self.rules = filter((lambda r: (not regex.match(str(r)))), self.rules) return (num_rules - len(self.rules))
'Remove all rules from a chain.'
def empty_chain(self, chain, wrap=True):
chained_rules = [rule for rule in self.rules if ((rule.chain == chain) and (rule.wrap == wrap))] for rule in chained_rules: self.rules.remove(rule)
'Apply the current in-memory set of iptables rules. This will blow away any rules left over from previous runs of the same component of Nova, and replace them with our current set of rules. This happens atomically, thanks to iptables-restore.'
@lockutils.synchronized('iptables', 'nova-', external=True) def _apply(self):
s = [('iptables', self.ipv4)] if CONF.use_ipv6: s += [('ip6tables', self.ipv6)] for (cmd, tables) in s: (all_tables, _err) = self.execute(('%s-save' % (cmd,)), '-c', run_as_root=True, attempts=5) all_lines = all_tables.split('\n') for (table_name, table) in tables.iteritems()...
'Create Linux device, return device name.'
def plug(self, network, mac_address):
raise NotImplementedError()
'Destroy Linux device, return device name.'
def unplug(self, network):
raise NotImplementedError()
'Get device name.'
def get_dev(self, network):
raise NotImplementedError()
'Create a vlan and bridge unless they already exist.'
@classmethod def ensure_vlan_bridge(_self, vlan_num, bridge, bridge_interface, net_attrs=None, mac_address=None):
interface = LinuxBridgeInterfaceDriver.ensure_vlan(vlan_num, bridge_interface, mac_address) LinuxBridgeInterfaceDriver.ensure_bridge(bridge, interface, net_attrs) return interface
'Delete a bridge and vlan.'
@classmethod def remove_vlan_bridge(cls, vlan_num, bridge):
LinuxBridgeInterfaceDriver.remove_bridge(bridge) LinuxBridgeInterfaceDriver.remove_vlan(vlan_num)
'Create a vlan unless it already exists.'
@classmethod @lockutils.synchronized('lock_vlan', 'nova-', external=True) def ensure_vlan(_self, vlan_num, bridge_interface, mac_address=None):
interface = ('vlan%s' % vlan_num) if (not device_exists(interface)): LOG.debug(_('Starting VLAN interface %s'), interface) _execute('ip', 'link', 'add', 'link', bridge_interface, 'name', interface, 'type', 'vlan', 'id', vlan_num, run_as_root=True, check_exit_code=[0, 2, 254]) if...
'Delete a vlan.'
@classmethod @lockutils.synchronized('lock_vlan', 'nova-', external=True) def remove_vlan(cls, vlan_num):
vlan_interface = ('vlan%s' % vlan_num) if (not device_exists(vlan_interface)): return else: try: utils.execute('ip', 'link', 'delete', vlan_interface, run_as_root=True, check_exit_code=[0, 2, 254]) except exception.ProcessExecutionError: with excutils.save_and...
'Create a bridge unless it already exists. :param interface: the interface to create the bridge on. :param net_attrs: dictionary with attributes used to create bridge. :param gateway: whether or not the bridge is a gateway. :param filtering: whether or not to create filters on the bridge. If net_attrs is set, it will ...
@classmethod @lockutils.synchronized('lock_bridge', 'nova-', external=True) def ensure_bridge(_self, bridge, interface, net_attrs=None, gateway=True, filtering=True):
if (not device_exists(bridge)): LOG.debug(_('Starting Bridge %s'), bridge) _execute('brctl', 'addbr', bridge, run_as_root=True) _execute('brctl', 'setfd', bridge, 0, run_as_root=True) _execute('brctl', 'stp', bridge, 'off', run_as_root=True) _execute('ip', 'link', 'set'...
'Delete a bridge.'
@classmethod @lockutils.synchronized('lock_bridge', 'nova-', external=True) def remove_bridge(cls, bridge, gateway=True, filtering=True):
if (not device_exists(bridge)): return else: if filtering: ipv4_filter = iptables_manager.ipv4['filter'] if gateway: for rule in get_gateway_rules(bridge): ipv4_filter.remove_rule(*rule) else: ipv4_filter.rem...
'Configures floating ips owned by host.'
def init_host_floating_ips(self):
admin_context = context.get_admin_context() try: floating_ips = self.db.floating_ip_get_all_by_host(admin_context, self.host) except exception.NotFound: return for floating_ip in floating_ips: fixed_ip_id = floating_ip.get('fixed_ip_id') if fixed_ip_id: try: ...
'Handles allocating the floating IP resources for an instance. calls super class allocate_for_instance() as well rpc.called by network_api'
def allocate_for_instance(self, context, **kwargs):
instance_uuid = kwargs.get('instance_id') if (not uuidutils.is_uuid_like(instance_uuid)): instance_uuid = kwargs.get('instance_uuid') project_id = kwargs.get('project_id') requested_networks = kwargs.get('requested_networks') nw_info = super(FloatingIP, self).allocate_for_instance(context, *...
'Handles deallocating floating IP resources for an instance. calls super class deallocate_for_instance() as well. rpc.called by network_api'
def deallocate_for_instance(self, context, **kwargs):
instance_uuid = kwargs.get('instance_id') if (not uuidutils.is_uuid_like(instance_uuid)): instance = self.db.instance_get(context.elevated(read_deleted='yes'), instance_uuid) instance_uuid = instance['uuid'] try: fixed_ips = self.db.fixed_ip_get_by_instance(context, instance_uuid) ...
'Raises if floating ip does not belong to project.'
def _floating_ip_owned_by_project(self, context, floating_ip):
if context.is_admin: return if (floating_ip['project_id'] != context.project_id): if (floating_ip['project_id'] is None): LOG.warn(_('Address |%(address)s| is not allocated'), {'address': floating_ip['address']}) raise exception.NotAuthorized() else: ...
'Gets a floating ip from the pool.'
def allocate_floating_ip(self, context, project_id, auto_assigned=False, pool=None):
pool = (pool or CONF.default_floating_pool) use_quota = (not auto_assigned) try: if use_quota: reservations = QUOTAS.reserve(context, floating_ips=1) except exception.OverQuota: pid = context.project_id LOG.warn((_('Quota exceeded for %(pid)s, tried to ...
'Returns a floating ip to the pool.'
@rpc_common.client_exceptions(exception.FloatingIpNotFoundForAddress) def deallocate_floating_ip(self, context, address, affect_auto_assigned=False):
floating_ip = self.db.floating_ip_get_by_address(context, address) if ((not affect_auto_assigned) and floating_ip.get('auto_assigned')): return use_quota = (not floating_ip.get('auto_assigned')) self._floating_ip_owned_by_project(context, floating_ip) if floating_ip['fixed_ip_id']: f...
'Associates a floating ip with a fixed ip. Makes sure everything makes sense then calls _associate_floating_ip, rpc\'ing to correct host if i\'m not it. Access to the floating_address is verified but access to the fixed_address is not verified. This assumes that that the calling side has already verified that the fixed...
@rpc_common.client_exceptions(exception.FloatingIpNotFoundForAddress) def associate_floating_ip(self, context, floating_address, fixed_address, affect_auto_assigned=False):
floating_ip = self.db.floating_ip_get_by_address(context, floating_address) if ((not affect_auto_assigned) and floating_ip.get('auto_assigned')): return self._floating_ip_owned_by_project(context, floating_ip) orig_instance_uuid = None if floating_ip['fixed_ip_id']: fixed_ip = self.d...
'Performs db and driver calls to associate floating ip & fixed ip.'
def _associate_floating_ip(self, context, floating_address, fixed_address, interface, instance_uuid):
interface = (CONF.public_interface or interface) @lockutils.synchronized(unicode(floating_address), 'nova-') def do_associate(): fixed = self.db.floating_ip_fixed_ip_associate(context, floating_address, fixed_address, self.host) if (not fixed): return try: sel...
'Disassociates a floating ip from its fixed ip. Makes sure everything makes sense then calls _disassociate_floating_ip, rpc\'ing to correct host if i\'m not it.'
@rpc_common.client_exceptions(exception.FloatingIpNotFoundForAddress) def disassociate_floating_ip(self, context, address, affect_auto_assigned=False):
floating_ip = self.db.floating_ip_get_by_address(context, address) if ((not affect_auto_assigned) and floating_ip.get('auto_assigned')): raise exception.CannotDisassociateAutoAssignedFloatingIP() self._floating_ip_owned_by_project(context, floating_ip) if (not floating_ip.get('fixed_ip_id')): ...
'Performs db and driver calls to disassociate floating ip.'
def _disassociate_floating_ip(self, context, address, interface, instance_uuid):
interface = (CONF.public_interface or interface) @lockutils.synchronized(unicode(address), 'nova-') def do_disassociate(): fixed = self.db.floating_ip_disassociate(context, address) if (not fixed): return if interface: self.l3driver.remove_floating_ip(address,...
'Returns a floating IP as a dict.'
@rpc_common.client_exceptions(exception.FloatingIpNotFound) def get_floating_ip(self, context, id):
return dict(self.db.floating_ip_get(context, id).iteritems())
'Returns list of floating pools.'
def get_floating_pools(self, context):
return self.get_floating_ip_pools(context)
'Returns list of floating ip pools.'
def get_floating_ip_pools(self, context):
pools = self.db.floating_ip_get_pools(context) return [dict(pool.iteritems()) for pool in pools]
'Returns a floating IP as a dict.'
def get_floating_ip_by_address(self, context, address):
return dict(self.db.floating_ip_get_by_address(context, address).iteritems())
'Returns the floating IPs allocated to a project.'
def get_floating_ips_by_project(self, context):
ips = self.db.floating_ip_get_all_by_project(context, context.project_id) return [dict(ip.iteritems()) for ip in ips]
'Returns the floating IPs associated with a fixed_address.'
def get_floating_ips_by_fixed_address(self, context, fixed_address):
floating_ips = self.db.floating_ip_get_by_fixed_address(context, fixed_address) return [floating_ip['address'] for floating_ip in floating_ips]
'Calls allocate_fixed_ip once for each network.'
def _allocate_fixed_ips(self, context, instance_id, host, networks, **kwargs):
green_pool = greenpool.GreenPool() vpn = kwargs.get('vpn') requested_networks = kwargs.get('requested_networks') for network in networks: address = None if (requested_networks is not None): for address in (fixed_ip for (uuid, fixed_ip) in requested_networks if (network['uuid'...
'Sits in between _allocate_fixed_ips and allocate_fixed_ip to perform network lookup on the far side of rpc.'
def _rpc_allocate_fixed_ip(self, context, instance_id, network_id, **kwargs):
network = self._get_network_by_id(context, network_id) return self.allocate_fixed_ip(context, instance_id, network, **kwargs)
'Call the superclass deallocate_fixed_ip if i\'m the correct host otherwise call to the correct host'
def deallocate_fixed_ip(self, context, address, host=None, teardown=True):
fixed_ip = self.db.fixed_ip_get_by_address(context, address) network = self._get_network_by_id(context, fixed_ip['network_id']) if (not network['multi_host']): host = network['host'] if (host == self.host): return super(RPCAllocateFixedIP, self).deallocate_fixed_ip(context, address) ...
'Get the proper dhcp address to listen on.'
@lockutils.synchronized('get_dhcp', 'nova-') def _get_dhcp_ip(self, context, network_ref, host=None):
if ((not network_ref.get('multi_host')) or CONF.share_dhcp_address): return network_ref['gateway'] if (not host): host = self.host network_id = network_ref['id'] try: fip = self.db.fixed_ip_get_by_network_host(context, network_id, host) return fip['address'] except ex...
'Broker the request to the driver to fetch the dhcp leases.'
def get_dhcp_leases(self, ctxt, network_ref):
return self.driver.get_dhcp_leases(ctxt, network_ref)
'Do any initialization that needs to be run if this is a standalone service.'
def init_host(self):
ctxt = context.get_admin_context() for network in self.db.network_get_all_by_host(ctxt, self.host): self._setup_network_on_host(ctxt, network) if CONF.update_dns_entries: dev = self.driver.get_dev(network) self.driver.update_dns(ctxt, dev, network)
'Safely sets the host of the network.'
def set_network_host(self, context, network_ref):
LOG.debug(_('setting network host'), context=context) host = self.db.network_set_host(context, network_ref['id'], self.host) return host
'Determine & return which networks an instance should connect to.'
def _get_networks_for_instance(self, context, instance_id, project_id, requested_networks=None):
if ((requested_networks is not None) and (len(requested_networks) != 0)): network_uuids = [uuid for (uuid, fixed_ip) in requested_networks] networks = self._get_networks_by_uuids(context, network_uuids) else: try: networks = self.db.network_get_all(context) except exc...