def create_service_volume(self, tenant, service, dep_vol): """ raise ErrInvalidVolume raise ErrDepVolumeNotFound """ tenant_service_volumes = volume_service.get_service_volumes( tenant, service) local_path = [l_path.volume_path for l_path in tenant_service_volumes] code, msg = volume_service.check_volume_path(service, dep_vol["path"], local_path=local_path) if code != 200: logger.debug("Service id: {0}; ingore mnt; msg: {1}".format( service.service_id, msg)) raise ErrInvalidVolume(msg) dep_volume = volume_repo.get_service_volume_by_name( dep_vol["service_id"], dep_vol["volume_name"]) if not dep_volume: raise ErrDepVolumeNotFound(dep_vol["service_id"], dep_vol["volume_name"]) source_path = dep_vol['path'].strip() return mnt_repo.add_service_mnt_relation(tenant.tenant_id, service.service_id, dep_volume.service_id, dep_volume.volume_name, source_path)
def add_service_mnt_relation(self, tenant, service, source_path, dep_volume): if service.create_status == "complete": if dep_volume.volume_type != "config-file": data = { "depend_service_id": dep_volume.service_id, "volume_name": dep_volume.volume_name, "volume_path": source_path, "enterprise_id": tenant.enterprise_id, "volume_type": dep_volume.volume_type } else: config_file = volume_repo.get_service_config_file( dep_volume.ID) data = { "depend_service_id": dep_volume.service_id, "volume_name": dep_volume.volume_name, "volume_path": source_path, "volume_type": dep_volume.volume_type, "file_content": config_file.file_content, "enterprise_id": tenant.enterprise_id } res, body = region_api.add_service_dep_volumes( service.service_region, tenant.tenant_name, service.service_alias, data) logger.debug("add service mnt info res: {0}, body:{1}".format( res, body)) mnt_relation = mnt_repo.add_service_mnt_relation( tenant.tenant_id, service.service_id, dep_volume.service_id, dep_volume.volume_name, source_path) logger.debug("mnt service {0} to service {1} on dir {2}".format( mnt_relation.service_id, mnt_relation.dep_service_id, mnt_relation.mnt_dir)) return 200, "success"
def create_service_volume(self, tenant, service, dep_vol): """ raise ErrInvalidVolume raise ErrDepVolumeNotFound """ tenant_service_volumes = volume_service.get_service_volumes( tenant, service) local_path = [ l_path["volume_path"] for l_path in tenant_service_volumes ] volume_service.check_volume_path(service, dep_vol["path"], local_path=local_path) dep_volume = volume_repo.get_service_volume_by_name( dep_vol["service_id"], dep_vol["volume_name"]) if not dep_volume: raise ErrDepVolumeNotFound(dep_vol["service_id"], dep_vol["volume_name"]) source_path = dep_vol['path'].strip() return mnt_repo.add_service_mnt_relation(tenant.tenant_id, service.service_id, dep_volume.service_id, dep_volume.volume_name, source_path)