def search_subnets(srcStr): if srcStr == 'search-all': command = 'aws ec2 describe-subnets --query Subnets[*]' else: command = 'aws ec2 describe-subnets --filter Name=tag-value,Values=*' + srcStr + '* --query Subnets[*]' json_res = cmdUtil.getJson_exec_commd(command) return json_res
def search_routeTables(srcStr): if srcStr == 'search-all': command = 'aws ec2 describe-route-tables --query RouteTables[*]' else: command = 'aws ec2 describe-route-tables --filter Name=vpc-id,Values=' + srcStr + ' --query RouteTables[*]' json_res = cmdUtil.getJson_exec_commd(command) return json_res
def select_ec2instance_byId(instanceId): command = "aws ec2 describe-instances --instance-ids " + instanceId + " --query Reservations[*].Instances[0]" json_res = cmdUtil.getJson_exec_commd(command) selectedObjInfoArr = [] for oneObj in json_res: objInfo = get_simple_ec2instance_info(oneObj) selectedObjInfoArr.append(objInfo) return selectedObjInfoArr
def search_sg(srcKey, srcStr): search_wd = "" if srcKey == "vpc-id": search_wd = " Name=vpc-id,Values=" + srcStr if search_wd != "": search_wd = "--filter" + search_wd command = 'aws ec2 describe-security-groups ' + search_wd + ' --query SecurityGroups[*]' json_res = cmdUtil.getJson_exec_commd(command) return json_res
def search_elb(): command = 'aws elb describe-load-balancers --query LoadBalancerDescriptions[*]' json_res = cmdUtil.getJson_exec_commd(command) objArr=[] if len(json_res) < 1: print("먼저 ELB 를 생성해주세요.") goMain.go_second_menu(selected_first_menu) else: for elbinfo in json_res: objArr.append(get_simple_elb_info(elbinfo)) return objArr
def search_elb_instances(inputElbNm): command = 'aws elb describe-load-balancers --load-balancer-names '+inputElbNm+' --query LoadBalancerDescriptions[0].Instances[*]' json_res = cmdUtil.getJson_exec_commd(command) if len(json_res) < 1: print("ELB에 할당된 instance가 없습니다.") flatMain.go_first_menu(selected_first_menu) instanceIds = "" for elbinfo in json_res: instanceIds = instanceIds+" "+elbinfo.get("InstanceId") selectedObjInfoArr = myec2.select_ec2instance_byId(instanceIds) return selectedObjInfoArr
def select_elb_listeners(searchElbNm): command = 'aws elb describe-load-balancers --load-balancer-names '+searchElbNm+' --query LoadBalancerDescriptions[0].ListenerDescriptions[*].Listener ' json_res = cmdUtil.getJson_exec_commd(command) objArr=[] if len(json_res) < 1: print("ELB에 허용 Port가 설정되어 있지 않습니다.") else: print("현재 ELB에 허용 Port는 아래와 같습니다.") i=0 for elbinfo in json_res: i+=1 listenerObj = get_simple_elb_listener_info(elbinfo) print(str(i)+"."+listenerObj) objArr.append(listenerObj) return objArr
def search_inoutBound(searchtype): print("먼저 Security Group을 선택합니다.") selectedSGInfoArr = select_sg("", "") command = 'aws ec2 describe-security-groups --group-ids ' + selectedSGInfoArr[ 1] + ' --query SecurityGroups[0]' json_res = cmdUtil.getJson_exec_commd(command) retArr = [] if len(json_res.get("IpPermissions")) > 0: retArr = retArr + get_simple_inoutBound_info( "in", selectedSGInfoArr[1], json_res.get("IpPermissions")) if len(json_res.get("IpPermissionsEgress")) > 0: retArr = retArr + get_simple_inoutBound_info( "out", selectedSGInfoArr[1], json_res.get("IpPermissionsEgress")) i = 0 for retObj in retArr: i += 1 print(str(i) + "." + retObj) return retArr
def search_ec2instance(search_vpc, search_subnet, search_tagname, instance_state): search_word = "" if search_vpc != "": search_word = search_word + " Name=vpc-id,Values=" + search_vpc if search_subnet != "": search_word = search_word + " Name=subnet-id,Values=" + search_subnet if search_tagname != "": search_word = search_word + " Name=tag-value,Values=" + search_tagname if instance_state != "": search_word = search_word + " Name=instance-state-name,Values=" + instance_state if search_word != "": search_word = "--filter" + search_word command = "aws ec2 describe-instances " + search_word + " --query Reservations[*].Instances[0]" json_res = cmdUtil.getJson_exec_commd(command) return json_res
def get_elb_instances(): objArr=[] command = 'aws elb describe-load-balancers --query LoadBalancerDescriptions[*]' json_res = cmdUtil.getJson_exec_commd(command) if len(json_res) > 0: for elbinfo in json_res: elbNm = elbinfo.get("LoadBalancerName") dnsNm = elbinfo.get("DNSName") instanceArr = elbinfo.get("Instances") if len(instanceArr) > 0: for instObj in instanceArr: instanceId = instObj.get("InstanceId") elbInstObj = elbNm+" : "+dnsNm+" : "+instanceId objArr.append(elbInstObj) else: elbInstObj = elbNm+" : "+dnsNm+" : " objArr.append(elbInstObj) return objArr
def search_instance_image(searchStr): if searchStr == "": command = 'aws ec2 describe-images --owners amazon --filters "Name=name,Values=amzn2-ami-hvm-*-x86_64-gp2" "Name=state,Values=available" --query "reverse(sort_by(Images, &CreationDate))[:3]"' #elif (searchStr.lower()).contains("ubuntu"): elif "ubuntu" in searchStr.lower(): command = 'aws ec2 describe-images --image-id ami-04876f29fd3a5e8ba ami-0ba5cd124d7a79612 ami-08508144e576d5b64 --query "reverse(sort_by(Images, &CreationDate))[:3]"' else: searchStr = "*" + searchStr + "*" command = 'aws ec2 describe-images --owners amazon --filters "Name=name,Values=' + searchStr + '" "Name=state,Values=available" --query "reverse(sort_by(Images, &CreationDate))[:3]"' ret_obj = cmdUtil.getJson_exec_commd(command) selectedObjInfoArr = [] objArr = [] if len(ret_obj) < 1: print("해당 이미지가 없습니다.") goMain.go_second_menu(selected_first_menu) else: i = 0 for oneObj in ret_obj: i += 1 objInfo = get_simple_image_info(oneObj) objArr.append(objInfo) print(str(i) + "." + objInfo) print("p.다시 검색해서 선택합니다.") selectedNo = goMain.goPage_inputValCheck( selected_first_menu) # 입력시 p, x 입력시 이전 메뉴 또는 프로그램 종료 진행 # 사용자가 입력한 번호가 vpc arr 보다 많으면 처음부터 다시 시작. if selectedNo == "p" or selectedNo == "P": selectedObjInfoArr = "research" elif int(selectedNo) > len(objArr): print("잘못 선택하셨습니다. 처음부터 다시 시작합니다.") goMain.go_second_menu(selected_first_menu) else: # 선택한 번호에 맞는 vpcid를 변수에 저장합니다. selectedObjInfoArr = (objArr[int(selectedNo) - 1]).split(' : ') # for index in range(len(objArr)): # if selectedNo == str(index+1): # selectedObjInfoArr = (objArr[index]).split(' : ') # break return selectedObjInfoArr
def search_subnets_byCidr(selectedVpcId, selectedSubnetCidr): command = 'aws ec2 describe-subnets --filter Name=vpc-id,Values=' + selectedVpcId + ' Name=cidr-block,Values=' + selectedSubnetCidr + '* --query Subnets[*]' json_res = cmdUtil.getJson_exec_commd(command) return json_res
def search_instance_profiles(): command = 'aws iam list-instance-profiles --query InstanceProfiles[*]' json_res = cmdUtil.getJson_exec_commd(command) return json_res
def search_vpcs_byCidr(cidr): command = 'aws ec2 describe-vpcs --filter Name=cidr,Values=' + cidr + ' --query Vpcs[*]' json_res = cmdUtil.getJson_exec_commd(command) return json_res
def search_keypairs(): command = 'aws ec2 describe-key-pairs --query KeyPairs[*]' json_res = cmdUtil.getJson_exec_commd(command) return json_res
def search_gw(): command = "aws ec2 describe-internet-gateways --query InternetGateways[*]" json_res = cmdUtil.getJson_exec_commd(command) return json_res