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

Commit ed683d6

Browse files
authored
bump version (#162)
* bump version add ip runtime properties add modify vpc/subnet attribute * Modify VPC/Subnet Attribute, example, log message, interface
1 parent 276f41b commit ed683d6

File tree

9 files changed

+161
-12
lines changed

9 files changed

+161
-12
lines changed

CHANGELOG.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.6.0:
2+
- Add Modify VPC Attribute
3+
- Add Modify Subnet Attribute
4+
- Add these runtime properties to instances: ipv4_address, ipv4_addresses, ipv6_address, ipv6_addresses.
15
2.5.0:
26
- New behavior for external resources in relationships.
37
- New + External = Perform Op (Current Behavior)

cloudify_awssdk/ec2/resources/instances.py

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,59 @@ def create(ctx, iface, resource_config, **_):
263263
modify_instance_attribute_args)
264264

265265

266+
def assign_ip_properties(_ctx, current_properties):
267+
268+
nics = current_properties.get('NetworkInterfaces', [])
269+
ipv4_addresses = \
270+
_ctx.instance.runtime_properties.get('ipv4_addresses', [])
271+
ipv6_addresses = \
272+
_ctx.instance.runtime_properties.get('ipv6_addresses', [])
273+
274+
for nic in nics:
275+
nic_ipv4 = nic.get('PrivateIpAddresses', [])
276+
for _nic_ipv4 in nic_ipv4:
277+
_private_ip = _nic_ipv4.get('PrivateIpAddress')
278+
if _nic_ipv4.get('Primary', False):
279+
_ctx.instance.runtime_properties['ipv4_address'] = _private_ip
280+
_ctx.instance.runtime_properties['private_ip_address'] = \
281+
_private_ip
282+
if _private_ip not in ipv4_addresses:
283+
ipv4_addresses.append(_private_ip)
284+
nic_ipv6 = nic.get('Ipv6Addresses', [])
285+
for _nic_ipv6 in nic_ipv6:
286+
if _nic_ipv6 not in ipv6_addresses:
287+
ipv6_addresses.append(_nic_ipv6)
288+
289+
_ctx.instance.runtime_properties['ipv4_addresses'] = ipv4_addresses
290+
_ctx.instance.runtime_properties['ipv6_addresses'] = ipv6_addresses
291+
292+
if len(ipv4_addresses) > 0 and \
293+
not _ctx.instance.runtime_properties.get('ipv4_address'):
294+
_ctx.instance.runtime_properties['ipv4_address'] = ipv4_addresses[0]
295+
296+
if len(ipv6_addresses) > 0 and \
297+
not _ctx.instance.runtime_properties.get('ipv6_address'):
298+
_ctx.instance.runtime_properties['ipv6_address'] = ipv6_addresses[0]
299+
300+
pip = current_properties.get('PublicIpAddress')
301+
ip = current_properties.get('PrivateIpAddress')
302+
303+
if ctx.node.properties['use_public_ip']:
304+
_ctx.instance.runtime_properties['ip'] = pip
305+
_ctx.instance.runtime_properties['public_ip_address'] = pip
306+
else:
307+
_ctx.instance.runtime_properties['ip'] = ip
308+
_ctx.instance.runtime_properties['public_ip_address'] = pip
309+
310+
_ctx.instance.runtime_properties['private_ip_address'] = ip
311+
312+
266313
@decorators.aws_resource(EC2Instances, RESOURCE_TYPE)
267314
def start(ctx, iface, resource_config, **_):
268315
'''Starts AWS EC2 Instances'''
269316

270317
if iface.status in [RUNNING] and ctx.operation.retry_number > 0:
271-
current_properties = iface.properties
272-
ip = current_properties.get('PrivateIpAddress')
273-
pip = current_properties.get('PublicIpAddress')
274-
if ctx.node.properties['use_public_ip']:
275-
ctx.instance.runtime_properties['ip'] = pip
276-
else:
277-
ctx.instance.runtime_properties['ip'] = ip
278-
ctx.instance.runtime_properties['public_ip_address'] = pip
279-
ctx.instance.runtime_properties['private_ip_address'] = ip
318+
assign_ip_properties(ctx, iface.properties)
280319
if not _handle_password(iface):
281320
raise OperationRetry(
282321
'Waiting for {0} ID# {1} password.'.format(

cloudify_awssdk/ec2/resources/subnet.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ def delete(self, params=None):
8181
self.logger.debug('Response: %s' % res)
8282
return res
8383

84+
def modify_instance_attribute(self, params=None):
85+
'''
86+
Modifies an existing AWS EC2 Subnet Attribute.
87+
'''
88+
self.logger.debug(
89+
'Modifying {0} attribute with parameters: {1}'.format(
90+
self.type_name, params))
91+
res = self.client.modify_instance_attribute(**params)
92+
self.logger.debug('Response: %s' % res)
93+
return res
94+
8495

8596
@decorators.aws_resource(EC2Subnet, resource_type=RESOURCE_TYPE)
8697
def prepare(ctx, iface, resource_config, **_):
@@ -130,6 +141,14 @@ def create(ctx, iface, resource_config, **_):
130141
iface.update_resource_id(subnet_id)
131142
utils.update_resource_id(ctx.instance, subnet_id)
132143

144+
modify_subnet_attribute_args = \
145+
_.get('modify_subnet_attribute_args')
146+
if modify_subnet_attribute_args:
147+
modify_subnet_attribute_args[SUBNET_ID] = \
148+
subnet_id
149+
iface.modify_subnet_attribute(
150+
modify_subnet_attribute_args)
151+
133152

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

147166
iface.delete(params)
167+
168+
169+
@decorators.aws_resource(EC2Subnet, RESOURCE_TYPE)
170+
def modify_subnet_attribute(ctx, iface, resource_config, **_):
171+
params = \
172+
dict() if not resource_config else resource_config.copy()
173+
instance_id = \
174+
ctx.instance.runtime_properties.get(
175+
SUBNET_ID, iface.resource_id)
176+
params[SUBNET_ID] = instance_id
177+
iface.modify_subnet_attribute(params)

cloudify_awssdk/ec2/resources/vpc.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ def delete(self, params=None):
7777
self.logger.debug('Response: %s' % res)
7878
return res
7979

80+
def modify_vpc_attribute(self, params):
81+
'''
82+
Modify attribute of AWS EC2 VPC.
83+
'''
84+
self.logger.debug(
85+
'Modifying {0} attribute with parameters: {1}'.format(
86+
self.type_name, params))
87+
res = self.client.modify_vpc_attribute(**params)
88+
self.logger.debug('Response: {0}'.format(res))
89+
return res
90+
8091

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

116+
modify_vpc_attribute_args = \
117+
_.get('modify_vpc_attribute_args')
118+
if modify_vpc_attribute_args:
119+
modify_vpc_attribute_args[VPC_ID] = \
120+
vpc_id
121+
iface.modify_vpc_attribute(
122+
modify_vpc_attribute_args)
123+
105124

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

117136
iface.delete(params)
137+
138+
139+
@decorators.aws_resource(EC2Vpc, RESOURCE_TYPE)
140+
def modify_vpc_attribute(ctx, iface, resource_config, **_):
141+
params = \
142+
dict() if not resource_config else resource_config.copy()
143+
instance_id = \
144+
ctx.instance.runtime_properties.get(
145+
VPC_ID, iface.resource_id)
146+
params[VPC_ID] = instance_id
147+
iface.modify_vpc_attribute(params)

cloudify_awssdk/ec2/tests/test_subnet.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
SUBNET_ID, VPC_ID, VPC_TYPE)
2020
from mock import patch, MagicMock
2121
from cloudify_awssdk.ec2.resources import subnet
22+
from cloudify.exceptions import OperationRetry
2223

2324

2425
class TestEC2Subnet(TestBase):
@@ -121,6 +122,18 @@ def test_delete(self):
121122
subnet.delete(ctx, iface, {})
122123
self.assertTrue(iface.delete.called)
123124

125+
def test_modify_subnet_attribute(self):
126+
ctx = self.get_mock_ctx("Subnet")
127+
iface = MagicMock()
128+
iface.status = 0
129+
self.subnet.resource_id = 'test_name'
130+
try:
131+
subnet.modify_subnet_attribute(
132+
ctx, iface, {SUBNET_ID: self.subnet.resource_id})
133+
except OperationRetry:
134+
pass
135+
self.assertTrue(iface.modify_subnet_attribute.called)
136+
124137

125138
if __name__ == '__main__':
126139
unittest.main()

cloudify_awssdk/ec2/tests/test_vpc.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from cloudify_awssdk.ec2.resources.vpc import EC2Vpc, VPC, CIDR_BLOCK, VPC_ID
1818
from mock import patch, MagicMock
1919
from cloudify_awssdk.ec2.resources import vpc
20+
from cloudify.exceptions import OperationRetry
2021

2122

2223
class TestEC2Vpc(TestBase):
@@ -106,6 +107,18 @@ def test_delete(self):
106107
vpc.delete(iface, {})
107108
self.assertTrue(iface.delete.called)
108109

110+
def test_modify_vpc_attribute(self):
111+
ctx = self.get_mock_ctx("Vpc")
112+
iface = MagicMock()
113+
iface.status = 0
114+
self.vpc.resource_id = 'test_name'
115+
try:
116+
vpc.modify_vpc_attribute(
117+
ctx, iface, {VPC_ID: self.vpc.resource_id})
118+
except OperationRetry:
119+
pass
120+
self.assertTrue(iface.modify_vpc_attribute.called)
121+
109122

110123
if __name__ == '__main__':
111124
unittest.main()

examples/ec2-instance-feature-demo/blueprint.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ node_templates:
5151
kwargs:
5252
CidrBlock: { get_input: vpc_cidr }
5353
client_config: *client_config
54+
interfaces:
55+
cloudify.interfaces.lifecycle:
56+
configure:
57+
implementation: awssdk.cloudify_awssdk.ec2.resources.vpc.create
58+
inputs:
59+
modify_vpc_attribute_args:
60+
EnableDnsHostnames: true
5461

5562
internet_gateway:
5663
type: cloudify.nodes.aws.ec2.InternetGateway
@@ -73,6 +80,13 @@ node_templates:
7380
target: vpc
7481
- type: cloudify.relationships.depends_on
7582
target: internet_gateway
83+
interfaces:
84+
cloudify.interfaces.lifecycle:
85+
configure:
86+
implementation: awssdk.cloudify_awssdk.ec2.resources.subnet.create
87+
inputs:
88+
modify_subnet_attribute_args:
89+
AssignIpv6AddressOnCreation: true
7690

7791
private_subnet:
7892
type: cloudify.nodes.aws.ec2.Subnet

plugin.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ plugins:
22

33
awssdk:
44
executor: central_deployment_agent
5-
source: https://github.com/cloudify-incubator/cloudify-awssdk-plugin/archive/2.5.0.zip
5+
source: https://github.com/cloudify-incubator/cloudify-awssdk-plugin/archive/2.6.0.zip
66
package_name: cloudify-awssdk-plugin
7-
package_version: '2.5.0'
7+
package_version: '2.6.0'
88

99
data_types:
1010

@@ -1636,6 +1636,9 @@ node_types:
16361636
delete:
16371637
implementation: awssdk.cloudify_awssdk.ec2.resources.vpc.delete
16381638
inputs: *operation_inputs
1639+
modify_vpc_attribute:
1640+
implementation: awssdk.cloudify_awssdk.ec2.resources.vpc.modify_vpc_attribute
1641+
inputs: *operation_inputs
16391642

16401643
cloudify.nodes.aws.ec2.VpcPeering:
16411644
derived_from: cloudify.nodes.Root
@@ -1722,6 +1725,9 @@ node_types:
17221725
delete:
17231726
implementation: awssdk.cloudify_awssdk.ec2.resources.subnet.delete
17241727
inputs: *operation_inputs
1728+
modify_subnet_attribute:
1729+
implementation: awssdk.cloudify_awssdk.ec2.resources.subnet.modify_subnet_attribute
1730+
inputs: *operation_inputs
17251731

17261732
cloudify.nodes.aws.ec2.SecurityGroup:
17271733
derived_from: cloudify.nodes.Root

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
setup(
2222
name='cloudify-awssdk-plugin',
23-
version='2.5.0',
23+
version='2.6.0',
2424
license='LICENSE',
2525
packages=find_packages(exclude=['tests*']),
2626
description='A Cloudify plugin for AWS',

0 commit comments

Comments
 (0)