/// <summary> /// 创建redis实例 /// </summary> /// <param name="req">参考<see cref="CreateInstancesRequest"/></param> /// <returns>参考<see cref="CreateInstancesResponse"/>实例</returns> public async Task <CreateInstancesResponse> CreateInstances(CreateInstancesRequest req) { JsonResponseModel <CreateInstancesResponse> rsp = null; try { var strResp = await this.InternalRequest(req, "CreateInstances"); rsp = JsonConvert.DeserializeObject <JsonResponseModel <CreateInstancesResponse> >(strResp); } catch (JsonSerializationException e) { throw new TencentCloudSDKException(e.Message); } return(rsp.Response); }
public void TestCreateInstance() { InstanceSpec instanceSpec = new InstanceSpec(); instanceSpec.Az = "cn-north-1a"; instanceSpec.InstanceType = "g.s1.micro"; instanceSpec.ImageId = "98d44a0f-88c1-451a-8971-f1f769073b6c"; instanceSpec.Name = "dotnet-sdk-test"; instanceSpec.Description = "dotnet-sdk"; // 主网卡 NetworkInterfaceSpec networkInterfaceSpec = new NetworkInterfaceSpec(); networkInterfaceSpec.SubnetId = "subnet-j0yka3pkcu"; networkInterfaceSpec.Az = "cn-north-1a"; InstanceNetworkInterfaceAttachmentSpec instanceNetworkInterfaceAttachmentSpec = new InstanceNetworkInterfaceAttachmentSpec(); instanceNetworkInterfaceAttachmentSpec.NetworkInterface = networkInterfaceSpec; instanceSpec.PrimaryNetworkInterface = instanceNetworkInterfaceAttachmentSpec; // 系统盘 InstanceDiskAttachmentSpec systemDisk = new InstanceDiskAttachmentSpec(); systemDisk.DiskCategory = "local"; instanceSpec.SystemDisk = systemDisk; // 数据盘 InstanceDiskAttachmentSpec dataDisk1 = new InstanceDiskAttachmentSpec(); dataDisk1.DiskCategory = "cloud"; dataDisk1.AutoDelete = true; dataDisk1.CloudDiskSpec = new DiskSpec(); dataDisk1.CloudDiskSpec.Name = "sdk-test-disk1"; dataDisk1.CloudDiskSpec.DiskSizeGB = 50; dataDisk1.CloudDiskSpec.DiskType = "premium-hdd"; InstanceDiskAttachmentSpec dataDisk2 = new InstanceDiskAttachmentSpec(); dataDisk2.DiskCategory = "cloud"; dataDisk2.AutoDelete = true; dataDisk2.CloudDiskSpec = new DiskSpec(); dataDisk2.CloudDiskSpec.Name = "sdk-test-disk2"; dataDisk2.CloudDiskSpec.DiskSizeGB = 40; dataDisk2.CloudDiskSpec.DiskType = "ssd"; List <InstanceDiskAttachmentSpec> dataDisks = new List <InstanceDiskAttachmentSpec>(); dataDisks.Add(dataDisk1); dataDisks.Add(dataDisk2); instanceSpec.DataDisks = dataDisks; // 公网IP ElasticIpSpec elasticIpSpec = new ElasticIpSpec(); elasticIpSpec.BandwidthMbps = 2; elasticIpSpec.Provider = "BGP"; instanceSpec.ElasticIp = elasticIpSpec; // 计费方式 ChargeSpec chargeSpec = new ChargeSpec(); chargeSpec.ChargeMode = "postpaid_by_duration"; // 请求创建 CreateInstancesRequest request = new CreateInstancesRequest(); request.RegionId = "cn-north-1"; request.InstanceSpec = instanceSpec; request.MaxCount = 1; var vmClient = GetVmClient(); CreateInstancesResponse response = vmClient.CreateInstances(request); Console.WriteLine(JsonConvert.SerializeObject(response)); // Console.WriteLine(); }