public void DeleteSecurityGroupTest() { var entity = new DeleteSecurityGroupRequest(Config.region, "15031"); var response = unet.DeleteSecurityGroup(entity); Assert.AreEqual(response.RetCode, 0); }
/// <summary> /// 删除防火墙 /// </summary> /// <param name="requestParams">请求参数.</param> /// <returns>返回对象<see cref="UCloudSDK.Models.DeleteSecurityGroupResponse"/></returns> public DeleteSecurityGroupResponse DeleteSecurityGroup(DeleteSecurityGroupRequest requestParams) { var request = new RestRequest(Method.GET); request.AddUObject(requestParams); return(Execute <DeleteSecurityGroupResponse>(request)); }
private static void DeleteSecurityGroup(VpcClient client) { var req = new DeleteSecurityGroupRequest { SecurityGroupId = "efa0d2e2-314f-44f2-99f6-ecfeaab3ba9d" }; try { DeleteSecurityGroupResponse resp = client.DeleteSecurityGroup(req); Console.WriteLine(resp.HttpStatusCode); } catch (RequestTimeoutException requestTimeoutException) { Console.WriteLine(requestTimeoutException.ErrorMessage); } catch (ServiceResponseException clientRequestException) { Console.WriteLine(clientRequestException.HttpStatusCode); Console.WriteLine(clientRequestException.ErrorCode); Console.WriteLine(clientRequestException.ErrorMsg); } catch (ConnectionException connectionException) { Console.WriteLine(connectionException.ErrorMessage); } }
/// <summary> /// Initializes the Amazon EC2 client object and then uses it to call /// the DeleteSecurityGroupAsync method to delete the security group. /// </summary> public static async Task Main() { string secGroupId = "sg-05c1b890f35c2c89e"; string groupName = "sample-security-group"; // If your Amazon EC2 security grup is not defined in the same AWS // Region as the default user on your system, you need to supply // the AWS Region as a parameter to the client constructor. var client = new AmazonEC2Client(); var request = new DeleteSecurityGroupRequest { GroupId = secGroupId, GroupName = groupName, }; var response = await client.DeleteSecurityGroupAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine($"Successfully deleted {groupName}."); } else { Console.WriteLine($"Could not delete {groupName}."); } }
private async Task DeleteSecurityGroup(string id) { _context.Logger.WriteLine("DeleteSecurityGroup"); var request = new DeleteSecurityGroupRequest { GroupId = id }; await _client.DeleteSecurityGroupAsync(request); }
/// <summary> /// 删除安全组 /// </summary> public async Task <DeleteSecurityGroupResponse> DeleteSecurityGroupAsync(DeleteSecurityGroupRequest deleteSecurityGroupRequest) { Dictionary <string, string> urlParam = new Dictionary <string, string>(); urlParam.Add("security_group_id", deleteSecurityGroupRequest.SecurityGroupId.ToString()); string urlPath = HttpUtils.AddUrlPath("/v1/{project_id}/security-groups/{security_group_id}", urlParam); SdkRequest request = HttpUtils.InitSdkRequest(urlPath, deleteSecurityGroupRequest); HttpResponseMessage response = await DoHttpRequestAsync("DELETE", request); return(JsonUtils.DeSerializeNull <DeleteSecurityGroupResponse>(response)); }
/// <summary> /// Delete Security Group /// </summary> /// <param name="request">Delete Security Group request</param> /// <returns>Delete Security Group Response from the service</returns> /// <remarks> /// The DeleteSecurityGroup operation deletes a security group. /// Note: /// If you attempt to delete a security group that contains instances, a fault is /// returned. /// If you attempt to delete a security group that is referenced by another /// security group, a fault is returned. For example, if security group B has a /// rule that allows access from security group A, security group A cannot be /// deleted until the allow rule is removed. /// /// </remarks> public DeleteSecurityGroupResponse DeleteSecurityGroup(DeleteSecurityGroupRequest request) { return(Invoke <DeleteSecurityGroupResponse>("DeleteSecurityGroupResponse.xml")); }
public bool delete_vpc_all(string region_txt) { try { var client = get_client(); write_log(region + " の VPC を確認しています。"); var query_req = new DescribeVpcsRequest(); query_req.Filters.Add(new Filter() { Name = "tag-value", Values = new List <string>() { Helper.build_name(setting_, "vpc") } }); var query_res = client.DescribeVpcs(query_req); if (query_res.Vpcs.Count == 0) { write_log(region + " の VPC が存在しませんでした。"); return(true); } vpc_id = query_res.Vpcs[0].VpcId; var query_instance_req = new DescribeInstancesRequest(); var query_instance_res = client.DescribeInstances(query_instance_req); bool flg = true; foreach (var row in query_instance_res.Reservations) { foreach (var row2 in row.Instances) { if (row2.State != null && row2.State.Code != 48 && row2.VpcId != null && row2.VpcId.Equals(vpc_id)) { flg = false; break; } } if (flg == false) { break; } } if (flg == false) { write_log(region + " にはインスタンスが存在する為、VPC を削除できません。"); return(false); } write_log(region + " のセキュリティグループを確認しています。"); var query_sg_req = new DescribeSecurityGroupsRequest(); query_sg_req.Filters.Add(new Filter() { Name = "tag-value", Values = new List <string>() { Helper.build_name(setting_, "sg") } }); var query_sg_res = client.DescribeSecurityGroups(query_sg_req); foreach (var row in query_sg_res.SecurityGroups) { write_log("セキュリティグループ " + row.GroupId + " を削除しています。"); var delete_sg_req = new DeleteSecurityGroupRequest(); delete_sg_req.GroupId = row.GroupId; client.DeleteSecurityGroup(delete_sg_req); } using (FileStream fs = new FileStream(region_txt, FileMode.Open, FileAccess.Read)) { IList <string> list = new List <string>(subnet_ids.Keys); foreach (string tag in list) { if (Helper.check_az(fs, region, tag, 0) == false) { continue; } write_log(region + tag + " のサブネットを確認しています。"); var query_sub_req = new DescribeSubnetsRequest(); query_sub_req.Filters.Add(new Filter() { Name = "tag-value", Values = new List <string>() { Helper.build_name(setting_, "subnet_" + tag) } }); var query_sub_res = client.DescribeSubnets(query_sub_req); foreach (var row in query_sub_res.Subnets) { write_log("サブネット " + row.SubnetId + " を削除しています。"); var delete_sub_req = new DeleteSubnetRequest(); delete_sub_req.SubnetId = row.SubnetId; client.DeleteSubnet(delete_sub_req); } } } write_log(region + " のインターネットゲートウェイを確認しています。"); var query_igw_req = new DescribeInternetGatewaysRequest(); query_igw_req.Filters.Add(new Filter() { Name = "tag-value", Values = new List <string>() { Helper.build_name(setting_, "igw") } }); var query_igw_res = client.DescribeInternetGateways(query_igw_req); foreach (var row in query_igw_res.InternetGateways) { var detach_igw_req = new DetachInternetGatewayRequest(); detach_igw_req.InternetGatewayId = row.InternetGatewayId; detach_igw_req.VpcId = vpc_id; client.DetachInternetGateway(detach_igw_req); var delete_igw_req = new DeleteInternetGatewayRequest(); delete_igw_req.InternetGatewayId = row.InternetGatewayId; client.DeleteInternetGateway(delete_igw_req); } write_log("VPC " + vpc_id + " を削除しています。"); var delete_vpc_req = new DeleteVpcRequest(); delete_vpc_req.VpcId = vpc_id; client.DeleteVpc(delete_vpc_req); } catch (Exception ex) { write_log("ERROR: " + ex.ToString()); return(false); } return(true); }