def _get_resource(self, plugin, context, resource, resource_id, clean_session=True): with utils.clean_session(context.session) if clean_session else ( dummy_context_mgr()): obj_getter = getattr(plugin, 'get_' + resource) obj = obj_getter(context, resource_id) return obj
def _update_resource(self, plugin, context, resource, resource_id, attrs, do_notify=True, clean_session=True): # REVISIT(rkukura): Do update.start notification? # REVISIT(rkukura): Check authorization? with utils.clean_session( context.session) if clean_session else (dummy_context_mgr()): obj_getter = getattr(plugin, 'get_' + resource) orig_obj = obj_getter(context, resource_id) action = 'update_' + resource obj_updater = getattr(plugin, action) obj = obj_updater(context, resource_id, {resource: attrs}) if do_notify: self._nova_notifier.send_network_change( action, orig_obj, {resource: obj}) # REVISIT(rkukura): Do update.end notification? if cfg.CONF.dhcp_agent_notification: self._dhcp_agent_notifier.notify(context, {resource: obj}, resource + '.update.end') return obj
def _get_resources(self, plugin, context, resource_plural, filters=None, clean_session=True): with utils.clean_session(context.session) if clean_session else ( dummy_context_mgr()): obj_getter = getattr(plugin, 'get_' + resource_plural) obj = obj_getter(context, filters) return obj
def _create_resource(self, plugin, context, resource, attrs, do_notify=True, clean_session=True): # REVISIT(rkukura): Do create.start notification? # REVISIT(rkukura): Check authorization? with utils.clean_session( context.session) if clean_session else (dummy_context_mgr()): reservation = None if plugin in [ self._group_policy_plugin, self._servicechain_plugin ]: reservation = quota.QUOTAS.make_reservation( context, context.tenant_id, {resource: 1}, plugin) action = 'create_' + resource obj_creator = getattr(plugin, action) try: obj = obj_creator(context, {resource: attrs}) except Exception: # In case of failure the plugin will always raise an # exception. Cancel the reservation with excutils.save_and_reraise_exception(): if reservation: quota.QUOTAS.cancel_reservation( context, reservation.reservation_id) if reservation: quota.QUOTAS.commit_reservation(context, reservation.reservation_id) # At this point the implicit resource creation is successfull, # so we should be calling: # resource_registry.set_resources_dirty(context) # to appropriately notify the quota engine. However, the above # call begins a new transaction and we want to avoid that. # Moreover, it can be safely assumed that any implicit resource # creation via this local_api is always in response to an # explicit resource creation request, and hence the above # method will be invoked in the API layer. if do_notify: if BATCH_NOTIFICATIONS and not clean_session: outer_transaction = (_get_outer_transaction( context._session.transaction)) else: outer_transaction = None args = [action, {}, {resource: obj}] send_or_queue_notification(outer_transaction, self._nova_notifier, 'send_network_change', args) # REVISIT(rkukura): Do create.end notification? if cfg.CONF.dhcp_agent_notification: args = [context, {resource: obj}, resource + '.create.end'] send_or_queue_notification(outer_transaction, self._dhcp_agent_notifier, 'notify', args) return obj
def _get_resource(self, plugin, context, resource, resource_id, clean_session=True): with utils.clean_session( context.session) if clean_session else (dummy_context_mgr()): obj_getter = getattr(plugin, 'get_' + resource) obj = obj_getter(context, resource_id) return obj
def _get_resources(self, plugin, context, resource_plural, filters=None, clean_session=True): with utils.clean_session( context.session) if clean_session else (dummy_context_mgr()): obj_getter = getattr(plugin, 'get_' + resource_plural) obj = obj_getter(context, filters) return obj
def _create_resource(self, plugin, context, resource, attrs): # REVISIT(rkukura): Do create.start notification? # REVISIT(rkukura): Check authorization? # REVISIT(rkukura): Do quota? with utils.clean_session(context.session): action = "create_" + resource obj_creator = getattr(plugin, action) obj = obj_creator(context, {resource: attrs}) self._nova_notifier.send_network_change(action, {}, {resource: obj}) # REVISIT(rkukura): Do create.end notification? if cfg.CONF.dhcp_agent_notification: self._dhcp_agent_notifier.notify(context, {resource: obj}, resource + ".create.end") return obj
def _delete_resource(self, plugin, context, resource, resource_id): # REVISIT(rkukura): Do delete.start notification? # REVISIT(rkukura): Check authorization? with utils.clean_session(context.session): obj_getter = getattr(plugin, "get_" + resource) obj = obj_getter(context, resource_id) action = "delete_" + resource obj_deleter = getattr(plugin, action) obj_deleter(context, resource_id) self._nova_notifier.send_network_change(action, {}, {resource: obj}) # REVISIT(rkukura): Do delete.end notification? if cfg.CONF.dhcp_agent_notification: self._dhcp_agent_notifier.notify(context, {resource: obj}, resource + ".delete.end")
def _create_resource(self, plugin, context, resource, attrs): # REVISIT(rkukura): Do create.start notification? # REVISIT(rkukura): Check authorization? # REVISIT(rkukura): Do quota? with utils.clean_session(context.session): action = 'create_' + resource obj_creator = getattr(plugin, action) obj = obj_creator(context, {resource: attrs}) self._nova_notifier.send_network_change(action, {}, {resource: obj}) # REVISIT(rkukura): Do create.end notification? if cfg.CONF.dhcp_agent_notification: self._dhcp_agent_notifier.notify(context, {resource: obj}, resource + '.create.end') return obj
def _delete_resource(self, plugin, context, resource, resource_id): # REVISIT(rkukura): Do delete.start notification? # REVISIT(rkukura): Check authorization? with utils.clean_session(context.session): obj_getter = getattr(plugin, 'get_' + resource) obj = obj_getter(context, resource_id) action = 'delete_' + resource obj_deleter = getattr(plugin, action) obj_deleter(context, resource_id) self._nova_notifier.send_network_change(action, {}, {resource: obj}) # REVISIT(rkukura): Do delete.end notification? if cfg.CONF.dhcp_agent_notification: self._dhcp_agent_notifier.notify(context, {resource: obj}, resource + '.delete.end')
def _delete_resource(self, plugin, context, resource, resource_id, do_notify=True, clean_session=True): # REVISIT(rkukura): Do delete.start notification? # REVISIT(rkukura): Check authorization? with utils.clean_session(context.session) if clean_session else ( dummy_context_mgr()): obj_getter = getattr(plugin, 'get_' + resource) obj = obj_getter(context, resource_id) action = 'delete_' + resource obj_deleter = getattr(plugin, action) obj_deleter(context, resource_id) if do_notify: self._nova_notifier.send_network_change(action, {}, {resource: obj}) # REVISIT(rkukura): Do delete.end notification? if cfg.CONF.dhcp_agent_notification: self._dhcp_agent_notifier.notify(context, {resource: obj}, resource + '.delete.end')
def _update_resource(self, plugin, context, resource, resource_id, attrs, do_notify=True): # REVISIT(rkukura): Do update.start notification? # REVISIT(rkukura): Check authorization? with utils.clean_session(context.session): obj_getter = getattr(plugin, 'get_' + resource) orig_obj = obj_getter(context, resource_id) action = 'update_' + resource obj_updater = getattr(plugin, action) obj = obj_updater(context, resource_id, {resource: attrs}) if do_notify: self._nova_notifier.send_network_change(action, orig_obj, {resource: obj}) # REVISIT(rkukura): Do update.end notification? if cfg.CONF.dhcp_agent_notification: self._dhcp_agent_notifier.notify(context, {resource: obj}, resource + '.update.end') return obj
def _create_resource(self, plugin, context, resource, attrs, do_notify=True, clean_session=True): # REVISIT(rkukura): Do create.start notification? # REVISIT(rkukura): Check authorization? with utils.clean_session(context.session) if clean_session else ( dummy_context_mgr()): reservation = None if plugin in [self._group_policy_plugin, self._servicechain_plugin]: reservation = quota.QUOTAS.make_reservation( context, context.tenant_id, {resource: 1}, plugin) action = 'create_' + resource obj_creator = getattr(plugin, action) try: obj = obj_creator(context, {resource: attrs}) except Exception: # In case of failure the plugin will always raise an # exception. Cancel the reservation with excutils.save_and_reraise_exception(): if reservation: quota.QUOTAS.cancel_reservation( context, reservation.reservation_id) if reservation: quota.QUOTAS.commit_reservation( context, reservation.reservation_id) # At this point the implicit resource creation is successfull, # so we should be calling: # resource_registry.set_resources_dirty(context) # to appropriately notify the quota engine. However, the above # call begins a new transaction and we want to avoid that. # Moreover, it can be safely assumed that any implicit resource # creation via this local_api is always in response to an # explicit resource creation request, and hence the above # method will be invoked in the API layer. if do_notify: self._nova_notifier.send_network_change(action, {}, {resource: obj}) # REVISIT(rkukura): Do create.end notification? if cfg.CONF.dhcp_agent_notification: self._dhcp_agent_notifier.notify( context, {resource: obj}, resource + '.create.end') return obj
def _get_resources(self, plugin, context, resource_plural, filters=None): with utils.clean_session(context.session): obj_getter = getattr(plugin, 'get_' + resource_plural) obj = obj_getter(context, filters) return obj
def _get_resource(self, plugin, context, resource, resource_id): with utils.clean_session(context.session): obj_getter = getattr(plugin, 'get_' + resource) obj = obj_getter(context, resource_id) return obj
def _get_resources(self, plugin, context, resource, filters=None): with utils.clean_session(context.session): obj_getter = getattr(plugin, 'get_' + resource + 's') obj = obj_getter(context, filters) return obj
def _get_resources(self, plugin, context, resource, filters=None): with utils.clean_session(context.session): obj_getter = getattr(plugin, "get_" + resource + "s") obj = obj_getter(context, filters) return obj