D6285: automation: don't create resources when deleting things

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Wed May 15 11:46:30 EDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rHGdd6a9723ae2b: automation: don't create resources when deleting things (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6285?vs=14862&id=15089

REVISION DETAIL
  https://phab.mercurial-scm.org/D6285

AFFECTED FILES
  contrib/automation/hgautomation/__init__.py
  contrib/automation/hgautomation/aws.py
  contrib/automation/hgautomation/cli.py

CHANGE DETAILS

diff --git a/contrib/automation/hgautomation/cli.py b/contrib/automation/hgautomation/cli.py
--- a/contrib/automation/hgautomation/cli.py
+++ b/contrib/automation/hgautomation/cli.py
@@ -95,12 +95,12 @@
 
 
 def terminate_ec2_instances(hga: HGAutomation, aws_region):
-    c = hga.aws_connection(aws_region)
+    c = hga.aws_connection(aws_region, ensure_ec2_state=False)
     aws.terminate_ec2_instances(c.ec2resource)
 
 
 def purge_ec2_resources(hga: HGAutomation, aws_region):
-    c = hga.aws_connection(aws_region)
+    c = hga.aws_connection(aws_region, ensure_ec2_state=False)
     aws.remove_resources(c)
 
 
diff --git a/contrib/automation/hgautomation/aws.py b/contrib/automation/hgautomation/aws.py
--- a/contrib/automation/hgautomation/aws.py
+++ b/contrib/automation/hgautomation/aws.py
@@ -180,7 +180,7 @@
 class AWSConnection:
     """Manages the state of a connection with AWS."""
 
-    def __init__(self, automation, region: str):
+    def __init__(self, automation, region: str, ensure_ec2_state: bool=True):
         self.automation = automation
         self.local_state_path = automation.state_path
 
@@ -191,11 +191,12 @@
         self.ec2resource = self.session.resource('ec2')
         self.iamclient = self.session.client('iam')
         self.iamresource = self.session.resource('iam')
-
-        ensure_key_pairs(automation.state_path, self.ec2resource)
+        self.security_groups = {}
 
-        self.security_groups = ensure_security_groups(self.ec2resource)
-        ensure_iam_state(self.iamresource)
+        if ensure_ec2_state:
+            ensure_key_pairs(automation.state_path, self.ec2resource)
+            self.security_groups = ensure_security_groups(self.ec2resource)
+            ensure_iam_state(self.iamresource)
 
     def key_pair_path_private(self, name):
         """Path to a key pair private key file."""
diff --git a/contrib/automation/hgautomation/__init__.py b/contrib/automation/hgautomation/__init__.py
--- a/contrib/automation/hgautomation/__init__.py
+++ b/contrib/automation/hgautomation/__init__.py
@@ -53,7 +53,7 @@
 
         return password
 
-    def aws_connection(self, region: str):
+    def aws_connection(self, region: str, ensure_ec2_state: bool=True):
         """Obtain an AWSConnection instance bound to a specific region."""
 
-        return AWSConnection(self, region)
+        return AWSConnection(self, region, ensure_ec2_state=ensure_ec2_state)



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list