You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by om...@apache.org on 2019/04/08 12:46:45 UTC

[incubator-dlab] branch DLAB-594 created (now 4c04431)

This is an automated email from the ASF dual-hosted git repository.

omartushevskyi pushed a change to branch DLAB-594
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git.


      at 4c04431  [DLAB-594]: added tags for Elastic IPs

This branch includes the following new commits:

     new 4c04431  [DLAB-594]: added tags for Elastic IPs

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org


[incubator-dlab] 01/01: [DLAB-594]: added tags for Elastic IPs

Posted by om...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

omartushevskyi pushed a commit to branch DLAB-594
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git

commit 4c04431dd8c164db29ab3e8c6157f9d31befe761
Author: Oleh Martushevskyi <Ol...@epam.com>
AuthorDate: Mon Apr 8 15:46:36 2019 +0300

    [DLAB-594]: added tags for Elastic IPs
---
 .../src/general/lib/aws/actions_lib.py                   | 16 ----------------
 .../src/general/scripts/aws/edge_associate_elastic_ip.py |  7 ++++++-
 .../src/general/scripts/aws/edge_prepare.py              |  5 ++++-
 .../src/general/scripts/aws/ssn_associate_elastic_ip.py  |  7 ++++++-
 .../src/general/scripts/aws/ssn_prepare.py               | 12 ++++++++----
 5 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/infrastructure-provisioning/src/general/lib/aws/actions_lib.py b/infrastructure-provisioning/src/general/lib/aws/actions_lib.py
index b31b104..b6978c8 100644
--- a/infrastructure-provisioning/src/general/lib/aws/actions_lib.py
+++ b/infrastructure-provisioning/src/general/lib/aws/actions_lib.py
@@ -189,22 +189,6 @@ def create_tag(resource, tag, with_tag_res_id=True):
         Tags=tags_list
     )
 
-def create_product_tag(resource):
-    print('Tag product for the resource {} will be created'.format(resource))
-    tags_list = list()
-    ec2 = boto3.client('ec2')
-    if type(resource) != list:
-        resource = [resource]
-    tags_list.append(
-        {
-            'Key': os.environ['conf_billing_tag_key'],
-            'Value': os.environ['conf_billing_tag_value']
-        }
-    )
-    ec2.create_tags(
-        Resources=resource,
-        Tags=tags_list
-    )
 
 def remove_emr_tag(emr_id, tag):
     try:
diff --git a/infrastructure-provisioning/src/general/scripts/aws/edge_associate_elastic_ip.py b/infrastructure-provisioning/src/general/scripts/aws/edge_associate_elastic_ip.py
index b23e4f7..bfc2df9 100644
--- a/infrastructure-provisioning/src/general/scripts/aws/edge_associate_elastic_ip.py
+++ b/infrastructure-provisioning/src/general/scripts/aws/edge_associate_elastic_ip.py
@@ -31,6 +31,8 @@ import argparse
 parser = argparse.ArgumentParser()
 parser.add_argument('--elastic_ip', type=str, default='')
 parser.add_argument('--edge_id', type=str)
+parser.add_argument('--infra_tag_name', type=str, default='')
+parser.add_argument('--infra_tag_value', type=str, default='')
 args = parser.parse_args()
 
 if __name__ == "__main__":
@@ -44,7 +46,10 @@ if __name__ == "__main__":
         if args.elastic_ip == 'None':
             print("Allocating Elastic IP")
             allocation_id = allocate_elastic_ip()
-            create_product_tag(allocation_id)
+            tag = {"Key": args.infra_tag_name, "Value": args.infra_tag_value}
+            tag_name = {"Key": "Name", "Value": args.infra_tag_value}
+            create_tag(allocation_id, tag)
+            create_tag(allocation_id, tag_name)
         else:
             allocation_id = get_allocation_id_by_elastic_ip(args.elastic_ip)
 
diff --git a/infrastructure-provisioning/src/general/scripts/aws/edge_prepare.py b/infrastructure-provisioning/src/general/scripts/aws/edge_prepare.py
index 71423cd..2e5380a 100644
--- a/infrastructure-provisioning/src/general/scripts/aws/edge_prepare.py
+++ b/infrastructure-provisioning/src/general/scripts/aws/edge_prepare.py
@@ -88,6 +88,8 @@ if __name__ == "__main__":
         edge_conf['allowed_ip_cidr'].append({"CidrIp": cidr.replace(' ','')})
     edge_conf['network_type'] = os.environ['conf_network_type']
     edge_conf['all_ip_cidr'] = '0.0.0.0/0'
+    edge_conf['elastic_ip_name'] = '{0}-{1}-edge-EIP'.format(edge_conf['service_base_name'],
+                                                             os.environ['edge_user_name'])
     if 'aws_user_predefined_s3_policies' not in os.environ:
         os.environ['aws_user_predefined_s3_policies'] = 'None'
 
@@ -532,7 +534,8 @@ if __name__ == "__main__":
                 edge_conf['elastic_ip'] = os.environ['edge_elastic_ip']
             except:
                 edge_conf['elastic_ip'] = 'None'
-            params = "--elastic_ip {} --edge_id {}".format(edge_conf['elastic_ip'], edge_conf['edge_id'])
+            params = "--elastic_ip {} --edge_id {}  --infra_tag_name {} --infra_tag_value {}".format(
+                edge_conf['elastic_ip'], edge_conf['edge_id'], edge_conf['tag_name'], edge_conf['elastic_ip_name'])
             try:
                 local("~/scripts/{}.py {}".format('edge_associate_elastic_ip', params))
             except:
diff --git a/infrastructure-provisioning/src/general/scripts/aws/ssn_associate_elastic_ip.py b/infrastructure-provisioning/src/general/scripts/aws/ssn_associate_elastic_ip.py
index f86b1cd..55bb37d 100644
--- a/infrastructure-provisioning/src/general/scripts/aws/ssn_associate_elastic_ip.py
+++ b/infrastructure-provisioning/src/general/scripts/aws/ssn_associate_elastic_ip.py
@@ -31,6 +31,8 @@ import argparse
 parser = argparse.ArgumentParser()
 parser.add_argument('--elastic_ip', type=str, default='')
 parser.add_argument('--ssn_id', type=str)
+parser.add_argument('--infra_tag_name', type=str, default='')
+parser.add_argument('--infra_tag_value', type=str, default='')
 args = parser.parse_args()
 
 if __name__ == "__main__":
@@ -43,7 +45,10 @@ if __name__ == "__main__":
         if args.elastic_ip == 'None':
             print("Allocating Elastic IP")
             allocation_id = allocate_elastic_ip()
-            create_product_tag(allocation_id)
+            tag = {"Key": args.infra_tag_name, "Value": args.infra_tag_value}
+            tag_name = {"Key": "Name", "Value": args.infra_tag_value}
+            create_tag(allocation_id, tag)
+            create_tag(allocation_id, tag_name)
         else:
             allocation_id = get_allocation_id_by_elastic_ip(args.elastic_ip)
 
diff --git a/infrastructure-provisioning/src/general/scripts/aws/ssn_prepare.py b/infrastructure-provisioning/src/general/scripts/aws/ssn_prepare.py
index 3fcda41..04b47fb 100644
--- a/infrastructure-provisioning/src/general/scripts/aws/ssn_prepare.py
+++ b/infrastructure-provisioning/src/general/scripts/aws/ssn_prepare.py
@@ -73,12 +73,16 @@ if __name__ == "__main__":
         policy_path = '/root/files/ssn_policy.json'
         vpc_cidr = os.environ['conf_vpc_cidr']
         vpc2_cidr = os.environ['conf_vpc2_cidr']
+        vpc_name = '{}-VPC'.format(service_base_name)
+        vpc2_name = '{}-secondary-VPC'.format(service_base_name)
+        subnet_name = '{}-subnet'.format(service_base_name)
         allowed_ip_cidr = list()
         for cidr in os.environ['conf_allowed_ip_cidr'].split(','):
             allowed_ip_cidr.append({"CidrIp": cidr.replace(' ','')})
         sg_name = instance_name + '-SG'
         network_type = os.environ['conf_network_type']
         all_ip_cidr = '0.0.0.0/0'
+        elastic_ip_name = '{0}-ssn-EIP'.format(os.environ['conf_service_base_name'])
 
         try:
             if not os.environ['aws_vpc_id']:
@@ -96,7 +100,7 @@ if __name__ == "__main__":
                     traceback.print_exc()
                     raise Exception
                 os.environ['aws_vpc_id'] = get_vpc_by_tag(tag_name, service_base_name)
-                create_product_tag(os.environ['aws_vpc_id'])
+                create_tag(os.environ['aws_vpc_id'], {"Key": "Name", "Value": vpc_name})
             except Exception as err:
                 print('Error: {0}'.format(err))
                 append_result("Failed to create VPC. Exception:" + str(err))
@@ -122,7 +126,7 @@ if __name__ == "__main__":
                     traceback.print_exc()
                     raise Exception
                 os.environ['aws_vpc2_id'] = get_vpc_by_tag(tag2_name, service_base_name)
-                create_product_tag(os.environ['aws_vpc2_id'])
+                create_tag(os.environ['aws_vpc2_id'], {"Key": "Name", "Value": vpc2_name})
             except Exception as err:
                 print('Error: {0}'.format(err))
                 append_result("Failed to create secondary VPC. Exception:" + str(err))
@@ -149,7 +153,6 @@ if __name__ == "__main__":
                     raise Exception
                 with open('/tmp/ssn_subnet_id', 'r') as f:
                     os.environ['aws_subnet_id'] = f.read()
-                create_product_tag(os.environ['aws_subnet_id'])
                 enable_auto_assign_ip(os.environ['aws_subnet_id'])
             except Exception as err:
                 print('Error: {0}'.format(err))
@@ -427,7 +430,8 @@ if __name__ == "__main__":
                 elastic_ip = os.environ['ssn_elastic_ip']
             except:
                 elastic_ip = 'None'
-            params = "--elastic_ip {} --ssn_id {}".format(elastic_ip, ssn_id)
+            params = "--elastic_ip {} --ssn_id {} --infra_tag_name {} --infra_tag_value {}".format(
+                elastic_ip, ssn_id, tag_name, elastic_ip_name)
             try:
                 local("~/scripts/{}.py {}".format('ssn_associate_elastic_ip', params))
             except:


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org