def create_security_group(str_vpcid, str_SecurityGroupTyp, str_SecurityGroupName): request = CreateSecurityGroupRequest() request.set_VpcId(str_vpcid) request.set_SecurityGroupType(str_SecurityGroupTyp) request.set_SecurityGroupName(str_SecurityGroupName) response = _send_request(request) return response['SecurityGroupId']
def create_security_group(self): security_group_name = input('please enter sg name:') request = CreateSecurityGroupRequest() request.set_accept_format('json') request.set_SecurityGroupName(security_group_name) request.set_VpcId(self.vpcid) response = self.client.do_action_with_exception(request) response_dict = json.loads(response) return response_dict['SecurityGroupId']
def create_security_group(self, vpc_id): """ Create a security group :param vpc_id: The ID of the VPC in which to create the security group. :return: The created security group ID. """ request = CreateSecurityGroupRequest() request.set_VpcId(vpc_id) response = self._send_request(request) if response is not None: security_group_id = response.get("SecurityGroupId") return security_group_id return None
def init(): security_group_dict = {} for region_id in c_region_id_list: client = AcsClient( conf.secret["aliyun"]["access_key"], conf.secret["aliyun"]["access_secret"], region_id, ) # Import keypair with open(conf.secret["aliyun"]["private_key"]) as f: data = f.read() req = ImportKeyPairRequest() req.set_accept_format("json") req.set_KeyPairName(c_keypair_name) req.set_PublicKeyBody(data) res = json.loads(client.do_action_with_exception(req)) print("Import keypair", res) # Create security group req = CreateSecurityGroupRequest() req.set_accept_format("json") res = json.loads(client.do_action_with_exception(req)) security_group_id = res["SecurityGroupId"] security_group_dict[region_id] = security_group_id print("Create security group", security_group_id) acdb.db.save("security_group_dict", security_group_dict) # Config port range req = AuthorizeSecurityGroupRequest() req.set_accept_format("json") req.set_SecurityGroupId(security_group_id) req.set_IpProtocol("all") req.set_PortRange("-1/-1") req.set_SourceCidrIp("0.0.0.0/0") res = json.loads(client.do_action_with_exception(req)) print("Config port range", res)
def createSecurityGroup(): request = CreateSecurityGroupRequest() request.set_accept_format('json') response = client.do_action_with_exception(request) response = json.loads(str(response, encoding='utf-8')) return response
""" # Security groupの取得 from aliyunsdkecs.request.v20140526.DescribeSecurityGroupsRequest import DescribeSecurityGroupsRequest VPC_ID = "vpc-***********" request = DescribeSecurityGroupsRequest() request.set_accept_format('json') request.set_VpcId(VPC_ID) response = json.loads(client.do_action_with_exception(request)) """ # Security Groupの作成 from aliyunsdkecs.request.v20140526.CreateSecurityGroupRequest import CreateSecurityGroupRequest request = CreateSecurityGroupRequest() request.set_accept_format('json') request.set_VpcId(VPC_ID) response = json.loads(client.do_action_with_exception(request)) # 確認 SECURITY_GROUP_ID = response["SecurityGroupId"] print("SECURITY_GROUP_ID : ", SECURITY_GROUP_ID) print("\n") print(json.dumps(response, indent=4, sort_keys=True)) # ECS Instanceの作成 from aliyunsdkecs.request.v20140526.RunInstancesRequest import RunInstancesRequest # 変数の準備 IMAGE_ID = "ubuntu_18_04_64_20G_alibase_20190624.vhd"