def test_11_delete_subnet(self): print("================Begin Test Delete Subnet================") listVpcResp = cli.vpcStub.ListVpc(c.ListVpcRequest(header=c.Header(regionId='gz'), start=0, limit=10)) self.assertEqual(listVpcResp.error.errno, 0) self.assertTrue(len(listVpcResp.data) > 0) for vpc in listVpcResp.data: # 选中刚才创建的VPC if vpc.name == 'testChangeVpcName': vpcToCheckDelete = vpc.vpcUuid break self.assertIsNotNone(vpcToCheckDelete) listSubnetResp = cli.vpcStub.ListSubnet(c.ListSubnetRequest(header=c.Header(regionId='gz'), start=0, limit=10, condition=c.ListSubnetCondition( vpcUuid=vpcToCheckDelete))) self.assertEqual(listSubnetResp.error.errno, 0) self.assertTrue(len(listSubnetResp.data) > 0) deleteSubnetReq = c.DeleteSubnetRequest(header=c.Header(regionId='gz'),vpcUuid=vpcToCheckDelete) subnetToDelete = deleteSubnetReq.subnet.add() subnetToDelete.subnetUuid=listSubnetResp.data[0].subnetUuid deleteSubnetResp = cli.vpcStub.DeleteSubnet(deleteSubnetReq) print(deleteSubnetResp) self.assertEqual(deleteSubnetResp.error.errno, 0) print("deleteSubnet, jobUuid:", deleteSubnetResp.data[0].jobUuid) success = cli.wait_for_job_result('gz', deleteSubnetResp.data[0].jobUuid) # 轮询等待结果 print("deleteSubnet, success:", success) self.assertTrue(success)
def test_08_change_subnet_name(self): print("================Begin Test Delete Snap================") listVpcResp = cli.vpcStub.ListVpc(c.ListVpcRequest(header=c.Header(regionId='gz'), start=0, limit=10)) self.assertEqual(listVpcResp.error.errno, 0) self.assertTrue(len(listVpcResp.data) > 0) for vpc in listVpcResp.data: # 选中刚才创建的VPC if vpc.name == 'testChangeVpcName': vpcToChangeUuid = vpc.vpcUuid break self.assertIsNotNone(vpcToChangeUuid) listSubnetResp = cli.vpcStub.ListSubnet(c.ListSubnetRequest(header=c.Header(regionId='gz'), start=0, limit=10, condition=c.ListSubnetCondition( vpcUuid=vpcToChangeUuid))) print(listSubnetResp) self.assertEqual(listSubnetResp.error.errno, 0) self.assertTrue(len(listSubnetResp.data) > 0) changeSubnetNameReq = c.ChangeSubnetNameRequest(header=c.Header(regionId='gz'),vpcUuid=vpcToChangeUuid) subnetToChangeName = changeSubnetNameReq.subnet.add() subnetToChangeName.subnetUuid = listSubnetResp.data[0].subnetUuid subnetToChangeName.name = 'testChangeSubnetName' changeSubnetNameResp = cli.vpcStub.ChangeSubnetName(changeSubnetNameReq) print(changeSubnetNameResp) self.assertEqual(changeSubnetNameResp.error.errno, 0) print("changeSubnetName, jobUuid:", changeSubnetNameResp.data[0].jobUuid) success = cli.wait_for_job_result('gz', changeSubnetNameResp.data[0].jobUuid) # 轮询等待结果 print("changeSubnetName, success:", success) self.assertTrue(success)
def test_06_get_subnet_total_cnt(self): print("================Begin Test Get Subnet Total Cnt================") listVpcResp = cli.vpcStub.ListVpc(c.ListVpcRequest(header=c.Header(regionId='gz'), start=0, limit=10)) print(listVpcResp) self.assertEqual(listVpcResp.error.errno, 0) self.assertTrue(len(listVpcResp.data) > 0) cntResp = cli.vpcStub.GetVpcTotalCnt(c.GetSubnetTotalCntRequest(header=c.Header(regionId='gz'), vpcUuid=listVpcResp.data[0].vpcUuid)) print(cntResp) self.assertEqual(cntResp.error.errno, 0) self.assertTrue(cntResp.data[0].totalCnt > 0)
def test_05_list_subnet(self): print("================Begin Test List Subnet================") listVpcResp = cli.vpcStub.ListVpc(c.ListVpcRequest(header=c.Header(regionId='gz'), start=0, limit=10)) print(listVpcResp) self.assertEqual(listVpcResp.error.errno, 0) self.assertTrue(len(listVpcResp.data) > 0) listSubnetResp = cli.vpcStub.ListSubnet(c.ListSubnetRequest(header=c.Header(regionId='gz'), start=0, limit=10, condition=c.ListSubnetCondition(vpcUuid=listVpcResp.data[0].vpcUuid))) print(listSubnetResp) self.assertEqual(listSubnetResp.error.errno, 0) self.assertTrue(len(listSubnetResp.data) > 0)
def test_10_check_subnet_cidr_overlap(self): print("================Begin Test Check Subnet Cidr Overlap================") listVpcResp = cli.vpcStub.ListVpc(c.ListVpcRequest(header=c.Header(regionId='gz'), start=0, limit=10)) self.assertEqual(listVpcResp.error.errno, 0) self.assertTrue(len(listVpcResp.data) > 0) for vpc in listVpcResp.data: # 选中刚才创建的VPC if vpc.name == 'testChangeVpcName': vpcToCheckUuid = vpc.vpcUuid break self.assertIsNotNone(vpcToCheckUuid) checkSubnetOverlapResp = cli.vpcStub.CheckSubnetCidrOverlap(c.CheckSubnetCidrOverlapRequest(header=c.Header(regionId='gz'), vpcUuid=vpcToCheckUuid,cidr='172.16.0.0/16')) self.assertEqual(checkSubnetOverlapResp.error.errno, 0) self.assertTrue(len(checkSubnetOverlapResp.data) > 0)
def test_02_create_dc2(self): print("================Begin Test Create Dc2================") # 获取镜像并选择 imgResp = cli.dc2Stub.ListImage( c.ListImageRequest(header=c.Header(regionId='gz'))) self.assertEqual(imgResp.error.errno, 0) for img in imgResp.data: if img.osFamily == 'CentOS' and img.osVersion == '7.5': targetImgUuid = img.imgUuid break self.assertNotEqual(len(targetImgUuid), 0) print("choose image, uuid:", targetImgUuid) # 获取子网并选择 vpcResp = cli.vpcStub.ListVpc( c.ListVpcRequest(header=c.Header(regionId='gz'), start=0, limit=10)) self.assertEqual(vpcResp.error.errno, 0) subnetResp = cli.vpcStub.ListSubnet( c.ListSubnetRequest(header=c.Header(regionId='gz'), condition=c.ListSubnetCondition( vpcUuid=vpcResp.data[0].vpcUuid), start=0, limit=10)) self.assertEqual(subnetResp.error.errno, 0) print("choose subnet, uuid:", subnetResp.data[0].subnetUuid) createDc2Req = c.CreateDc2Request( header=c.Header(regionId='gz'), name='test-python-sdk', imgUuid=targetImgUuid, subnetUuid=subnetResp.data[0].subnetUuid, dc2Model='dc2.s1.small1.d20', password=str_to_hex('YourPassword123')) # 密码进行16位编码后传输 createDc2Req.eip.bandwidth = 5 # 同时创建EIP,设置带宽 ebs1 = createDc2Req.ebs.add() # 同时创建EBS,对于数组参数调用add()添加 ebs1.diskType = 'SSD' ebs1.size = 30 createDc2Resp = cli.dc2Stub.CreateDc2(createDc2Req) # 创建DC2 print(createDc2Resp) self.assertEqual(createDc2Resp.error.errno, 0) print("createDc2, jobUuid:", createDc2Resp.data[0].jobUuid) success = cli.wait_for_job_result( 'gz', createDc2Resp.data[0].jobUuid) # 轮询等待结果 print("createDc2, success:", success) self.assertTrue(success)
def test_01_create_sg(self): print("================Begin Test Create Sg================") listVpcResp = cli.vpcStub.ListVpc( c.ListVpcRequest(header=c.Header(regionId='gz'), start=0, limit=10)) # 获取一个vpc的Uuid self.assertEqual(listVpcResp.error.errno, 0) self.assertTrue(len(listVpcResp.data) > 0) createSgReq = c.CreateSgRequest( header=c.Header(regionId='gz'), name='testSg', vpcUuid=listVpcResp.data[0].vpcUuid) # 创建一个默认vpc的sg createSgResp = cli.sgStub.CreateSg(createSgReq) print(createSgResp) self.assertEqual(createSgResp.error.errno, 0) print("createSg, jobUuid:", createSgResp.data[0].jobUuid) success = cli.wait_for_job_result( 'gz', createSgResp.data[0].jobUuid) # 轮询等待结果 print("createSg, success:", success) self.assertTrue(success)
def test_02_create_subnet(self): print("================Begin Test Create Subnet================") listVpcResp = cli.vpcStub.ListVpc(c.ListVpcRequest(header=c.Header(regionId='gz'), start=0, limit=10)) self.assertEqual(listVpcResp.error.errno, 0) self.assertTrue(len(listVpcResp.data) > 0) for vpc in listVpcResp.data: # 选中刚才创建的VPC if vpc.name == 'testCreateVpc': vpcToCreate = vpc.vpcUuid break self.assertIsNotNone(vpcToCreate) createSubnetReq = c.CreateSubnetRequest(header=c.Header(regionId='gz'), vpcUuid=vpcToCreate) subnetToCreate = createSubnetReq.subnet.add() subnetToCreate.name='testCreateSubnet' subnetToCreate.cidr='172.16.0.0/16' subnetToCreate.zoneId='gz02' createSubnetResp = cli.vpcStub.CreateSubnet(createSubnetReq) self.assertEqual(createSubnetResp.error.errno, 0) print("createSubnet, jobUuid:", createSubnetResp.data[0].jobUuid) success = cli.wait_for_job_result('gz', createSubnetResp.data[0].jobUuid) # 轮询等待结果 print("createSubnet, success:", success) self.assertTrue(success)
def test_07_change_vpc_name(self): print("================Begin Test Change Vpc Name================") listVpcResp = cli.vpcStub.ListVpc(c.ListVpcRequest(header=c.Header(regionId='gz'), start=0, limit=10)) self.assertEqual(listVpcResp.error.errno, 0) self.assertTrue(len(listVpcResp.data) > 0) for vpc in listVpcResp.data: # 选中刚才创建的VPC if vpc.name == 'testCreateVpc': vpcToChangeUuid = vpc.vpcUuid break self.assertIsNotNone(vpcToChangeUuid) changeVpcNameReq = c.ChangeVpcNameRequest(header=c.Header(regionId='gz')) vpcToChangeName = changeVpcNameReq.vpc.add() vpcToChangeName.vpcUuid=vpcToChangeUuid vpcToChangeName.name = 'testChangeVpcName' changeVpcNameResp = cli.vpcStub.ChangeVpcName(changeVpcNameReq) print(changeVpcNameResp) self.assertEqual(changeVpcNameResp.error.errno, 0) print("changeVpcName, jobUuid:", changeVpcNameResp.data[0].jobUuid) success = cli.wait_for_job_result('gz', changeVpcNameResp.data[0].jobUuid) # 轮询等待结果 print("changeVpcName, success:", success) self.assertTrue(success)
def test_03_list_vpc(self): print("================Begin Test List Vpc================") listResp = cli.vpcStub.ListVpc(c.ListVpcRequest(header=c.Header(regionId='gz'), start=0, limit=10)) print(listResp) self.assertEqual(listResp.error.errno, 0) self.assertTrue(len(listResp.data) > 0)