Skip to content
This repository has been archived by the owner on Jan 2, 2019. It is now read-only.

bump version #162

Merged
merged 2 commits into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.6.0:
- Add Modify VPC Attribute
- Add Modify Subnet Attribute
- Add these runtime properties to instances: ipv4_address, ipv4_addresses, ipv6_address, ipv6_addresses.
2.5.0:
- New behavior for external resources in relationships.
- New + External = Perform Op (Current Behavior)
Expand Down
57 changes: 48 additions & 9 deletions cloudify_awssdk/ec2/resources/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,20 +263,59 @@ def create(ctx, iface, resource_config, **_):
modify_instance_attribute_args)


def assign_ip_properties(_ctx, current_properties):

nics = current_properties.get('NetworkInterfaces', [])
ipv4_addresses = \
_ctx.instance.runtime_properties.get('ipv4_addresses', [])
ipv6_addresses = \
_ctx.instance.runtime_properties.get('ipv6_addresses', [])

for nic in nics:
nic_ipv4 = nic.get('PrivateIpAddresses', [])
for _nic_ipv4 in nic_ipv4:
_private_ip = _nic_ipv4.get('PrivateIpAddress')
if _nic_ipv4.get('Primary', False):
_ctx.instance.runtime_properties['ipv4_address'] = _private_ip
_ctx.instance.runtime_properties['private_ip_address'] = \
_private_ip
if _private_ip not in ipv4_addresses:
ipv4_addresses.append(_private_ip)
nic_ipv6 = nic.get('Ipv6Addresses', [])
for _nic_ipv6 in nic_ipv6:
if _nic_ipv6 not in ipv6_addresses:
ipv6_addresses.append(_nic_ipv6)

_ctx.instance.runtime_properties['ipv4_addresses'] = ipv4_addresses
_ctx.instance.runtime_properties['ipv6_addresses'] = ipv6_addresses

if len(ipv4_addresses) > 0 and \
not _ctx.instance.runtime_properties.get('ipv4_address'):
_ctx.instance.runtime_properties['ipv4_address'] = ipv4_addresses[0]

if len(ipv6_addresses) > 0 and \
not _ctx.instance.runtime_properties.get('ipv6_address'):
_ctx.instance.runtime_properties['ipv6_address'] = ipv6_addresses[0]

pip = current_properties.get('PublicIpAddress')
ip = current_properties.get('PrivateIpAddress')

if ctx.node.properties['use_public_ip']:
_ctx.instance.runtime_properties['ip'] = pip
_ctx.instance.runtime_properties['public_ip_address'] = pip
else:
_ctx.instance.runtime_properties['ip'] = ip
_ctx.instance.runtime_properties['public_ip_address'] = pip

_ctx.instance.runtime_properties['private_ip_address'] = ip


@decorators.aws_resource(EC2Instances, RESOURCE_TYPE)
def start(ctx, iface, resource_config, **_):
'''Starts AWS EC2 Instances'''

if iface.status in [RUNNING] and ctx.operation.retry_number > 0:
current_properties = iface.properties
ip = current_properties.get('PrivateIpAddress')
pip = current_properties.get('PublicIpAddress')
if ctx.node.properties['use_public_ip']:
ctx.instance.runtime_properties['ip'] = pip
else:
ctx.instance.runtime_properties['ip'] = ip
ctx.instance.runtime_properties['public_ip_address'] = pip
ctx.instance.runtime_properties['private_ip_address'] = ip
assign_ip_properties(ctx, iface.properties)
if not _handle_password(iface):
raise OperationRetry(
'Waiting for {0} ID# {1} password.'.format(
Expand Down
30 changes: 30 additions & 0 deletions cloudify_awssdk/ec2/resources/subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ def delete(self, params=None):
self.logger.debug('Response: %s' % res)
return res

def modify_instance_attribute(self, params=None):
'''
Modifies an existing AWS EC2 Subnet Attribute.
'''
self.logger.debug(
'Modifying {0} attribute with parameters: {1}'.format(
self.type_name, params))
res = self.client.modify_instance_attribute(**params)
self.logger.debug('Response: %s' % res)
return res


@decorators.aws_resource(EC2Subnet, resource_type=RESOURCE_TYPE)
def prepare(ctx, iface, resource_config, **_):
Expand Down Expand Up @@ -130,6 +141,14 @@ def create(ctx, iface, resource_config, **_):
iface.update_resource_id(subnet_id)
utils.update_resource_id(ctx.instance, subnet_id)

modify_subnet_attribute_args = \
_.get('modify_subnet_attribute_args')
EarthmanT marked this conversation as resolved.
Show resolved Hide resolved
if modify_subnet_attribute_args:
modify_subnet_attribute_args[SUBNET_ID] = \
subnet_id
iface.modify_subnet_attribute(
modify_subnet_attribute_args)


@decorators.aws_resource(EC2Subnet, RESOURCE_TYPE,
ignore_properties=True)
Expand All @@ -145,3 +164,14 @@ def delete(ctx, iface, resource_config, **_):
ctx.instance.runtime_properties.get(EXTERNAL_RESOURCE_ID)

iface.delete(params)


@decorators.aws_resource(EC2Subnet, RESOURCE_TYPE)
def modify_subnet_attribute(ctx, iface, resource_config, **_):
params = \
dict() if not resource_config else resource_config.copy()
instance_id = \
ctx.instance.runtime_properties.get(
SUBNET_ID, iface.resource_id)
params[SUBNET_ID] = instance_id
iface.modify_subnet_attribute(params)
30 changes: 30 additions & 0 deletions cloudify_awssdk/ec2/resources/vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ def delete(self, params=None):
self.logger.debug('Response: %s' % res)
return res

def modify_vpc_attribute(self, params):
'''
Modify attribute of AWS EC2 VPC.
'''
self.logger.debug(
'Modifying {0} attribute with parameters: {1}'.format(
self.type_name, params))
res = self.client.modify_vpc_attribute(**params)
self.logger.debug('Response: {0}'.format(res))
return res


@decorators.aws_resource(EC2Vpc, resource_type=RESOURCE_TYPE)
def prepare(ctx, iface, resource_config, **_):
Expand All @@ -102,6 +113,14 @@ def create(ctx, iface, resource_config, **_):
utils.update_resource_id(
ctx.instance, vpc_id)

modify_vpc_attribute_args = \
_.get('modify_vpc_attribute_args')
if modify_vpc_attribute_args:
EarthmanT marked this conversation as resolved.
Show resolved Hide resolved
modify_vpc_attribute_args[VPC_ID] = \
vpc_id
iface.modify_vpc_attribute(
modify_vpc_attribute_args)


@decorators.aws_resource(EC2Vpc, RESOURCE_TYPE,
ignore_properties=True)
Expand All @@ -115,3 +134,14 @@ def delete(iface, resource_config, **_):
params.update({VPC_ID: iface.resource_id})

iface.delete(params)


@decorators.aws_resource(EC2Vpc, RESOURCE_TYPE)
def modify_vpc_attribute(ctx, iface, resource_config, **_):
params = \
dict() if not resource_config else resource_config.copy()
instance_id = \
ctx.instance.runtime_properties.get(
VPC_ID, iface.resource_id)
params[VPC_ID] = instance_id
iface.modify_vpc_attribute(params)
13 changes: 13 additions & 0 deletions cloudify_awssdk/ec2/tests/test_subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
SUBNET_ID, VPC_ID, VPC_TYPE)
from mock import patch, MagicMock
from cloudify_awssdk.ec2.resources import subnet
from cloudify.exceptions import OperationRetry


class TestEC2Subnet(TestBase):
Expand Down Expand Up @@ -121,6 +122,18 @@ def test_delete(self):
subnet.delete(ctx, iface, {})
self.assertTrue(iface.delete.called)

def test_modify_subnet_attribute(self):
ctx = self.get_mock_ctx("Subnet")
iface = MagicMock()
iface.status = 0
self.subnet.resource_id = 'test_name'
try:
subnet.modify_subnet_attribute(
ctx, iface, {SUBNET_ID: self.subnet.resource_id})
except OperationRetry:
pass
self.assertTrue(iface.modify_subnet_attribute.called)


if __name__ == '__main__':
unittest.main()
13 changes: 13 additions & 0 deletions cloudify_awssdk/ec2/tests/test_vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from cloudify_awssdk.ec2.resources.vpc import EC2Vpc, VPC, CIDR_BLOCK, VPC_ID
from mock import patch, MagicMock
from cloudify_awssdk.ec2.resources import vpc
from cloudify.exceptions import OperationRetry


class TestEC2Vpc(TestBase):
Expand Down Expand Up @@ -106,6 +107,18 @@ def test_delete(self):
vpc.delete(iface, {})
self.assertTrue(iface.delete.called)

def test_modify_vpc_attribute(self):
ctx = self.get_mock_ctx("Vpc")
iface = MagicMock()
iface.status = 0
self.vpc.resource_id = 'test_name'
try:
vpc.modify_vpc_attribute(
ctx, iface, {VPC_ID: self.vpc.resource_id})
except OperationRetry:
pass
self.assertTrue(iface.modify_vpc_attribute.called)


if __name__ == '__main__':
unittest.main()
14 changes: 14 additions & 0 deletions examples/ec2-instance-feature-demo/blueprint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ node_templates:
kwargs:
CidrBlock: { get_input: vpc_cidr }
client_config: *client_config
interfaces:
cloudify.interfaces.lifecycle:
configure:
implementation: awssdk.cloudify_awssdk.ec2.resources.vpc.create
inputs:
modify_vpc_attribute_args:
EnableDnsHostnames: true

internet_gateway:
type: cloudify.nodes.aws.ec2.InternetGateway
Expand All @@ -73,6 +80,13 @@ node_templates:
target: vpc
- type: cloudify.relationships.depends_on
target: internet_gateway
interfaces:
cloudify.interfaces.lifecycle:
configure:
implementation: awssdk.cloudify_awssdk.ec2.resources.subnet.create
inputs:
modify_subnet_attribute_args:
AssignIpv6AddressOnCreation: true

private_subnet:
type: cloudify.nodes.aws.ec2.Subnet
Expand Down
10 changes: 8 additions & 2 deletions plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ plugins:

awssdk:
executor: central_deployment_agent
source: https://github.com/cloudify-incubator/cloudify-awssdk-plugin/archive/2.5.0.zip
source: https://github.com/cloudify-incubator/cloudify-awssdk-plugin/archive/2.6.0.zip
package_name: cloudify-awssdk-plugin
package_version: '2.5.0'
package_version: '2.6.0'

data_types:

Expand Down Expand Up @@ -1636,6 +1636,9 @@ node_types:
delete:
implementation: awssdk.cloudify_awssdk.ec2.resources.vpc.delete
inputs: *operation_inputs
modify_vpc_attribute:
implementation: awssdk.cloudify_awssdk.ec2.resources.vpc.modify_vpc_attribute
inputs: *operation_inputs

cloudify.nodes.aws.ec2.VpcPeering:
derived_from: cloudify.nodes.Root
Expand Down Expand Up @@ -1722,6 +1725,9 @@ node_types:
delete:
implementation: awssdk.cloudify_awssdk.ec2.resources.subnet.delete
inputs: *operation_inputs
modify_subnet_attribute:
implementation: awssdk.cloudify_awssdk.ec2.resources.subnet.modify_subnet_attribute
inputs: *operation_inputs

cloudify.nodes.aws.ec2.SecurityGroup:
derived_from: cloudify.nodes.Root
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

setup(
name='cloudify-awssdk-plugin',
version='2.5.0',
version='2.6.0',
license='LICENSE',
packages=find_packages(exclude=['tests*']),
description='A Cloudify plugin for AWS',
Expand Down