def get_service_of_avaliable_port(self, group_id): """ 获取可用http端口的服务 :param group_id: :return: """ group = app_group_svc.get_tenant_service_group_by_pk(group_id, True) data = [] for svc in group.service_list: http_port_svcs = app_group_svc.get_service_http_port( svc.service_id) port = http_port_svcs[0] if http_port_svcs else None if port: domains = ServiceDomain.objects.filter( service_id=port.service_id, protocol='http') ret = { 'service_id': svc.service_id, 'service_key': svc.service_key, 'service_name': svc.service_cname, 'service_version': svc.version, } if not domains: ret.update({'domain': ''}) else: ret.update({ 'domain': { 'domain_id': domains[0].ID, 'domain_url': domains[0].domain_name } }) data.append(ret) return data
def install_service_group(self, user, tenant_name, group_key, group_version, region_name, template_version): logger.debug('prepared install [{}-{}] to [{}] on [{}]'.format( group_key, group_version, tenant_name, region_name)) if tenant_name: tenant = self.get_tenant_by_name(tenant_name) else: tenant = self.get_default_tenant_by_user(user.user_id) if not tenant: logger.error('tenant does not existed!') return False, '租户不存在', None logger.debug('login_user_id: {}'.format(user.user_id)) logger.debug('login_user: {}'.format(user.nick_name)) logger.debug('tenant_name: {}'.format(tenant.tenant_name)) # 查看安装的目标数据中心是否已初始化, 如果未初始化则先初始化 if not tenant_svc.init_region_tenant(tenant, region_name): return False, '初始化数据中心失败: {}'.format(region_name), None app_template_json_str = app_group_svc.get_app_templates( tenant.tenant_id, group_key, group_version, template_version) if not app_template_json_str: return False, '初始化应用组模板信息失败', None success, message, group, installed_services = app_group_svc.install_market_apps_directly( user, tenant, region_name, app_template_json_str, 'cloud') if group: group = app_group_svc.get_tenant_service_group_by_pk( group.pk, True, True, True) return success, message, group return success, message, group
def install_tenant_service_group(self, user, tenant_name, group_key, group_version, region_name): logger.debug('prepared install [{}-{}] to [{}] on [{}]'.format( group_key, group_version, tenant_name, region_name)) if tenant_name: tenant = self.get_tenant_by_name(tenant_name) else: tenant = self.get_default_tenant_by_user(user.user_id) if not tenant: logger.error('tenant does not existed!') return False, '租户不存在', None logger.debug('login_user_id: {}'.format(user.user_id)) logger.debug('login_user: {}'.format(user.nick_name)) logger.debug('tenant_name: {}'.format(tenant.tenant_name)) # if app_group_svc.is_tenant_service_group_installed(tenant, region_name, group_key, group_version): # logger.info('group service already installed!') # return False, '应用组已安装, 请卸载后再重装!', None # 查看安装的目标数据中心是否已初始化, 如果未初始化则先初始化 if not tenant_svc.init_region_tenant(tenant, region_name): return False, '初始化数据中心失败: {}'.format(region_name), None app_service_group = app_group_svc.download_app_service_group_from_market( tenant.tenant_id, group_key, group_version) if not app_service_group: return False, '初始化应用组模板信息失败', None success, message, group, installed_services = app_group_svc.install_tenant_service_group( user, tenant, region_name, app_service_group, 'cloud') group = app_group_svc.get_tenant_service_group_by_pk( group.pk, True, True, True) return success, message, group
def get_certificates(self, alias=None, group_id=None): """ 获取证书 :param alias: :param group_id: :return: """ q = Q() if alias: q = q & Q(alias=alias) if group_id: group = app_group_svc.get_tenant_service_group_by_pk(group_id) q = q & Q(tenant_id=group.tenant_id) return ServiceDomainCertificate.objects.filter(q)
def get_group_services_by_pk(self, group_id): return app_group_svc.get_tenant_service_group_by_pk( int(group_id), True, True, False)