def create_servicechain_instance(self, context, servicechain_instance): """Instance created. When a Servicechain Instance is created, all its nodes need to be instantiated. """ instance = self._process_commit_phase(context) if instance: return instance deployers = {} # REVISIT: Consider adding ensure_tenant() call here with db_api.CONTEXT_WRITER.using(context): instance = super(NodeCompositionPlugin, self).create_servicechain_instance( context, servicechain_instance) if len(instance['servicechain_specs']) > 1: raise exc.OneSpecPerInstanceAllowed() deployers = self._get_scheduled_drivers(context, instance, 'deploy') if not gutils.is_precommit_policy_driver_configured(): # Actual node deploy try: self._deploy_servicechain_nodes(context, deployers) except Exception: # Some node could not be deployed with excutils.save_and_reraise_exception(): LOG.error( "Node deployment failed, " "deleting servicechain_instance %s", instance['id']) self.delete_servicechain_instance(context, instance['id']) return instance
def create_servicechain_instance(self, context, servicechain_instance): """Instance created. When a Servicechain Instance is created, all its nodes need to be instantiated. """ session = context.session deployers = {} with session.begin(subtransactions=True): instance = super(NodeCompositionPlugin, self).create_servicechain_instance( context, servicechain_instance) if len(instance['servicechain_specs']) > 1: raise exc.OneSpecPerInstanceAllowed() deployers = self._get_scheduled_drivers(context, instance, 'deploy') # Actual node deploy try: self._deploy_servicechain_nodes(context, deployers) except Exception: # Some node could not be deployed with excutils.save_and_reraise_exception(): LOG.error( _LE("Node deployment failed, " "deleting servicechain_instance %s"), instance['id']) self.delete_servicechain_instance(context, instance['id']) return instance
def update_servicechain_instance(self, context, servicechain_instance_id, servicechain_instance): """Instance updated. When a Servicechain Instance is updated and the spec changed, all the nodes of the previous spec should be destroyed and the newer ones created. """ session = context.session deployers = {} destroyers = {} with session.begin(subtransactions=True): original_instance = self.get_servicechain_instance( context, servicechain_instance_id) updated_instance = super(NodeCompositionPlugin, self).update_servicechain_instance( context, servicechain_instance_id, servicechain_instance) if (original_instance['servicechain_specs'] != updated_instance['servicechain_specs']): if len(updated_instance['servicechain_specs']) > 1: raise exc.OneSpecPerInstanceAllowed() destroyers = self._get_scheduled_drivers( context, original_instance, 'destroy') deployers = self._get_scheduled_drivers( context, updated_instance, 'deploy') self._destroy_servicechain_nodes(context, destroyers) self._deploy_servicechain_nodes(context, deployers) return updated_instance
def update_servicechain_instance(self, context, servicechain_instance_id, servicechain_instance): """Instance updated. When a Servicechain Instance is updated and the spec changed, all the nodes of the previous spec should be destroyed and the newer ones created. """ instance = self._process_commit_phase(context) if instance: return instance session = context.session deployers = {} updaters = {} destroyers = {} with session.begin(subtransactions=True): original_instance = self.get_servicechain_instance( context, servicechain_instance_id) updated_instance = super(NodeCompositionPlugin, self).update_servicechain_instance( context, servicechain_instance_id, servicechain_instance) if (original_instance['servicechain_specs'] != updated_instance['servicechain_specs']): if len(updated_instance['servicechain_specs']) > 1: raise exc.OneSpecPerInstanceAllowed() destroyers = self._get_scheduled_drivers( context, original_instance, 'destroy') else: # Could be classifier update updaters = self._get_scheduled_drivers(context, original_instance, 'update') if (original_instance['servicechain_specs'] != updated_instance['servicechain_specs']): self._destroy_servicechain_nodes(context, destroyers) deployers = self._get_scheduled_drivers(context, updated_instance, 'deploy') context.deployers = deployers context.servicechain_instance = updated_instance if not gutils.is_precommit_policy_driver_configured(): self._deploy_servicechain_nodes(context, deployers) else: self._update_servicechain_nodes(context, updaters) return updated_instance
def _get_resource(self, context, resource_name, resource_id, fields=None): session = context.session deployers = {} with session.begin(subtransactions=True): resource = getattr(super(NodeCompositionPlugin, self), 'get_' + resource_name)(context, resource_id) if resource_name == 'servicechain_instance': if len(resource['servicechain_specs']) > 1: raise exc.OneSpecPerInstanceAllowed() try: deployers = self._get_scheduled_drivers( context, resource, 'get') except Exception: LOG.warning(_LW("Failed to get node driver")) # Invoke drivers only if status attributes are requested if not fields or STATUS_SET.intersection(set(fields)): _resource = self._get_resource_status(context, resource_name, deployers) if _resource: updated_status = _resource['status'] updated_status_details = _resource['status_details'] if resource['status'] != updated_status or ( resource['status_details'] != updated_status_details): new_status = { resource_name: { 'status': updated_status, 'status_details': updated_status_details } } session = context.session with session.begin(subtransactions=True): getattr(super(NodeCompositionPlugin, self), 'update_' + resource_name)(context, resource['id'], new_status) resource['status'] = updated_status resource['status_details'] = updated_status_details return self._fields(resource, fields)