def __init__(self, ecsid): Aliyunsdk.__init__(self) self.ecsid = ecsid self.resultFormat = resultFormat self.request = DescribeInstancesRequest() self.request.set_accept_format(self.resultFormat) self.request.set_InstanceIds([self.ecsid])
def __init__(self, address, name=None, resultFormat=resultFormat): Aliyunsdk.__init__(self) self.resultFormat = resultFormat rel = GetSlbIpAll() rel.run() if address not in rel.iplist: print('IP: %s is not exists' % address) os._exit(17) self.slbip = address rel = SlbIpToId(self.slbip) rel.run() self.slbid = rel.slbid #如果不提供name参数则根据服务器名称生成name if not name: rel = GetSlbInfo(self.slbip) rel.run() if rel.backendServerId: name = rel.backendServerName.split('-')[-1] t = mydatetime() name = name + '-' + t['year'] + t['mon'] + t['day'] else: name = 'tmp' t = mydatetime() name = name + t['year'] + t['mon'] + t['day'] self.slbname = name self.request = SetLoadBalancerNameRequest() self.request.set_LoadBalancerId(self.slbid) self.request.set_LoadBalancerName(self.slbname)
def __init__(self, slbIp, listenPort, resultFormat=resultFormat): Aliyunsdk.__init__(self) self.listenPort = int(listenPort) #要开放的端口 self.resultFormat = resultFormat self.slbIp = slbIp #要开放端口的SLB IP self.slballip = GetSlbIpAll() self.slballip.run() if not self.slbIp in self.slballip.iplist: #检查SLB IP是否有错 print('SLB IP: %s not exists' % self.slbIp) os._exit(17) self.slbinfo = GetSlbInfo(slbIp) #获取SLB的相关信息 self.slbinfo.run() if len(self.slbinfo.listenerPorts) == 50: #开放端口达到50个,停止添加 print('50 Ports') os._exit(17) if self.listenPort in self.slbinfo.listenerPorts: #如果端口已经开放则跳过 raise SkipPort(self.listenPort) #设置相关参数 self.request = CreateLoadBalancerTCPListenerRequest() self.request.set_accept_format(self.resultFormat) self.request.set_LoadBalancerId(self.slbinfo.slbid) self.request.set_ListenerPort(self.listenPort) self.request.set_BackendServerPort(self.listenPort) #后端服务器开放的端口 self.request.set_Bandwidth(-1) #设置带宽,-1为不限制
def __init__(self, publicIp): Aliyunsdk.__init__(self) self.publicIp = publicIp self.resultFormat = resultFormat self.request = DescribeInstancesRequest() self.request.set_accept_format(self.resultFormat) self.request.set_PublicIpAddresses([self.publicIp])
def handling(self): if u'RequestId' in self.result.keys(): rel = SlbSetName(self.slbip) #删除后端服务器后重新设置SLB名称 rel.run() print('SLB: %s backendServer is deleted' % self.slbip) Aliyunsdk.handling(self)
def handling(self): self.iplist = self.result['LoadBalancers']['LoadBalancer'] l = [] #print('SLB IP:') #sum = len(self.iplist) for re in self.iplist: l.append(re['Address']) self.iplist = l[:] #for i in self.iplist: # print(i) #print 'Total:',sum Aliyunsdk.handling(self)
def handling(self): try: self.ecsid = self.result['Instances']['Instance'][0]['InstanceId'] self.innerIp = self.result['Instances']['Instance'][0][ 'InnerIpAddress']['IpAddress'][0] self.instanceName = self.result['Instances']['Instance'][0][ 'InstanceName'] self.regionId = self.result['Instances']['Instance'][0]['RegionId'] Aliyunsdk.handling(self) except IndexError: print('IP: %s is not exist' % self.publicIp) os._exit(17)
def __init__(self, address, resultFormat=resultFormat): Aliyunsdk.__init__(self) self.resultFormat = resultFormat rel = GetSlbIpAll() rel.run() if address not in rel.iplist: print('IP: %s is not exists' % address) os._exit(17) self.request = DescribeLoadBalancersRequest() self.request.set_accept_format(self.resultFormat) self.request.set_Address(address) self.slbid = ''
def __init__(self, slbip, resultFormat=resultFormat): Aliyunsdk.__init__(self) self.resultFormat = resultFormat self.slbip = slbip #SLB IP rel = GetSlbInfo(slbip) #获得后端服务器的ID rel.run() if not rel.backendServerId: #如果后端未设置服务器则打印信息并退出 print("SLB: %s has not backendServer" % slbip) os._exit(17) #删除后端服务器 self.slbid = rel.slbid self.ecsid = rel.backendServerId self.request = RemoveBackendServersRequest() self.request.set_LoadBalancerId(self.slbid) self.request.set_BackendServers([str(self.ecsid)])
def __init__(self, slbip, ecsip, resultFormat=resultFormat): Aliyunsdk.__init__(self) self.resultFormat = resultFormat self.slbip = slbip self.ecsip = ecsip rel = GetSlbInfo(slbip) rel.run() self.slbid = rel.slbid if rel.backendServerId: #检查SLB IP是否正确 print('SLB: %s is used' % slbip) os._exit(17) rel = EcsIpToId(ecsip) #通过ecs IP获得ID rel.run() self.ecsid = rel.ecsid self.request = AddBackendServersRequest() self.request.set_LoadBalancerId(self.slbid) self.request.set_BackendServers([{"ServerId": str(self.ecsid)}])
def __init__(self, slbIp, listenPort, resultFormat=resultFormat): Aliyunsdk.__init__(self) self.listenPort = int(listenPort) self.resultFormat = resultFormat self.slbIp = slbIp self.slballip = GetSlbIpAll() self.slballip.run() if not self.slbIp in self.slballip.iplist: #检查SLB IP是否正确,否则退出 print('SLB IP: %s not exists' % self.slbIp) os._exit(17) self.slbinfo = GetSlbInfo(slbIp) self.slbinfo.run() if self.listenPort not in self.slbinfo.listenerPorts: #检查要删除的端口是否存在,否则跳过 raise SkipPort(self.listenPort) self.request = DeleteLoadBalancerListenerRequest() self.request.set_accept_format(self.resultFormat) self.request.set_LoadBalancerId(self.slbinfo.slbid) self.request.set_ListenerPort(self.listenPort)
def handling(self): if u'RequestId' in self.result.keys(): rel = SlbSetName(self.slbip) #重新设置SLB的名称,根据ECS的名称(服务器ID-月日) rel.run() print('ecs: %s => slb: %s is added' % (self.ecsip, self.slbip)) Aliyunsdk.handling(self)
def handling(self): re = self.result['LoadBalancers']['LoadBalancer'][0] self.slbid = re['LoadBalancerId'] self.slbip = re['Address'] Aliyunsdk.handling(self)
def run(self): #重载run方法 Aliyunsdk.run(self) #调用父类的run依法 sp = SlbStartPort(self.slbinfo.slbid, self.listenPort) #激活端口 sp.run()
def __init__(self, resultFormat=resultFormat): Aliyunsdk.__init__(self) self.resultFormat = resultFormat self.request = DescribeLoadBalancersRequest() self.request.set_accept_format(self.resultFormat)
def handling(self): if u'RequestId' in self.result.keys(): print('Name: %s is setted' % self.slbname) Aliyunsdk.handling(self)
def handling(self): if u'RequestId' in self.result.keys(): print('Port %s opened' % self.listenPort) Aliyunsdk.handling(self)
def __init__(self, slbid, port, resultFormat=resultFormat): Aliyunsdk.__init__(self) self.resultFormat = resultFormat self.request = StartLoadBalancerListenerRequest() self.request.set_LoadBalancerId(slbid) self.request.set_ListenerPort(port)