def set_configure_healthCheck(inputElbNm): print("ELB health check 설정을 진행합니다.") print("Health Check 할 Ping Path 를 입력해주세요.") inputFileNm=input() command = 'aws elb configure-health-check --load-balancer-name '+inputElbNm+' --health-check Target=HTTP:80/'+inputFileNm+',Interval=30,UnhealthyThreshold=2,HealthyThreshold=2,Timeout=3' cmdUtil.exec_commd(command) return "success"
def start_instance(): print("1.instance 리부팅 2.instance 시작") nextStep1_YN = goMain.goPage_inputValCheck( selected_first_menu) # 입력시 p, x 입력시 이전 메뉴 또는 프로그램 종료 진행 search_instance_state = "running" comment_1 = "리부팅" commd_str = "reboot-instances" if nextStep1_YN == "2": search_instance_state = "stopped" commd_str = "start-instances" comment_1 = "시작" if nextStep1_YN != "1" and nextStep1_YN != "2": print("다시 선택해주세요.") start_instance() print("ec2 Instance를 선택해 주세요.") selectedObjInfoArr = select_ec2instance("", "", "", search_instance_state) print("(" + selectedObjInfoArr[0] + ")" + selectedObjInfoArr[4] + " instance 를 " + comment_1 + "하시겠습니까?(y/n)") nextStep2_YN = goMain.goPage_inputValCheck( selected_first_menu) # 입력시 p, x 입력시 이전 메뉴 또는 프로그램 종료 진행 if nextStep2_YN[0] == 'Y' or nextStep2_YN[0] == 'y': command = "aws ec2 " + commd_str + " --instance-ids " + selectedObjInfoArr[ 4] retMsg = cmdUtil.exec_commd(command) print(comment_1 + " 요청이 완료되었습니다.") goMain.go_second_menu(selected_first_menu) else: goMain.go_second_menu(selected_first_menu) return "success"
def del_elb_listener(): print("먼저 ELB를 선택합니다.") selectElbArr = select_elb() print("ELB 에 등록된 Port를 조회합니다.") objArr = select_elb_listeners(selectElbArr[0]) print("삭제하실 Port를 선택하세요") while 1>0: selectPortNo=input() if (int(selectPortNo)-1)>len(objArr): print("잘못 선택하셨습니다. 다시 선택하세요.") else: selectedElbPort = objArr[(int(selectPortNo)-1)] selectedElbPortArr = selectedElbPort.split(" : ") print("선택하신 ("+selectedElbPort+")를 삭제하시겠습니까?(y/n)") nextStep2_YN=input() if nextStep2_YN.lower() == "y": command = 'aws elb delete-load-balancer-listeners --load-balancer-name '+selectElbArr[0] command = command +' --load-balancer-ports '+selectedElbPortArr[1] retStr = cmdUtil.exec_commd(command) break else: break if nextStep2_YN.lower() == "n": goMain.go_second_menu(selected_first_menu) # 이전 메뉴로 이동 return "success"
def create_loadBalance(): print("load Balance는 http(80) 만 생성 가능합니다.") print("생성할 ELB의 명칭을 입력하세요.(예: my-elb)") print("ELB 명칭은 알파벳과 - 만 입력가능합니다.") inputElbNm=input() print("Subnet을 선택합니다.") selectedSubnetInfoArr = mySubnet.select_subnet() print("ELB에 적용할 Security Group을 선택합니다.") selectedSGInfoArr = mysg.select_sg("vpc-id",selectedSubnetInfoArr[4]) print("ELB에 연결할 instance 의 port를 입력하세요.(예: 80)") inputInstPort=input() # print("생성할 Protocol을 선택하세요.") # print("1.http/https 2.http 3.https ") # inputProtocol=goMain.goPage_inputValCheck(selected_first_menu) # 입력시 p, x 입력시 이전 메뉴 또는 프로그램 종료 진행 command = 'aws elb create-load-balancer --load-balancer-name '+inputElbNm+' --listeners' command = command+' "Protocol=HTTP,LoadBalancerPort=80,InstanceProtocol=HTTP,InstancePort='+inputInstPort+'" ' command = command+' --subnets '+selectedSubnetInfoArr[3]+' --security-groups '+selectedSGInfoArr[1] command = command+' --query DNSName' retStr = cmdUtil.exec_commd(command) print("ELB 도메인이 생성되었습니다.") print(retStr) # health check 설정 retStr = set_configure_healthCheck(inputElbNm) if retStr == "success": # instance 연결 parameter : elbNm, vpcid, subnetId register_Instance(inputElbNm, selectedSubnetInfoArr[4], selectedSubnetInfoArr[3]) return "success"
def del_inoutBound(): awsCmd = "" selectedObj = select_inoutBound() selectedInOutBoundArr = (selectedObj).split(' | ') print("선택하신 (" + selectedObj + ") 삭제하시겠습니까?(y/n)") nextStep2_YN = goMain.goPage_inputValCheck( selected_first_menu) # 입력시 p, x 입력시 이전 메뉴 또는 프로그램 종료 진행 if nextStep2_YN.lower() == 'y': if selectedInOutBoundArr[0] == "in": awsCmd = "revoke-security-group-ingress" else: awsCmd = " revoke-security-group-egress" #revoke-security-group-ingress command = 'aws ec2 ' + awsCmd + ' --group-id ' + selectedInOutBoundArr[ 5] + ' --ip-permissions IpProtocol=' + selectedInOutBoundArr[4] if selectedInOutBoundArr[4] != "-1": command = command + ',FromPort=' + selectedInOutBoundArr[ 2] + ',ToPort=' + selectedInOutBoundArr[3] command = command + ',IpRanges="[{CidrIp=' + selectedInOutBoundArr[ 1] + '}]"' cmdUtil.exec_commd(command) print("선택하신 (" + selectedObj + ") 삭제되었습니다.") return "success"
def create_route(): #print("먼저 Subnet을 선택합니다.") #selectedSubnetInfoArr = mySubnet.select_subnet() print("먼저 Vpc를 선택합니다.") selectedVpcInfoArr = myVpcs.select_vpc() print("Vpc에 만들어진 route-table를 선택합니다.") selectedRouteTableArr = select_routeTable(selectedVpcInfoArr[2]) selectedGatewayArr = myGw.select_gw() #"aws ec2 describe-route-tables --filter Name=vpc-id,Values=vpc-0ee42dfba9b4f6010" command = 'aws ec2 create-route --route-table-id ' + selectedRouteTableArr[ 1] + ' --destination-cidr-block 0.0.0.0/0 --gateway-id ' + selectedGatewayArr[ 1] json_res = cmdUtil.exec_commd(command) return json_res
def add_inoutBound(doType): doComment = "Inbound" awsCmd = "authorize-security-group-ingress" if doType == "out": doComment = "Outbound" awsCmd = "authorize-security-group-egress" print("Security Group 에 " + doComment + " 를 추가합니다.") print("먼저 추가할 Security Group을 선택합니다.") selectedSGInfoArr = select_sg("", "") print("TCP Protocol 만 등록 가능합니다.") print("허용할 Port 를 입력해주세요 (예: 80)") inPort = goMain.goPage_inputValCheck( selected_first_menu) # 입력시 p, x 입력시 이전 메뉴 또는 프로그램 종료 진행 print("허용할 IP 대역을 입력해주세요 (예: 192.168.10.23/32") inipRange = goMain.goPage_inputValCheck( selected_first_menu) # 입력시 p, x 입력시 이전 메뉴 또는 프로그램 종료 진행 if cmdUtil.ipValidate(inipRange): print(doComment + " 정책 추가 중입니다.") command = 'aws ec2 ' + awsCmd + ' --group-id ' + selectedSGInfoArr[ 1] + ' --ip-permissions IpProtocol=tcp,FromPort=' + inPort + ',ToPort=' + inPort + ',IpRanges="[{CidrIp=' + inipRange + '}]"' cmdUtil.exec_commd(command) return "success"
def del_elb(): print("삭제할 ELB 를 선택해주세요") objArr = search_all_elb() selectedNo="" while 1>0: selectedNo=input() if int(selectedNo)>len(objArr): print("잘못 선택하셨습니다. 다시 선택해주세요.") else: break command = 'aws elb delete-load-balancer --load-balancer-name '+(objArr[int(selectedNo)-1]).split(' : ')[0] retStr = cmdUtil.exec_commd(command) print("삭제되었습니다.") return "success"
def remove_instance(): print("삭제할 ec2 Instance를 선택해 주세요.") search_instance_state = "running,stopping,stopped" selectedObjInfoArr = select_ec2instance("", "", "", search_instance_state) print("(" + selectedObjInfoArr[0] + ")" + selectedObjInfoArr[4] + " instance 를 삭제하시겠습니까?(y/n)") nextStep2_YN = goMain.goPage_inputValCheck( selected_first_menu) # 입력시 p, x 입력시 이전 메뉴 또는 프로그램 종료 진행 if nextStep2_YN[0] == 'Y' or nextStep2_YN[0] == 'y': command = "aws ec2 terminate-instances --instance-ids " + selectedObjInfoArr[ 4] retMsg = cmdUtil.exec_commd(command) print("삭제 요청이 완료되었습니다.") goMain.go_second_menu(selected_first_menu) else: goMain.go_second_menu(selected_first_menu) return "success"
def deregister_Instance(selectElbArr): registeredInstancesArr = search_registered_Instance_with_elb(selectElbArr) print("연결해제할 instance를 선택하세요.") while 1>0: selectedInstNo=input() if int(selectedInstNo) > len(registeredInstancesArr): print("잘못 선택하셨습니다. 다시 선택해주세요.") else: objArr = (registeredInstancesArr[int(selectedInstNo)-1]).split(" : ") print("선택하신 instance("+objArr[0]+")를 ELB에서 연결해제 하시겠습니까?(y/n)") nextStep1_YN=input() if nextStep1_YN.lower() == "p": goMain.go_second_menu(selected_first_menu) if nextStep1_YN.lower() == "y": command = 'aws elb deregister-instances-from-load-balancer --load-balancer-name '+objArr[7] command = command+' --instances '+objArr[4] retStr = cmdUtil.exec_commd(command) print("연결된 instance를 해제했습니다.") break else: print("다시 선택해주세요.") return "success"
def add_elb_listener(): print("먼저 ELB를 선택합니다.") selectElbArr = select_elb() print("ELB 에 등록된 Port를 조회합니다.") objArr = select_elb_listeners(selectElbArr[0]) print("허용 Port를 추가하시겠습니까?(y/n)") nextStep2_YN=input() if nextStep2_YN.lower() == "n": goMain.go_second_menu(selected_first_menu) # 이전 메뉴로 이동 print("Protocol을 선택하세요.") print("1.HTTP 2.TCP") inputProtocol="0" while 1>0: inputProtocol=input() if inputProtocol == "1" or inputProtocol == "2": if inputProtocol == "1": inputProtocol="HTTP" else: inputProtocol="TCP" break else: print("다시 선택해주세요.") print("ELB Port를 입력하세요.(예: 80)") inputElbPort=input() print("연결할 Instance의 Port를 입력하세요.(예: 80)") inputInstPort=input() print("추가 할 정보("+inputProtocol+" : "+inputElbPort+" : "+inputInstPort+")로 등록하시겠습니까?(y/n)") nextStep2_YN=input() if nextStep2_YN.lower() == "y": command = 'aws elb create-load-balancer-listeners --load-balancer-name '+selectElbArr[0] command = command+' --listeners "Protocol='+inputProtocol+',LoadBalancerPort='+inputElbPort+',InstanceProtocol='+inputProtocol+',InstancePort='+inputInstPort+'"' retStr = cmdUtil.exec_commd(command) print("ELB에 Port가 추가되었습니다.") else: goMain.go_second_menu(selected_first_menu) # 이전 메뉴로 이동
def register_Instance(inputElbNm, vpcId, subnetId): instanceArr = myec2.search_all_ec2instance(vpcId, subnetId, "") i=0 while 1>0: selectedNos = [] selectedInstIds = "" if len(instanceArr)>0: print("ELB에 연결할 instance 들을 1개 이상 엔터로 선택하세요.(예: 1)") print("x 를 입력하면 선택이 종료됩니다.") while 1>0: inputInstNo=input() if inputInstNo.lower() == "x": print("선택을 종료합니다.") break elif (int(inputInstNo)-1)>len(instanceArr): print("잘못 선택하셨습니다. 다시 선택하세요.") else: selectedNos.append(int(inputInstNo)-1) # instanceArr[int(inputInstNo)-1] print("계속 선택해주세요. 선택을 종료하시려면 x 를 입력하세요.") for indexNo in selectedNos: print(instanceArr[indexNo]) selectedInstIds = selectedInstIds+" "+((instanceArr[indexNo]).split(' : '))[4] print("를 선택하셨습니다.") print("Instance 선택을 완료하시겠습니까?(y/n)") print("n 을 입력하시면 instance 를 다시 선택 가능합니다.") nextStep2_YN=input() if nextStep2_YN.lower() == "y": break command3 = 'aws elb register-instances-with-load-balancer --load-balancer-name '+inputElbNm+' --instances '+selectedInstIds retStr = cmdUtil.exec_commd(command3) return "success"
def attach_gw_to_vpc(gwId, vpcId): command = 'aws ec2 attach-internet-gateway --internet-gateway-id '+gwId+' --vpc-id '+vpcId json_res = cmdUtil.exec_commd(command) print("Internet Gateway와 Vpc가 연결되었습니다.") return "success"