def dep_volumes_changes(self, new_dep_volumes): def key(sid, mnt_name): logger.debug("sid: {}; mnt_name: {}".format(sid, mnt_name)) return sid + "-" + mnt_name old_dep_volumes = mnt_repo.get_service_mnts(self.service.tenant_id, self.service.service_id) olds = {key(item.dep_service_id, item.mnt_name): item for item in old_dep_volumes} tenant_service_volumes = volume_repo.get_service_volumes(self.service.service_id) local_path = [item.volume_path for item in tenant_service_volumes] add = [] for new_dep_volume in new_dep_volumes: dep_service = app_service.get_service_by_service_key(self.service, new_dep_volume["service_share_uuid"]) logger.debug("dep_service: {}".format(dep_service)) if dep_service is None: continue if olds.get(key(dep_service["service_id"], new_dep_volume["mnt_name"]), None): logger.debug("ignore dep volume: {}; dep volume exist.".format( key(dep_service["service_id"], new_dep_volume["mnt_name"]))) continue code, msg = volume_service.check_volume_path(self.service, new_dep_volume["mnt_dir"], local_path=local_path) if code != 200: logger.warning("service id: {}; path: {}; invalid volume: {1}".format(self.service.service_id, new_dep_volume["mnt_dir"], msg)) new_dep_volume["service_id"] = dep_service["service_id"] add.append(new_dep_volume) if not add: return None return {"add": add}
def create_plugin_cfg_4marketsvc(self, tenant, service, version, plugin_id, build_version, service_plugin_config_vars): service_source = service_source_repo.get_service_source( tenant.tenant_id, service.service_id) config_list = [] for config in service_plugin_config_vars: dest_service_id, dest_service_alias = "", "" if config["service_meta_type"] == "downstream_port": service_key = rbd_center_app_service.get_service_key_by_service_id( tenant, service_source, version, config["dest_service_id"]) dest_service = app_service.get_service_by_service_key( service, service_key) dest_service_id = dest_service.service_id dest_service_alias = dest_service.service_alias config_list.append( ServicePluginConfigVar( service_id=service.service_id, plugin_id=plugin_id, build_version=build_version, service_meta_type=config["service_meta_type"], injection=config["injection"], dest_service_id=dest_service_id, dest_service_alias=dest_service_alias, container_port=config["container_port"], attrs=config["attrs"], protocol=config["protocol"])) ServicePluginConfigVar.objects.bulk_create(config_list)
def create_plugin_cfg_4marketsvc(self, tenant, service, version, plugin_id, build_version, components, service_plugin_config_vars): config_list = [] component_id_key_map = {} for com in components: if type(com) == dict: component_id_key_map[com["service_id"]] = com["service_share_uuid"] for config in service_plugin_config_vars: dest_service_id, dest_service_alias = "", "" if config["service_meta_type"] == "downstream_port": # step1: get dep component key dep_service_key = component_id_key_map.get(config["dest_service_id"]) dest_service = app_service.get_service_by_service_key(service, dep_service_key) if dest_service: dest_service_id = dest_service.get("service_id", "") dest_service_alias = dest_service.get("service_alias", "") config_list.append( ServicePluginConfigVar( service_id=service.service_id, plugin_id=plugin_id, build_version=build_version, service_meta_type=config["service_meta_type"], injection=config["injection"], dest_service_id=dest_service_id, dest_service_alias=dest_service_alias, container_port=config["container_port"], attrs=config["attrs"], protocol=config["protocol"])) if config_list and len(config_list) > 0: ServicePluginConfigVar.objects.bulk_create(config_list)