Esempio n. 1
0
    def get_service_unmount_volume_list(self, tenant, service, service_ids, page, page_size, is_config=False):
        """
        1. 获取租户下其他所有组件列表,方便后续进行名称的冗余
        2. 获取其他组件的所有可共享的存储
        3. 获取已经使用的存储,方便后续过滤
        4. 遍历存储,组装信息
        """

        for serviceID in service_ids:
            if serviceID == service.service_id:
                service_ids.remove(serviceID)
        services = service_repo.get_services_by_service_ids(service_ids)
        state_services = []  # 有状态组件
        for svc in services:
            if is_state(svc.extend_method):
                state_services.append(svc)
        state_service_ids = [svc.service_id for svc in state_services]

        current_tenant_services_id = service_ids
        # 已挂载的组件路径
        mounted = mnt_repo.get_service_mnts(tenant.tenant_id, service.service_id)
        mounted_ids = [mnt.volume_id for mnt in mounted]
        # 当前未被挂载的共享路径
        service_volumes = []
        # 配置文件无论组件是否是共享存储都可以共享,只需过滤掉已经挂载的存储;其他存储类型则需要考虑排除有状态组件的存储
        if is_config:
            service_volumes = volume_repo.get_services_volumes(current_tenant_services_id).filter(volume_type=self.CONFIG) \
                .exclude(ID__in=mounted_ids)
        else:
            service_volumes = volume_repo.get_services_volumes(current_tenant_services_id).filter(volume_type=self.SHARE) \
                .exclude(ID__in=mounted_ids).exclude(service_id__in=state_service_ids)
        # TODO 使用函数进行存储的排查,确定哪些存储不可以进行共享,哪些存储可以共享,而不是现在这样简单的提供一个self.SHARE

        total = len(service_volumes)
        volume_paginator = JuncheePaginator(service_volumes, int(page_size))
        page_volumes = volume_paginator.page(page)
        un_mount_dependencies = []
        for volume in page_volumes:
            gs_rel = group_service_relation_repo.get_group_by_service_id(volume.service_id)
            group = None
            if gs_rel:
                group = group_repo.get_group_by_pk(tenant.tenant_id, service.service_region, gs_rel.group_id)
            un_mount_dependencies.append({
                "dep_app_name": services.get(service_id=volume.service_id).service_cname,
                "dep_app_group": group.group_name if group else '未分组',
                "dep_vol_name": volume.volume_name,
                "dep_vol_path": volume.volume_path,
                "dep_vol_type": volume.volume_type,
                "dep_vol_id": volume.ID,
                "dep_group_id": group.ID if group else -1,
                "dep_app_alias": services.get(service_id=volume.service_id).service_alias
            })
        return un_mount_dependencies, total
Esempio n. 2
0
    def get_service_unmnt_details(self, tenant, service, service_ids, page,
                                  page_size):

        services = service_repo.get_services_by_service_ids(*service_ids)
        current_tenant_services_id = service_ids
        # 已挂载的服务路径
        dep_mnt_names = mnt_repo.get_service_mnts(
            tenant.tenant_id, service.service_id).values_list('mnt_name',
                                                              flat=True)
        # 当前未被挂载的共享路径
        service_volumes = volume_repo.get_services_volumes(
            current_tenant_services_id).filter(
                volume_type__in=[self.SHARE, self.CONFIG]).exclude(
                    service_id=service.service_id).exclude(
                        volume_name__in=dep_mnt_names)
        # 只展示无状态的服务组件(有状态服务的存储类型为config-file也可)
        logger.debug('----------volumes----->{0}'.format(
            type(service_volumes)))
        volumes = list(service_volumes)
        for volume in volumes:
            service_obj = service_repo.get_service_by_service_id(
                volume.service_id)
            if service_obj:
                if service_obj.extend_method != "stateless" and volume.volume_type != "config-file":
                    volumes.remove(volume)
        total = len(volumes)
        volume_paginator = JuncheePaginator(volumes, int(page_size))
        page_volumes = volume_paginator.page(page)
        un_mount_dependencies = []
        for volume in page_volumes:
            gs_rel = group_service_relation_repo.get_group_by_service_id(
                volume.service_id)
            group = None
            if gs_rel:
                group = group_repo.get_group_by_pk(tenant.tenant_id,
                                                   service.service_region,
                                                   gs_rel.group_id)
            un_mount_dependencies.append({
                "dep_app_name":
                services.get(service_id=volume.service_id).service_cname,
                "dep_app_group":
                group.group_name if group else '未分组',
                "dep_vol_name":
                volume.volume_name,
                "dep_vol_path":
                volume.volume_path,
                "dep_vol_type":
                volume.volume_type,
                "dep_vol_id":
                volume.ID,
                "dep_group_id":
                group.ID if group else -1,
                "dep_app_alias":
                services.get(service_id=volume.service_id).service_alias
            })
        return un_mount_dependencies, total
Esempio n. 3
0
    def get_service_unmnt_details(self, tenant, service, service_ids, page,
                                  page_size, q):

        services = service_repo.get_services_by_service_ids(service_ids)
        current_tenant_services_id = service_ids
        # 已挂载的组件路径
        dep_mnts = mnt_repo.get_service_mnts(tenant.tenant_id,
                                             service.service_id)
        dep_volume_ids = [dep_mnt.volume_id for dep_mnt in dep_mnts]
        # 当前未被挂载的共享路径
        service_volumes = volume_repo.get_services_volumes(current_tenant_services_id) \
            .filter(volume_type__in=[self.SHARE, self.CONFIG]) \
            .exclude(service_id=service.service_id) \
            .exclude(ID__in=dep_volume_ids).filter(q)
        # 只展示无状态的组件(有状态组件的存储类型为config-file也可)
        volumes = list(service_volumes)
        copy_volumes = copy.copy(volumes)
        for volume in copy_volumes:
            service_obj = service_repo.get_service_by_service_id(
                volume.service_id)
            if service_obj:
                if is_state(service_obj.extend_method):
                    if volume.volume_type != "config-file":
                        volumes.remove(volume)
        total = len(volumes)
        volume_paginator = JuncheePaginator(volumes, int(page_size))
        page_volumes = volume_paginator.page(page)
        un_mount_dependencies = []
        for volume in page_volumes:
            gs_rel = group_service_relation_repo.get_group_by_service_id(
                volume.service_id)
            group = None
            if gs_rel:
                group = group_repo.get_group_by_pk(tenant.tenant_id,
                                                   service.service_region,
                                                   gs_rel.group_id)
            un_mount_dependencies.append({
                "dep_app_name":
                services.get(service_id=volume.service_id).service_cname,
                "dep_app_group":
                group.group_name if group else '未分组',
                "dep_vol_name":
                volume.volume_name,
                "dep_vol_path":
                volume.volume_path,
                "dep_vol_type":
                volume.volume_type,
                "dep_vol_id":
                volume.ID,
                "dep_group_id":
                group.ID if group else -1,
                "dep_app_alias":
                services.get(service_id=volume.service_id).service_alias
            })
        return un_mount_dependencies, total
    def get_service_unmnt_details(self, tenant, service, service_ids, page,
                                  page_size):

        services = service_repo.get_services_by_service_ids(*service_ids)
        current_tenant_services_id = service_ids
        # 已挂载的服务路径
        dep_mnt_names = mnt_repo.get_service_mnts(
            tenant.tenant_id, service.service_id).values_list('mnt_name',
                                                              flat=True)
        # 当前未被挂载的共享路径
        volumes = volume_repo.get_services_volumes(
            current_tenant_services_id).filter(volume_type=self.SHARE).exclude(
                service_id=service.service_id).exclude(
                    volume_name__in=dep_mnt_names)
        total = len(volumes)
        volume_paginator = JuncheePaginator(volumes, int(page_size))
        page_volumes = volume_paginator.page(page)
        un_mount_dependencies = []
        for volume in page_volumes:
            gs_rel = group_service_relation_repo.get_group_by_service_id(
                volume.service_id)
            group = None
            if gs_rel:
                group = group_repo.get_group_by_pk(tenant.tenant_id,
                                                   service.service_region,
                                                   gs_rel.group_id)
            un_mount_dependencies.append({
                "dep_app_name":
                services.get(service_id=volume.service_id).service_cname,
                "dep_app_group":
                group.group_name if group else '未分组',
                "dep_vol_name":
                volume.volume_name,
                "dep_vol_path":
                volume.volume_path,
                "dep_vol_type":
                volume.volume_type,
                "dep_vol_id":
                volume.ID,
                "dep_group_id":
                group.ID if group else -1,
                "dep_app_alias":
                services.get(service_id=volume.service_id).service_alias
            })
        return un_mount_dependencies, total