protected override void ProcessRecord() { base.ProcessRecord(); if (!ConfirmDelete("OCIVirtualNetworkInternetGateway", "Remove")) { return; } DeleteInternetGatewayRequest request; try { request = new DeleteInternetGatewayRequest { IgId = IgId, IfMatch = IfMatch }; response = client.DeleteInternetGateway(request).GetAwaiter().GetResult(); WriteOutput(response); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
/** * Deletes a InternetGateway and waits for it to be deleted. * * @param vcnClient the service client to use to delete the InternetGateway. * @param igId the InternetGateway to delete. */ private static async Task DeleteInternetGateway(VirtualNetworkClient vcnClient, string igId) { DeleteInternetGatewayRequest deleteInternetGatewayRequest = new DeleteInternetGatewayRequest { IgId = igId }; await vcnClient.DeleteInternetGateway(deleteInternetGatewayRequest); logger.Info($"Deleted Internet Gateway: {igId}"); }
private static async Task deleteInternetGateway(VirtualNetworkClient virtualNetworkClient, InternetGateway internetGateway) { DeleteInternetGatewayRequest deleteInternetGatewayRequest = new DeleteInternetGatewayRequest { IgId = internetGateway.Id }; await virtualNetworkClient.DeleteInternetGateway(deleteInternetGatewayRequest); logger.Info($"Deleted Internet Gateway: {internetGateway.Id}"); }
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); }