def post(self, request, *args, **kwargs): print(request.POST) suppUserId = request.POST.get("suppUserId") regionId = request.POST.get("suppId") limit = request.POST.get("pageSize") # 当页有几列 page = request.POST.get("pageStart") # 当前是多少页 VpcId = request.POST.get("VpcId") # if VpcId == "0": # VpcId = 0 act = account.get_act(suppUserId) if act["state"]: print(regionId) vpc_route = aliVpc.aliVpc(act["accessKey"], act["accessSecret"], regionId) vpc_route_list = vpc_route.get_route_list(PageNumber=page, PageSize=limit, VpcId=VpcId) for i in vpc_route_list["RouterTableList"]["RouterTableListType"]: i["accountName"] = suppUserId i["RegionId"] = regionId self.dic_news["data"] = vpc_route_list["RouterTableList"][ "RouterTableListType"] self.dic_news["count"] = len(vpc_route_list) paginator = Paginator(self.dic_news["data"], limit) self.dic_news["data"] = paginator.page(page).object_list return JsonResponse(self.dic_news)
def post(self,request, *args, **kwargs): dic_news = { "state": 0, "code": 0 , "msg": "" , "count": 3000000 , "data": []} accountName = request.POST.get("accountName") # 账号名 RegionId = request.POST.get("RegionId") # 可用区 LoadBalancerId = request.POST.get("LoadBalancerId") # lbID act = account.get_act(accountName) if act["state"]: domain = aliHandle.AliyunSlb(act["accessKey"], act["accessSecret"], RegionId) result = domain.get_slb(LoadBalancerId) # dic_news["count"] = len(result) # dic_news["data"] = result listener = result["ListenerPortsAndProtocol"]["ListenerPortAndProtocol"] dic_news["data"] = listener for i in dic_news["data"]: print(i.get("ForwardPort")) z = domain.get_slb_listener(action=i.get("ListenerProtocol"),LoadBalancerId=LoadBalancerId,ListenerPort=i.get("ListenerPort")) if z.get("Scheduler") == "wrr": z["Scheduler"] = "加权轮询" elif z.get("Scheduler") == "rr": z["Scheduler"] = "轮询" elif z.get("Scheduler") == "wlc": z["Scheduler"] = "加权最少连接" else: pass i.update(z) return JsonResponse(dic_news)
def post(self, request, *args, **kwargs): print(request.POST) suppUserId = request.POST.get("suppUserId") regionId = request.POST.get("suppId") limit = request.POST.get("pageSize") # 当页有几列 page = request.POST.get("pageStart") # 当前是多少页 print(limit, page, 1111) act = account.get_act(suppUserId) status = { "Associating": "绑定中", "Unassociating": "解绑中", "InUse": "已分配", "Available": "可用" } if act["state"]: vpc_eip = aliVpc.aliVpc(act["accessKey"], act["accessSecret"], regionId) vpc_eip_list = vpc_eip.get_eip_addresses(PageNumber=page, PageSize=limit) print(vpc_eip_list) utcBandwidth = "%Y-%m-%dT%H:%M:%SZ" utcTraffic = "%Y-%m-%dT%H:%MZ" for i in vpc_eip_list["EipAddresses"]["EipAddress"]: InternetChargeType = { "PayByTraffic": "共享带宽", "PayByBandwidth": "按固定带宽计费" } times = { "PayByTraffic": "后付费{}创建", "PayByBandwidth": "预付费{}到期" } i["accountName"] = suppUserId i["Status"] = status.get(i.get("Status")) i["RegionId"] = regionId i["BandwidthAndType"] = "{} Mbps\n{}".format( i.get("Bandwidth"), InternetChargeType.get(i.get("InternetChargeType"))) if i.get("ExpiredTime"): i["times"] = times.get(i.get("InternetChargeType")).format( othHandler.utc2local(utcTraffic, i.get("ExpiredTime"))) else: i["times"] = times.get(i.get("InternetChargeType")).format( othHandler.utc2local(utcBandwidth, i.get("AllocationTime"))) self.dic_news["data"] = vpc_eip_list["EipAddresses"]["EipAddress"] self.dic_news["count"] = vpc_eip_list["TotalCount"] print(limit, page) paginator = Paginator(self.dic_news["data"], limit) try: self.dic_news["data"] = paginator.page(page).object_list print(self.dic_news["data"]) except Exception as e: self.dic_news["data"] = paginator.page( paginator.num_pages).object_list return JsonResponse(self.dic_news)
def get(self, request, *args, **kwargs): accountName = request.GET.get("accountName") bucketName = request.GET.get("bucketName") act = account.get_act(accountName) if act["state"]: oss = aliHandle.AliOss(act["accessKey"], act["accessSecret"]) oss_info = oss.get_bucket_info(bucket_name=bucketName) print(oss_info.get("acl").__dict__) return render(request, "aliyun/oss/info.html", locals())
def post(self, request, *args, **kwargs): accessKeyID = request.POST.get("accessKeyID") UserName = request.POST.get("UserName") accountName = request.POST.get("accountName") act = account.get_act(accountName) if act["state"]: ram = aliRam.aliRam(act["accessKey"], act["accessSecret"]) accesskey = ram.delete_accesskey(accessKeyID,UserName) print(accesskey) return JsonResponse({"state":1})
def post(self, request, *args, **kwargs): UserName = request.POST.get("UserName") accountName = request.POST.get("accountName") act = account.get_act(accountName) if act["state"]: ram = aliRam.aliRam(act["accessKey"], act["accessSecret"]) accessKey = ram.create_accesskey(UserName) if accessKey.get("AccessKey"): return JsonResponse({"state":1}) else: return JsonResponse({"state": 0})
def post(self, request, *args, **kwargs): dic_news = { "state": 0, "code": 0 , "msg": "" , "count": 3000000 , "data": []} accountName = request.POST.get("accountName") # 账号名 RegionId = request.POST.get("RegionId") # 可用区 VServerGroupId = request.POST.get("VServerGroupId") # lbID act = account.get_act(accountName) if act["state"]: domain = aliHandle.AliyunSlb(act["accessKey"], act["accessSecret"], RegionId) jj = domain.get_vserver_group_attr(VServerGroupId) print(jj) return JsonResponse(dic_news)
def post(self, request, *args, **kwargs): accessKeyID = request.POST.get("accessKeyID") Status = request.POST.get("Status") UserName = request.POST.get("UserName") accountName = request.POST.get("accountName") if Status == "启用": Status = "Active" elif Status == "禁用": Status = "Inactive" act = account.get_act(accountName) if act["state"]: ram = aliRam.aliRam(act["accessKey"], act["accessSecret"]) accesskey_set_status = ram.update_accesskey(accessKeyID,Status,UserName) print(accesskey_set_status) return JsonResponse({"state":1})
def post(self,request, *args, **kwargs): dic_news = { "state": 0, "code": 0 , "msg": "" , "count": 3000000 , "data": []} accountName = request.POST.get("accountName") # 账号名 RegionId = request.POST.get("RegionId") # 可用区 LoadBalancerId = request.POST.get("LoadBalancerId") # lbID act = account.get_act(accountName) if act["state"]: domain = aliHandle.AliyunSlb(act["accessKey"], act["accessSecret"], RegionId) result = domain.get_vservergroups(LoadBalancerId) dic_news["data"] = result.get("VServerGroups").get("VServerGroup") return JsonResponse(dic_news)
def get(self, request, *args, **kwargs): rbac_menu_permission = request.session.get("rbac_permission_session_key") username = request.session.get("user_info").get("username") role_caption = User2Role.objects.values("role__caption").filter(user__username=username).first() rbac_list = list(Permission2Action2Role.objects.values("permission__menu", "action__code", "permission__url", "permission__caption", "permission__menu__caption", "permission__menu__parent").filter( Q(permission__url__in=rbac_menu_permission.keys()) & Q(role__caption=role_caption["role__caption"]))) for i in rbac_list: i["permission__url"] = i["permission__url"].split("$")[0] accountName = request.GET.get("accountName") RegionId = request.GET.get("RegionId") LoadBalancerId = request.GET.get("LoadBalancerId") act = account.get_act(accountName) if act["state"]: slb = aliHandle.AliyunSlb(act["accessKey"],act["accessSecret"],RegionId) slb_info = slb.get_slb(LoadBalancerId) return render(request,"aliyun/slb/info.html",locals())
def get(self, request, *args, **kwargs): rbac_menu_permission = request.session.get("rbac_permission_session_key") username = request.session.get("user_info").get("username") role_caption = User2Role.objects.values("role__caption").filter(user__username=username).first() rbac_list = list(Permission2Action2Role.objects.values("permission__menu", "action__code", "permission__url", "permission__caption", "permission__menu__caption", "permission__menu__parent").filter( Q(permission__url__in=rbac_menu_permission.keys()) & Q(role__caption=role_caption["role__caption"]))) for i in rbac_list: i["permission__url"] = i["permission__url"].split("$")[0] accountName = request.GET.get("accountName") UserName = request.GET.get("UserName") act = account.get_act(accountName) if act["state"]: ram = aliRam.aliRam(act["accessKey"],act["accessSecret"]) ram_info = ram.get_user(UserName) ram_acc = ram.list_accesskeys(UserName) return render(request,"aliyun/ram/info.html",locals())
def post(self,request, *args, **kwargs): print(request.POST) suppUserId = request.POST.get("suppUserId") limit = request.POST.get("pageSize") # 当页有几列 page = request.POST.get("pageStart") # 当前是多少页 act = account.get_act(suppUserId) if act["state"]: ram = aliRam.aliRam(act["accessKey"],act["accessSecret"]) print(ram.list_users()) ram_user_list = ram.list_users()["Users"]["User"] print(ram_user_list) for i in ram_user_list: i["accountName"] = suppUserId self.dic_news["data"] = ram_user_list self.dic_news["count"] = len(ram_user_list) paginator = Paginator(self.dic_news["data"], limit) self.dic_news["data"] = paginator.page(page).object_list return JsonResponse(self.dic_news)
def post(self, request, *args, **kwargs): print(request.POST) suppUserId = request.POST.get("suppUserId") regionId = request.POST.get("suppId") limit = request.POST.get("pageSize") # 当页有几列 page = request.POST.get("pageStart") # 当前是多少页 act = account.get_act(suppUserId) if act["state"]: vpc = aliVpc.aliVpc(act["accessKey"], act["accessSecret"], regionId) vpc_list = vpc.vpc_list(PageNumber=page, PageSize=limit) print(1) for i in vpc_list["Vpcs"]["Vpc"]: vroute_url = reverse("ali_vpc_route")+\ "?accountName={}&RegionId={}&VpcId={}".format( suppUserId, regionId, i.get("VpcId")) print(vroute_url) vswitch_url = reverse("ali_vpc_switch")+\ "?accountName={}&RegionId={}&VpcId={}".format( suppUserId, regionId, i.get("VpcId")) vroute = "<a href='{}'>{}</a>".format( vroute_url, len(i.get("RouterTableIds").get("RouterTableIds"))) vswitch = "<a href='{}'>{}</a>".format( vswitch_url, len(i.get("VSwitchIds").get("VSwitchId"))) i["vRoute_count"] = vroute i["vSwitch_count"] = vswitch i["accountName"] = suppUserId self.dic_news["data"] = vpc_list["Vpcs"]["Vpc"] self.dic_news["count"] = len(vpc_list) paginator = Paginator(self.dic_news["data"], limit) self.dic_news["data"] = paginator.page(page).object_list return JsonResponse(self.dic_news)
def post(self, request, *args, **kwargs): print(request.POST) suppUserId = request.POST.get("suppUserId") limit = request.POST.get("pageSize") # 当页有几列 page = request.POST.get("pageStart") # 当前是多少页 act = account.get_act(suppUserId) if act["state"]: oss = aliHandle.AliOss(act["accessKey"], act["accessSecret"]) oss_list = oss.get_oss_list() print(type(oss_list), oss_list) if isinstance(oss_list, dict): print(1) self.dic_news["message"] = oss_list.get("details").get( "Message") self.dic_news["state"] = oss_list.get("status") return JsonResponse(self.dic_news) for i in oss_list: i["accountName"] = suppUserId self.dic_news["state"] = 200 self.dic_news["data"] = oss_list self.dic_news["count"] = len(oss_list) # paginator = Paginator(self.dic_news["data"], limit) # self.dic_news["data"] = paginator.page(page).object_list return JsonResponse(self.dic_news)
def get(self, request, *args, **kwargs): rbac_menu_permission = request.session.get( "rbac_permission_session_key") username = request.session.get("user_info").get("username") role_caption = User2Role.objects.values("role__caption").filter( user__username=username).first() rbac_list = list( Permission2Action2Role.objects.values( "permission__menu", "action__code", "permission__url", "permission__caption", "permission__menu__caption", "permission__menu__parent").filter( Q(permission__url__in=rbac_menu_permission.keys()) & Q(role__caption=role_caption["role__caption"]))) for i in rbac_list: i["permission__url"] = i["permission__url"].split("$")[0] accountName = request.GET.get("accountName") RegionId = request.GET.get("RegionId") DBInstanceId = request.GET.get("DBInstanceId") act = account.get_act(accountName) if act["state"]: rds = aliHandle.AliyunRDS(act["accessKey"], act["accessSecret"], RegionId) rds_info = rds.get_rds_instace( DBInstanceId)["Items"]["DBInstanceAttribute"][0] rds_array_list = rds.get_rds_IP_ArrayList( DBInstanceId)["Items"]["DBInstanceIPArray"] rds_info["DBInstanceIPArray"] = rds_array_list if rds_info["Category"] == "Basic": rds_info["Category"] = "基础版" elif rds_info["Category"] == "HighAvailability": rds_info["Category"] = "高可用版" elif rds_info["Category"] == "Finance": rds_info["Category"] = "金融版" else: pass if rds_info["PayType"] == "Postpaid": rds_info["PayType"] = "按量付费" elif rds_info["PayType"] == "Prepaid": rds_info["PayType"] = "包年包月" else: pass if rds_info["DBInstanceClassType"] == "s": rds_info["DBInstanceClassType"] = "共享型" elif rds_info["DBInstanceClassType"] == "x": rds_info["DBInstanceClassType"] = "通用型" elif rds_info["DBInstanceClassType"] == "d": rds_info["DBInstanceClassType"] = "独享套餐" elif rds_info["DBInstanceClassType"] == "h": rds_info["DBInstanceClassType"] = "独占物理机" else: pass if rds_info["DBInstanceStatus"] == "Creating": rds_info["DBInstanceStatus"] = "创建中" elif rds_info["DBInstanceStatus"] == "Running": rds_info["DBInstanceStatus"] = "运行中" elif rds_info["DBInstanceStatus"] == "Deleting": rds_info["DBInstanceStatus"] = "删除中" elif rds_info["DBInstanceStatus"] == "Rebooting": rds_info["DBInstanceStatus"] = "重启中" elif rds_info["DBInstanceStatus"] == "DBInstanceClassChanging ": rds_info["DBInstanceStatus"] = "升降级中" elif rds_info["DBInstanceStatus"] == "TRANSING": rds_info["DBInstanceStatus"] = "迁移中" elif rds_info["DBInstanceStatus"] == "EngineVersionUpgrading": rds_info["DBInstanceStatus"] = "迁移版本中" elif rds_info["DBInstanceStatus"] == "TransingToOthers": rds_info["DBInstanceStatus"] = "迁移数据到其他RDS中" elif rds_info["DBInstanceStatus"] == "GuardDBInstanceCreating": rds_info["DBInstanceStatus"] = "生产灾备实例中" elif rds_info["DBInstanceStatus"] == "Restoring": rds_info["DBInstanceStatus"] = "备份恢复中" elif rds_info["DBInstanceStatus"] == "Importing": rds_info["DBInstanceStatus"] = "数据导入中" elif rds_info["DBInstanceStatus"] == "ImportingFromOthers": rds_info["DBInstanceStatus"] = "从其他RDS实例导入数据中" elif rds_info["DBInstanceStatus"] == "DBInstanceNetTypeChanging ": rds_info["DBInstanceStatus"] = "内外网切换中" elif rds_info["DBInstanceStatus"] == "GuardSwitching": rds_info["DBInstanceStatus"] = "容灾切换中" elif rds_info["DBInstanceStatus"] == "INS_CLONING": rds_info["DBInstanceStatus"] = "实例克隆中" else: rds_info["DBInstanceStatus"] = "未识别的状态" rds_info["DBInstanceDiskUsed"] = rds_info[ "DBInstanceDiskUsed"] / 1024 / 1024 / 1024 local_time = str( othHandler.utc2local("%Y-%m-%dT%H:%M:%SZ", rds_info["CreationTime"])) rds_info["CreationTime"] = local_time time_list = rds_info["MaintainTime"].split("-") local_maintain_time_list = [] for tm in time_list: ti = str(othHandler.utc2local("%H:%MZ", tm).time()) local_maintain_time_list.append(ti) local_maintain_time = "--".join(local_maintain_time_list) rds_info["MaintainTime"] = local_maintain_time print(rds_info) return render(request, "aliyun/rds/info.html", locals())