Skip to content

Commit

Permalink
Merge pull request #355 from cloudify-cosmo/RD-2410-Sites
Browse files Browse the repository at this point in the history
add site assignment
  • Loading branch information
EarthmanT committed Jun 3, 2021
2 parents 5a86655 + b56ddbe commit 4849c26
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,5 @@
- Fix issue in Node Group start up.
2.9.2:
- Add back AWS Account that was overwritten.
2.10.0:
- Add site assignment to EKS cluster.
71 changes: 71 additions & 0 deletions cloudify_aws/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,74 @@


MAX_AWS_NAME = 255

LOCATIONS = {
'ap-northeast-1': {
'coordinates': '35.6828387, 139.7594549',
'town': 'Tokyo'
},
'ap-northeast-2': {
'coordinates': '37.5666791, 126.9782914',
'town': 'Seoul'
},
'ap-northeast-3': {
'coordinates': '34.6198813, 135.490357',
'town': 'Osaka'
},
'ap-south-1': {
'coordinates': '19.0759899, 72.8773928',
'town': 'Mumbai'
},
'ap-southeast-1': {
'coordinates': '1.357107, 103.8194992',
'town': 'Singapore'
},
'ap-southeast-2': {
'coordinates': '-33.8548157, 151.2164539',
'town': 'Sydney'
},
'ca-central-1': {
'coordinates': '45.4972159, -73.6103642',
'town': 'Montreal'
},
'eu-central-1': {
'coordinates': '50.1106444, 8.6820917',
'town': 'Frankfurt'
},
'eu-north-1': {
'coordinates': '59.3251172, 18.0710935',
'town': 'Stockholm'
},
'eu-west-1': {
'coordinates': '52.865196, -7.9794599',
'town': 'Ireland'
},
'eu-west-2': {
'coordinates': '51.5073219, -0.1276474',
'town': 'London'
},
'eu-west-3': {
'coordinates': '48.8566969, 2.3514616',
'town': 'Paris'
},
'sa-east-1': {
'coordinates': '-23.5506507, -46.6333824',
'town': 'Sao Paulo'
},
'us-east-1': {
'coordinates': '39.0438, -77.4874',
'town': 'Ashburn, VA'
},
'us-east-2': {
'coordinates': '40.1536742, -82.6851699',
'town': 'Johnstown, OH'
},
'us-west-1': {
'coordinates': '37.0065078, -121.5631723',
'town': 'Gilroy, CA'
},
'us-west-2': {
'coordinates': '45.839855, -119.7005834',
'town': 'Boardman, OR'
}
}
43 changes: 43 additions & 0 deletions cloudify_aws/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,46 @@ def get_deployment(deployment_id, rest_client):
return rest_client.deployments.get(deployment_id=deployment_id)
except CloudifyClientError:
return


def format_location_name(location_name):
return re.sub('\\-+', '-', re.sub('[^0-9a-zA-Z]', '-', str(location_name)))


def assign_site(deployment_id, location, location_name):
site = get_site(location_name)
if not site:
create_site(location_name, location)
elif not site.get('location'):
update_site(location_name, location)
update_deployment_site(deployment_id, location_name)


@with_rest_client
def create_site(site_name, location, rest_client):
return rest_client.sites.create(site_name, location)


@with_rest_client
def update_site(site_name, location, rest_client):
return rest_client.sites.update(site_name, location)


@with_rest_client
def get_site(site_name, rest_client):
try:
return rest_client.sites.get(site_name)
except CloudifyClientError:
return


@with_rest_client
def update_deployment_site(deployment_id, site_name, rest_client):
deployment = get_deployment(deployment_id)
if deployment.site_name == site_name:
return deployment
elif deployment.site_name:
return rest_client.deployments.set_site(
deployment_id, detach_site=True)
return rest_client.deployments.set_site(
deployment_id, site_name)
14 changes: 13 additions & 1 deletion cloudify_aws/eks/resources/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

# Local imports
from cloudify_aws.eks import EKSBase
from cloudify_aws.common import decorators, utils
from cloudify_aws.common import constants, decorators, utils
from cloudify_aws.common._compat import text_type
from cloudify_aws.ec2.resources.subnet import EC2Subnet

Expand Down Expand Up @@ -307,6 +307,18 @@ def poststart(ctx, iface, resource_config, **_):
ctx.logger.warn(
'Skipping assignment of labels due to '
'incompatible Cloudify version.')

try:
location = constants.LOCATIONS.get(region_name)
if location:
utils.assign_site(
ctx.deployment.id,
location['coordinates'],
name
)
except ClientError:
ctx.logger.warn('Skipping assignment of site due to '
'incompatible Cloudify version.')
ctx.instance.runtime_properties['resource'] = utils.JsonCleanuper(
iface.properties).to_dict()

Expand Down
4 changes: 2 additions & 2 deletions plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ plugins:

aws:
executor: central_deployment_agent
source: https://github.com/cloudify-cosmo/cloudify-aws-plugin/archive/2.9.2.zip
source: https://github.com/cloudify-cosmo/cloudify-aws-plugin/archive/2.10.0.zip
package_name: cloudify-aws-plugin
package_version: '2.9.2'
package_version: '2.10.0'

data_types:

Expand Down

0 comments on commit 4849c26

Please sign in to comment.