Skip to content

Commit 5a4aa29

Browse files
authored
Merge pull request #361 from cloudify-cosmo/CY-3046-Update-Port-Server-Relationship
Cy 3046 update port server relationship
2 parents 84cbfdb + 9148fb9 commit 5a4aa29

File tree

5 files changed

+71
-7
lines changed

5 files changed

+71
-7
lines changed

CHANGELOG.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
3.2.17: Support no networks.
12
3.2.16:
23
- Update wagon builder to py2py3 wagon.
34
- Added 5.1.0 integration tests.

openstack_plugin/resources/compute/server.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,22 @@ def _update_nics_config(server_config, client_config, allow_multiple=False):
872872
# valid only when one network created for the current tenant, the server
873873
# will attach automatically to that network
874874
if not (nics_from_node or nics_from_rels):
875+
compute_api_version = client_config.get('compute_api_version')
876+
compute_microversion = client_config.get(
877+
'compute_default_microversion')
878+
if compute_api_version:
879+
compute_api_version = float(compute_api_version)
880+
if compute_microversion:
881+
compute_microversion = float(compute_microversion)
882+
if any([compute_api_version >= 2.37, compute_microversion >= 2.37]):
883+
ctx.logger.warn(
884+
'No network was provided and no ports are connected '
885+
'at server creation time. This is only supported for compute '
886+
'API versions 2.37 and above. '
887+
'Additionally, the network key should be set to \'none\' or '
888+
'\'auto\'. The plugin default is \'none\'.')
889+
server_config['networks'] = 'none'
890+
ctx.instance.runtime_properties['networks'] = 'none'
875891
return
876892
# Try to merge them
877893
elif nics_from_node and nics_from_rels and not allow_multiple:
@@ -1486,6 +1502,8 @@ def _validate_external_volume_connection(openstack_resource):
14861502

14871503

14881504
def _validate_security_groups_on_ports(server_networks, client_config):
1505+
if not isinstance(server_networks, list):
1506+
return
14891507
for net in server_networks:
14901508
if net.get('port'):
14911509
port = OpenstackPort(client_config=client_config,

openstack_plugin/resources/network/port.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,39 @@ def detach(openstack_resource, port_id):
417417
port_id)
418418

419419

420+
@with_compat_node
421+
@with_openstack_resource(OpenstackServer)
422+
def create_server_interface(openstack_resource, port_id, **_):
423+
"""
424+
This method will create an interface on a server and perform the
425+
attachment.
426+
:param openstack_resource:
427+
:param port_id:
428+
:return:
429+
"""
430+
for interface_attachments in openstack_resource.server_interfaces():
431+
if port_id in interface_attachments:
432+
return
433+
openstack_resource.create_server_interface(port_id=port_id)
434+
435+
436+
@with_compat_node
437+
@with_openstack_resource(OpenstackServer)
438+
def delete_server_interface(openstack_resource, port_id, **_):
439+
"""
440+
This method will delete an interface on a server and perform the
441+
attachment.
442+
:param openstack_resource:
443+
:param port_id:
444+
:return:
445+
"""
446+
for interface_attachments in openstack_resource.server_interfaces():
447+
if interface_attachments.id == port_id:
448+
openstack_resource.delete_server_interface(port_id)
449+
_update_port_association(openstack_resource.client_config,
450+
port_id)
451+
452+
420453
@with_compat_node
421454
@with_openstack_resource(OpenstackPort)
422455
def attach_to_server(openstack_resource, device_id):

plugin.yaml

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

33
openstack:
44
executor: central_deployment_agent
5-
source: https://github.com/cloudify-cosmo/cloudify-openstack-plugin/archive/3.2.16.zip
5+
source: https://github.com/cloudify-cosmo/cloudify-openstack-plugin/archive/3.2.17.zip
66
package_name: cloudify-openstack-plugin
7-
package_version: '3.2.16'
7+
package_version: '3.2.17'
88

99
dsl_definitions:
1010

@@ -1715,18 +1715,30 @@ relationships:
17151715
# server is created, usually used if the server need to attached to multiple ports
17161716
cloudify.relationships.openstack.port_connected_to_server:
17171717
derived_from: cloudify.relationships.connected_to
1718+
target_interfaces:
1719+
cloudify.interfaces.relationship_lifecycle:
1720+
postconfigure:
1721+
implementation: openstack.openstack_plugin.resources.network.port.create_server_interface
1722+
inputs:
1723+
port_id:
1724+
default: { get_attribute: [ SOURCE, id ] }
1725+
unlink:
1726+
implementation: openstack.openstack_plugin.resources.network.port.delete_server_interface
1727+
inputs:
1728+
port_id:
1729+
default: { get_attribute: [ SOURCE, id ] }
17181730
source_interfaces:
17191731
cloudify.interfaces.relationship_lifecycle:
17201732
establish:
1721-
implementation: openstack.openstack_plugin.resources.network.port.attach_to_server
1733+
implementation: openstack.openstack_plugin.resources.network.port.attach
17221734
inputs:
17231735
device_id:
17241736
default: { get_attribute: [ TARGET, id ] }
17251737
unlink:
1726-
implementation: openstack.openstack_plugin.resources.network.port.detach_from_server
1738+
implementation: openstack.openstack_plugin.resources.network.port.detach
17271739
inputs:
1728-
device_id:
1729-
default: { get_attribute: [ TARGET, id ] }
1740+
port_id:
1741+
default: { get_attribute: [ SOURCE, id ] }
17301742

17311743
cloudify.relationships.openstack.port_connected_to_security_group:
17321744
derived_from: cloudify.relationships.connected_to

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-openstack-plugin',
23-
version='3.2.16',
23+
version='3.2.17',
2424
author='Cloudify',
2525
author_email='[email protected]',
2626
license='LICENSE',

0 commit comments

Comments
 (0)