def detach_disk(self, req, scope_id, id): context = self._get_context(req) scope = self._get_scope(req, scope_id) operation_util.init_operation(context, "detachDisk", self._type_name, id, scope) self._instance_disk_api.delete_item(context, id, req.params.get("deviceName"))
def attach_disk(self, req, body, scope_id, id): context = self._get_context(req) scope = self._get_scope(req, scope_id) operation_util.init_operation(context, "attachDisk", self._type_name, id, scope) self._instance_disk_api.add_item(context, id, body["source"], body.get("deviceName"))
def delete_access_config(self, req, scope_id, id): context = self._get_context(req) scope = self._get_scope(req, scope_id) operation_util.init_operation(context, "deleteAccessConfig", self._type_name, id, scope) self._instance_address_api.delete_item(context, id, req.params.get('accessConfig'))
def create_snapshot(self, req, body, scope_id, id): body["disk_name"] = id scope = self._get_scope(req, scope_id) context = self._get_context(req) operation_util.init_operation(context, "createSnapshot", self._type_name, id, scope) snapshot_api.API().add_item(context, body, scope)
def create(self, req, body, scope_id=None): """GCE add requests.""" scope = self._get_scope(req, scope_id) context = self._get_context(req) operation_util.init_operation(context, "insert", self._type_name, body["name"], scope) self._api.add_item(context, body['name'], body, scope)
def set_disk_auto_delete(self, req, scope_id, id): context = self._get_context(req) scope = self._get_scope(req, scope_id) operation_util.init_operation(context, "setDiskAutoDelete", self._type_name, id, scope) auto_delete = req.params.get("autoDelete").lower() == "true" self._instance_disk_api.set_disk_auto_delete( context, id, req.params.get("deviceName"), auto_delete)
def set_disk_auto_delete(self, req, scope_id, id): context = self._get_context(req) scope = self._get_scope(req, scope_id) operation_util.init_operation(context, "setDiskAutoDelete", self._type_name, id, scope) auto_delete = req.params.get("autoDelete").lower() == "true" self._instance_disk_api.set_disk_auto_delete(context, id, req.params.get("deviceName"), auto_delete)
def add_access_config(self, req, body, scope_id, id): context = self._get_context(req) scope = self._get_scope(req, scope_id) operation_util.init_operation(context, "addAccessConfig", self._type_name, id, scope) self._instance_address_api.add_item(context, id, req.params.get('networkInterface'), body.get("natIP"), body.get("type"), body.get("name"))
def attach_disk(self, req, body, scope_id, id): context = self._get_context(req) scope = self._get_scope(req, scope_id) operation_util.init_operation(context, "attachDisk", self._type_name, id, scope) self._instance_disk_api.add_item(context, id, body.get("initializeParams"), body.get("source"), body.get("deviceName"), body.get("autoDelete", False), scope)
def reset_instance(self, req, scope_id, id): context = self._get_context(req) scope = self._get_scope(req, scope_id) operation_util.init_operation(context, "reset", self._type_name, id, scope) try: self._api.reset_instance(context, scope, id) except (exception.NotFound, KeyError, IndexError): msg = _("Instance %s could not be found") % id raise webob.exc.HTTPNotFound(explanation=msg)
def delete(self, req, id, scope_id=None): """GCE delete requests.""" scope = self._get_scope(req, scope_id) context = self._get_context(req) operation_util.init_operation(context, "delete", self._type_name, id, scope) try: self._api.delete_item(context, id, scope) except (exception.NotFound, KeyError, IndexError): msg = _("Resource '%s' could not be found") % id raise exc.HTTPNotFound(explanation=msg)
def create_snapshot(self, req, body, scope_id, id): body["disk_name"] = id scope = self._get_scope(req, scope_id) context = self._get_context(req) operation_util.init_operation(context, "createSnapshot", self._type_name, id, scope) snapshot = snapshot_api.API().add_item(context, body, scope) # TODO(alexey-mr): workaround: have to set item id here # snapshot_api.API().add_item set_item_id has no effect because # of different type_name disk vs. snapshot # but snapshot type_name can't be used in init_operation because # targetLink and targetId should point to disk object operation_util.set_item_id(context, snapshot['id'], self._type_name)
def delete(self, req, id, scope_id=None): """GCE delete requests.""" scope = self._get_scope(req, scope_id) context = self._get_context(req) operation_util.init_operation(context, "delete", self._type_name, id, scope) try: self._api.delete_item(context, id, scope) except (exception.NotFound, KeyError, IndexError) as ex: LOG.exception(ex) msg = _("Resource '%s' could not be found") % id raise exc.HTTPNotFound(explanation=msg)
def set_common_instance_metadata(self, req, body): context = self._get_context(req) operation_util.init_operation(context, "setMetadata", self._type_name, None, scopes.GlobalScope()) try: self._api.set_common_instance_metadata(context, body.get("items", [])) except exception.KeypairLimitExceeded: msg = _("Quota exceeded, too many key pairs.") raise webob.exc.HTTPRequestEntityTooLarge( explanation=msg, headers={'Retry-After': 0}) except exception.InvalidKeypair: msg = _("Keypair data is invalid") raise webob.exc.HTTPBadRequest(explanation=msg) except exception.KeyPairExists: msg = _("Key pair already exists.") raise webob.exc.HTTPConflict(explanation=msg)
def set_common_instance_metadata(self, req, body): context = self._get_context(req) operation_util.init_operation(context, "setMetadata", self._type_name, None, scopes.GlobalScope()) try: self._api.set_common_instance_metadata( context, body.get("items", [])) except exception.KeypairLimitExceeded: msg = _("Quota exceeded, too many key pairs.") raise webob.exc.HTTPRequestEntityTooLarge( explanation=msg, headers={'Retry-After': 0}) except exception.InvalidKeypair: msg = _("Keypair data is invalid") raise webob.exc.HTTPBadRequest(explanation=msg) except exception.KeyPairExists: msg = _("Key pair already exists.") raise webob.exc.HTTPConflict(explanation=msg)