Skip to content

Commit

Permalink
Merge pull request #361 from cloudify-cosmo/CY-3046-Update-Port-Serve…
Browse files Browse the repository at this point in the history
…r-Relationship

Cy 3046 update port server relationship
  • Loading branch information
EarthmanT authored Jul 6, 2020
2 parents 84cbfdb + 9148fb9 commit 5a4aa29
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
3.2.17: Support no networks.
3.2.16:
- Update wagon builder to py2py3 wagon.
- Added 5.1.0 integration tests.
Expand Down
18 changes: 18 additions & 0 deletions openstack_plugin/resources/compute/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,22 @@ def _update_nics_config(server_config, client_config, allow_multiple=False):
# valid only when one network created for the current tenant, the server
# will attach automatically to that network
if not (nics_from_node or nics_from_rels):
compute_api_version = client_config.get('compute_api_version')
compute_microversion = client_config.get(
'compute_default_microversion')
if compute_api_version:
compute_api_version = float(compute_api_version)
if compute_microversion:
compute_microversion = float(compute_microversion)
if any([compute_api_version >= 2.37, compute_microversion >= 2.37]):
ctx.logger.warn(
'No network was provided and no ports are connected '
'at server creation time. This is only supported for compute '
'API versions 2.37 and above. '
'Additionally, the network key should be set to \'none\' or '
'\'auto\'. The plugin default is \'none\'.')
server_config['networks'] = 'none'
ctx.instance.runtime_properties['networks'] = 'none'
return
# Try to merge them
elif nics_from_node and nics_from_rels and not allow_multiple:
Expand Down Expand Up @@ -1486,6 +1502,8 @@ def _validate_external_volume_connection(openstack_resource):


def _validate_security_groups_on_ports(server_networks, client_config):
if not isinstance(server_networks, list):
return
for net in server_networks:
if net.get('port'):
port = OpenstackPort(client_config=client_config,
Expand Down
33 changes: 33 additions & 0 deletions openstack_plugin/resources/network/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,39 @@ def detach(openstack_resource, port_id):
port_id)


@with_compat_node
@with_openstack_resource(OpenstackServer)
def create_server_interface(openstack_resource, port_id, **_):
"""
This method will create an interface on a server and perform the
attachment.
:param openstack_resource:
:param port_id:
:return:
"""
for interface_attachments in openstack_resource.server_interfaces():
if port_id in interface_attachments:
return
openstack_resource.create_server_interface(port_id=port_id)


@with_compat_node
@with_openstack_resource(OpenstackServer)
def delete_server_interface(openstack_resource, port_id, **_):
"""
This method will delete an interface on a server and perform the
attachment.
:param openstack_resource:
:param port_id:
:return:
"""
for interface_attachments in openstack_resource.server_interfaces():
if interface_attachments.id == port_id:
openstack_resource.delete_server_interface(port_id)
_update_port_association(openstack_resource.client_config,
port_id)


@with_compat_node
@with_openstack_resource(OpenstackPort)
def attach_to_server(openstack_resource, device_id):
Expand Down
24 changes: 18 additions & 6 deletions plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ plugins:

openstack:
executor: central_deployment_agent
source: https://github.com/cloudify-cosmo/cloudify-openstack-plugin/archive/3.2.16.zip
source: https://github.com/cloudify-cosmo/cloudify-openstack-plugin/archive/3.2.17.zip
package_name: cloudify-openstack-plugin
package_version: '3.2.16'
package_version: '3.2.17'

dsl_definitions:

Expand Down Expand Up @@ -1715,18 +1715,30 @@ relationships:
# server is created, usually used if the server need to attached to multiple ports
cloudify.relationships.openstack.port_connected_to_server:
derived_from: cloudify.relationships.connected_to
target_interfaces:
cloudify.interfaces.relationship_lifecycle:
postconfigure:
implementation: openstack.openstack_plugin.resources.network.port.create_server_interface
inputs:
port_id:
default: { get_attribute: [ SOURCE, id ] }
unlink:
implementation: openstack.openstack_plugin.resources.network.port.delete_server_interface
inputs:
port_id:
default: { get_attribute: [ SOURCE, id ] }
source_interfaces:
cloudify.interfaces.relationship_lifecycle:
establish:
implementation: openstack.openstack_plugin.resources.network.port.attach_to_server
implementation: openstack.openstack_plugin.resources.network.port.attach
inputs:
device_id:
default: { get_attribute: [ TARGET, id ] }
unlink:
implementation: openstack.openstack_plugin.resources.network.port.detach_from_server
implementation: openstack.openstack_plugin.resources.network.port.detach
inputs:
device_id:
default: { get_attribute: [ TARGET, id ] }
port_id:
default: { get_attribute: [ SOURCE, id ] }

cloudify.relationships.openstack.port_connected_to_security_group:
derived_from: cloudify.relationships.connected_to
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-openstack-plugin',
version='3.2.16',
version='3.2.17',
author='Cloudify',
author_email='[email protected]',
license='LICENSE',
Expand Down

0 comments on commit 5a4aa29

Please sign in to comment.