Ejemplo n.º 1
0
    def __save_service_mnt_relation(self, tenant, service_mnt_relation_list, old_new_service_id_map):
        new_service_mnt_relation_list = []
        if service_mnt_relation_list:
            for mnt in service_mnt_relation_list:
                mnt.pop("ID")
                new_service_mnt = TenantServiceMountRelation(**mnt)
                new_service_mnt.tenant_id = tenant.tenant_id
                new_service_mnt.service_id = old_new_service_id_map[mnt["service_id"]]
                new_service_mnt.dep_service_id = old_new_service_id_map[mnt["dep_service_id"]]
                new_service_mnt_relation_list.append(new_service_mnt)

            TenantServiceMountRelation.objects.bulk_create(new_service_mnt_relation_list)
Ejemplo n.º 2
0
 def dep_volumes(self, service_mnts):
     mnt_repo.delete_mnt(self.service.service_id)
     if not service_mnts:
         return
     mnts = []
     for item in service_mnts:
         item.pop("ID")
         mnt = TenantServiceMountRelation(**item)
         mnts.append(mnt)
     mnt_repo.bulk_create(mnts)
Ejemplo n.º 3
0
    def _create_volume_deps(self, raw_components):
        """
        Create new volume dependencies with application template
        """
        volumes = []
        for cpt in raw_components:
            volumes.extend(cpt.volumes)
        components = {
            cpt.component_source.service_share_uuid: cpt.component
            for cpt in raw_components
        }
        original_components = {
            cpt.component_source.service_share_uuid: cpt.component
            for cpt in self.original_app.components()
        }

        deps = []
        for tmpl in self.app_template.get("apps", []):
            component_key = tmpl.get("service_share_uuid")
            component = components.get(component_key)
            if not component:
                continue

            volume_deps = tmpl.get("mnt_relation_list")
            if not volume_deps:
                continue
            for dep in volume_deps:
                # check if the dependent component exists
                dep_component_key = dep["service_share_uuid"]
                dep_component = components.get(
                    dep_component_key) if components.get(
                        dep_component_key) else original_components.get(
                            dep_component_key)
                if not dep_component:
                    logger.info("dependent component({}) not found".format(
                        dep_component.service_id))
                    continue

                # check if the dependent volume exists
                if not self._volume_exists(volumes, dep_component.service_id,
                                           dep["mnt_name"]):
                    logger.info("dependent volume({}/{}) not found".format(
                        dep_component.service_id, dep["mnt_name"]))
                    continue

                dep = TenantServiceMountRelation(
                    tenant_id=component.tenant_id,
                    service_id=component.service_id,
                    dep_service_id=dep_component.service_id,
                    mnt_name=dep["mnt_name"],
                    mnt_dir=dep["mnt_dir"],
                )
                deps.append(dep)
        return deps
Ejemplo n.º 4
0
 def _create_volume_deps(self, component_ids):
     volume_deps = []
     for snap in self.snapshot["components"]:
         volume_deps.extend([
             TenantServiceMountRelation(**dep)
             for dep in snap["service_mnts"]
         ])
     # filter out the component dependencies which dep_service_id does not belong to the components
     return [
         dep for dep in volume_deps if dep.dep_service_id in component_ids
     ]
Ejemplo n.º 5
0
    def get_service_mnts_filter_volume_type(self,
                                            tenant_id,
                                            service_id,
                                            volume_types=None):
        conn = BaseConnection()
        query = "mnt.tenant_id = '%s' and mnt.service_id = '%s'" % (tenant_id,
                                                                    service_id)
        if volume_types:
            vol_type_sql = " and volume.volume_type in ({})".format(','.join(
                ["'%s'"] * len(volume_types)))
            query += vol_type_sql % tuple(volume_types)

        sql = """
        select mnt.mnt_name,
            mnt.mnt_dir,
            mnt.dep_service_id,
            mnt.service_id,
            mnt.tenant_id,
            volume.volume_type,
            volume.ID as volume_id
        from tenant_service_mnt_relation as mnt
                 inner join tenant_service_volume as volume
                            on mnt.dep_service_id = volume.service_id and mnt.mnt_name = volume.volume_name
        where {};
        """.format(query)
        result = conn.query(sql)
        dep_mnts = []
        for real_dep_mnt in result:
            mnt = TenantServiceMountRelation(
                tenant_id=real_dep_mnt.get("tenant_id"),
                service_id=real_dep_mnt.get("service_id"),
                dep_service_id=real_dep_mnt.get("dep_service_id"),
                mnt_name=real_dep_mnt.get("mnt_name"),
                mnt_dir=real_dep_mnt.get("mnt_dir"))
            mnt.volume_type = real_dep_mnt.get("volume_type")
            mnt.volume_id = real_dep_mnt.get("volume_id")
            dep_mnts.append(mnt)
        return dep_mnts
 def __save_service_mnt_relation(self, tenant, service_mnt_relation_list,
                                 old_new_service_id_map, same_team,
                                 same_region):
     new_service_mnt_relation_list = []
     if service_mnt_relation_list:
         for mnt in service_mnt_relation_list:
             mnt.pop("ID")
             new_service_mnt = TenantServiceMountRelation(**mnt)
             new_service_mnt.tenant_id = tenant.tenant_id
             new_service_mnt.service_id = old_new_service_id_map[
                 mnt["service_id"]]
             if old_new_service_id_map.get(mnt["dep_service_id"]):
                 new_service_mnt.dep_service_id = old_new_service_id_map[
                     mnt["dep_service_id"]]
             elif same_team and same_region:
                 new_service_mnt.dep_service_id = mnt["dep_service_id"]
             else:
                 continue
             new_service_mnt_relation_list.append(new_service_mnt)
         TenantServiceMountRelation.objects.bulk_create(
             new_service_mnt_relation_list)
Ejemplo n.º 7
0
 def init(self):
     self.sources = [
         Tenants(),
         TenantRegionInfo(),
         TenantRegionResource(),
         ServiceInfo(),
         TenantServiceInfo(),
         TenantServiceInfoDelete(),
         TenantServiceLog(),
         TenantServiceRelation(),
         TenantServiceEnv(),
         TenantServiceAuth(),
         TenantServiceExtendMethod(),
         ServiceDomain(),
         ServiceDomainCertificate(),
         PermRelService(),
         PermRelTenant(),
         PhoneCode(),
         TenantServiceL7Info(),
         TenantServiceEnvVar(),
         TenantServicesPort(),
         TenantServiceMountRelation(),
         TenantServiceVolume(),
         TenantServiceConfigurationFile(),
         ServiceGroup(),
         ServiceGroupRelation(),
         ImageServiceRelation(),
         ComposeServiceRelation(),
         ServiceRule(),
         ServiceRuleHistory(),
         ServiceCreateStep(),
         ServiceProbe(),
         ConsoleConfig(),
         TenantEnterprise(),
         TenantEnterpriseToken(),
         TenantServiceGroup(),
         ServiceTcpDomain(),
         ThirdPartyServiceEndpoints(),
         ServiceWebhooks(),
         GatewayCustomConfiguration(),
         ConsoleSysConfig(),
         RainbondCenterApp(),
         RainbondCenterAppInherit(),
         RainbondCenterPlugin(),
         ServiceShareRecord(),
         EnterpriseUserPerm(),
         TenantUserRole(),
         TenantUserPermission(),
         TenantUserRolePermission(),
         PermGroup(),
         ServiceRelPerms(),
         AppExportRecord(),
         UserMessage(),
         AppImportRecord(),
         GroupAppBackupRecord(),
         GroupAppMigrateRecord(),
         GroupAppBackupImportRecord(),
         Applicants(),
         DeployRelation(),
         ServiceBuildSource(),
         TenantServiceBackup(),
         AppUpgradeRecord(),
         ServiceUpgradeRecord(),
         RegionConfig(),
         CloundBangImages(),
         Announcement(),
     ]