Skip to content

Commit

Permalink
CZ-96 Add support for tier1 node type (#5)
Browse files Browse the repository at this point in the history
* CZ-96 Add support for tier1 node type

* CZ-96 Update tier1 node

* CZ-96 Update plugin yaml file

* CZ-96 Update handling state for tier1 resource

* CZ-96 Update handling state for tier1 resource

* CZ-96 Add extra state for check if tier1 resource is ready or not

* CZ-96 Update state handling for tier1

* CZ-96 Update readme file
  • Loading branch information
mabuaisha authored Aug 23, 2020
1 parent 41d2ad2 commit ab0f907
Show file tree
Hide file tree
Showing 11 changed files with 478 additions and 91 deletions.
59 changes: 57 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ The plugin provides the following features for interacting with NSX-T API:
2. DHCP Server Config:
- Create DHCP Server Config
- Delete DHCP Server Config

3. Tier1 Gateway:
- Create Tier1 Gateway
- Delete Tier1 Gateway

## Authentication with NSX-T

Expand Down Expand Up @@ -65,6 +69,7 @@ This node type refers to a DHCP Server Config.

* `id`: _String_. _Required_. This is the ID of the DHCP Server Config
* `display_name`: _String_. _Not required_. The name of DHCP Server Config. if not provided, it will take the same ID value.
* `description`: _String_. _Not required_. The resource description.
* `edge_cluster_path`: _String_. Edge cluster path
* `lease_time`: _Integer_. IP address lease time in seconds.
* `server_addresses`: _List_: DHCP server address in CIDR format. Both IPv4 and IPv6 address families are supported.
Expand Down Expand Up @@ -100,6 +105,7 @@ This node type refers to a Segment.

* `id`: _String_. _Required_. This is the ID of the Segment
* `display_name`: _String_. _Not required_. The name of Segment. if not provided, it will take the same ID value.
* `description`: _String_. _Not required_. The Segment description.
* `subnet`: _Dict_: Segment Subnet Configuration. The following keys are part of `subnet`:
- `ip_v4_config`: _Dict_: IP V4 Configuration.
- `dhcp_config`: _Dict_: The DHCP Configuration
Expand Down Expand Up @@ -186,6 +192,55 @@ This node type refers to a Segment.
target: dhcb_server_config
```

### **cloudify.nodes.nsx-t.Tier1**

This node type refers to a Tier1 Gateway.

**Resource Config**

* `id`: _String_. _Required_. This is the ID of the Tier1 Gateway
* `display_name`: _String_. _Not required_. The name of Tier1 Gateway. if not provided, it will take the same ID value.
* `tier0_path`: _String_. _Not required_. Specify Tier-1 connectivity to Tier-0 instance.
* `type`: _String_. Tier1 connectivity type for reference.
* `dhcp_config_paths`: _List_. DHCP configuration for Segments connected to Tier-1
* `disable_firewall`: _Boolean_: Disable or enable gateway firewall. Default False
* `enable_standby_relocation`: _Boolean_: Flag to enable standby service router relocation.
* `failover_mode`: _String_: Determines the behavior when a Tier-1 instance restarts after a failure. Default NON_PREEMPTIVE
* `intersite_config`: _Dict_: Inter site routing configuration when the gateway is streched.
* `fallback_sites`: _List_: Fallback site to be used as new primary site on current primary site failure.
* `intersite_transit_subnet`: _String_: IPv4 subnet for inter-site transit segment connecting service routers across sites for stretched gateway. Default `169.254.32.0/20`
* `last_admin_active_epoch`: _Integer_: Epoch(in seconds) is auto updated based on system current timestamp when primary locale service is updated
* `primary_site_path`: _String_: Primary egress site for gateway.
* `ipv6_profile_paths`: _List_: Configuration IPv6 NDRA and DAD profiles . Either or both NDRA and/or DAD profiles can be configured.
* `pool_allocation`: _String_: Supports edge node allocation at different sizes for routing and load balancer service to meet performance and scalability requirements. Default ROUTING
* `qos_profile`: _Dict_: QoS Profile configuration for Tier1 router link connected to Tier0 gateway.
* `egress_qos_profile_path`: _String_: Policy path to gateway QoS profile in egress direction.
* `ingress_qos_profile_path`: _String_: Policy path to gateway QoS profile in ingress direction.
* `route_advertisement_rules`: _List_: Route advertisement rules and filtering.
* `route_advertisement_types`: _List_: Enable different types of route advertisements.
* `children`: _List_: subtree for this type within policy tree containing nested elements.
* `tags`: _List_: Opaque identifiers meaningful to the API user


### Tier1 Example

```yaml
tier1:
type: cloudify.nodes.nsx-t.Tier1
properties:
client_config:
host: { get_input: host }
port: { get_input: port }
username: { get_input: username }
password: { get_input: password }
resource_config:
id: test_tier1
display_name: Test Tier1 Router
description: Test Tier1 Router
tier0_path:{ get_input: tier0_path }
```

Note: The configuration for the above resources are based on the NSX-T API documentation:
1. https://vdc-download.vmware.com/vmwb-repository/dcr-public/9e1c6bcc-85db-46b6-bc38-d6d2431e7c17/30af91b5-3a91-4d5d-8ed5-a7d806764a16/api_includes/method_CreateOrReplaceInfraSegment.html
2. https://vdc-download.vmware.com/vmwb-repository/dcr-public/9e1c6bcc-85db-46b6-bc38-d6d2431e7c17/30af91b5-3a91-4d5d-8ed5-a7d806764a16/api_includes/method_CreateOrReplaceDhcpServerConfig.html
1. https://vdc-download.vmware.com/vmwb-repository/dcr-public/9e1c6bcc-85db-46b6-bc38-d6d2431e7c17/30af91b5-3a91-4d5d-8ed5-a7d806764a16/api_includes/policy_networking_connectivity_segment.html
2. https://vdc-download.vmware.com/vmwb-repository/dcr-public/9e1c6bcc-85db-46b6-bc38-d6d2431e7c17/30af91b5-3a91-4d5d-8ed5-a7d806764a16/api_includes/policy_networking_ip_management_dhcp_dhcp_server_configs.html
3. https://vdc-download.vmware.com/vmwb-repository/dcr-public/9e1c6bcc-85db-46b6-bc38-d6d2431e7c17/30af91b5-3a91-4d5d-8ed5-a7d806764a16/api_includes/policy_networking_connectivity_tier-1_gateways_tier-1_gateways.html
15 changes: 12 additions & 3 deletions examples/blueprint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ inputs:
password:
type: string

tier1_gateway_id:
type: string
tier1_config:
type: dict

dhcp_server_config:
type: dict
Expand Down Expand Up @@ -68,12 +68,21 @@ dsl_definitions:
allow_insecure: true

node_templates:
tier1:
type: cloudify.nodes.nsx-t.Tier1
properties:
client_config: *client_config
resource_config: { get_input: tier1_config }

dhcb_server_config:
type: cloudify.nodes.nsx-t.DhcpServerConfig
properties:
client_config: *client_config
tier1_gateway_id: { get_input: tier1_gateway_id }
tier1_gateway_id: { get_attribute: [ tier1, id ] }
resource_config: { get_input: dhcp_server_config }
relationships:
- type: cloudify.relationships.depends_on
target: tier1

segment:
type: cloudify.nodes.nsx-t.Segment
Expand Down
26 changes: 15 additions & 11 deletions examples/inputs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@ port: -YOUR_PORT-
username: -YOUR_USERNAME-
password: -YOUR_PASSWORD-

tier1_gateway_id: test-tier1
tier1_config:
id: mo_tier1
display_name: MO Tier1 Router
description: MO Tier1 Router
tier0_path: /infra/tier-0s/tier0

dhcp_server_config:
id: test_dhcp_server
display_name: Test DHCP Server
description: Test DHCP Server Config
edge_cluster_path: /infra/sites/default/enforcement-points/default/edge-clusters/b004f47e-f18d-42b3-a226-ed33e534ebe0
id: mo_dhcp_server
display_name: MO DHCP Server
description: MO DHCP Server Config
edge_cluster_path: /infra/sites/default/enforcement-points/default/edge-clusters/272cfe43-ebcc-49bb-8471-62a261ed8931
tags:
- scope: Name
tag: Test DHCP
tag: MO DHCP

segment_config:
id: test_segment
display_name: Test Segment
description: Test Segment Config
id: mo_segment
display_name: MO Segment
description: MO Segment Config
transport_zone_path: /infra/sites/default/enforcement-points/default/transport-zones/1b3a2f36-bfd1-443e-a0f6-4de01abc963e
connectivity_path: /infra/tier-1s/test-tier1
dhcp_config_path: /infra/dhcp-server-configs/test_dhcp_server
connectivity_path: { get_attribute: [ tier1, path ] }
dhcp_config_path: { get_attribute: [ dhcb_server_config, path ] }
subnet:
ip_v4_config:
dhcp_config:
Expand Down
37 changes: 37 additions & 0 deletions nsx_t_plugin/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
########
# Copyright (c) 2020 Cloudify Technologies Ltd. All rights reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.

# STATE VALUES
STATE_PENDING = 'pending'
STATE_IN_PROGRESS = 'in_progress'
STATE_IN_SYNC = 'in_sync'
STATE_SUCCESS = 'success'

# SEGMENTS
TASK_DELETE = 'delete_task'

# OPERATIONS
DELETE_OPERATION = 'cloudify.interfaces.lifecycle.delete'
CREATE_OPERATION = 'cloudify.interfaces.lifecycle.create'

# RUNTIME PROPERTIES
BASIC_RUNTIME_PROPERTIES = (
'id',
'resource_type'
)
NSXT_ID_PROPERTY = 'id'
NSXT_NAME_PROPERTY = 'name'
NSXT_TYPE_PROPERTY = 'type'
NSXT_RESOURCE_CONFIG_PROPERTY = 'resource_config'
67 changes: 16 additions & 51 deletions nsx_t_plugin/segment/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@
# * limitations under the License.

from cloudify import ctx
from cloudify.exceptions import OperationRetry, NonRecoverableError

from nsx_t_plugin.decorators import with_nsx_t_client
from nsx_t_plugin.constants import (
STATE_IN_PROGRESS,
STATE_SUCCESS,
STATE_PENDING,
)
from nsx_t_plugin.utils import (
validate_if_resource_started,
validate_if_resource_deleted
)
from nsx_t_sdk.resources import (
Segment,
SegmentState,
SegmentPort
)
from nsx_t_sdk.exceptions import NSXTSDKException

SEGMENT_TASK_DELETE = 'segment_delete_task'
SEGMENT_STATE_PENDING = 'pending'
SEGMENT_STATE_IN_PROGRESS = 'in_progress'
SEGMENT_STATE_SUCCESS = 'success'


def _update_subnet_configuration(resource_config):
Expand All @@ -52,19 +54,12 @@ def create(nsx_t_resource):

@with_nsx_t_client(SegmentState)
def start(nsx_t_resource):
segment_state = nsx_t_resource.get()
state = segment_state.state
if state in [SEGMENT_STATE_PENDING, SEGMENT_STATE_IN_PROGRESS]:
raise OperationRetry(
'Segment state '
'is still in {0} state'.format(state)
)
elif state == SEGMENT_STATE_SUCCESS:
ctx.logger.info('Segment started successfully')
else:
raise NonRecoverableError(
'Segment failed to started {0}'.format(state)
)
validate_if_resource_started(
'Segment',
nsx_t_resource,
[STATE_PENDING, STATE_IN_PROGRESS],
[STATE_SUCCESS]
)


@with_nsx_t_client(Segment)
Expand All @@ -89,34 +84,4 @@ def stop(nsx_t_resource):

@with_nsx_t_client(Segment)
def delete(nsx_t_resource):
try:
nsx_t_resource.get()
except NSXTSDKException:
ctx.logger.info('Segment {0} is deleted successfully'
.format(nsx_t_resource.resource_id))
return

if SEGMENT_TASK_DELETE not in ctx.instance.runtime_properties:
try:
nsx_t_resource.delete()
except NSXTSDKException:
ctx.logger.info(
'Segment {0} cannot be deleted now, try again'
''.format(nsx_t_resource.resource_id)
)
raise OperationRetry(
message='Segment {0} deletion is in progress.'
''.format(nsx_t_resource.resource_id)
)
else:
ctx.instance.runtime_properties[SEGMENT_TASK_DELETE] = True
else:
ctx.logger.info(
'Waiting for segment "{0}" to be deleted'.format(
nsx_t_resource.resource_id,
)
)
raise OperationRetry(
message='Segment {0} deletion is in progress.'
''.format(nsx_t_resource.resource_id)
)
validate_if_resource_deleted(nsx_t_resource)
Empty file added nsx_t_plugin/tier1/__init__.py
Empty file.
53 changes: 53 additions & 0 deletions nsx_t_plugin/tier1/tier1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
########
# Copyright (c) 2020 Cloudify Technologies Ltd. All rights reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
from cloudify import ctx

from nsx_t_plugin.decorators import with_nsx_t_client
from nsx_t_plugin.constants import (
STATE_IN_PROGRESS,
STATE_SUCCESS,
STATE_PENDING,
STATE_IN_SYNC
)
from nsx_t_plugin.utils import (
validate_if_resource_started,
validate_if_resource_deleted,
)
from nsx_t_sdk.resources import Tier1, Tier1state


@with_nsx_t_client(Tier1)
def create(nsx_t_resource):
# Trigger the actual call to the NSXT Manager API
resource = nsx_t_resource.create()
# Update the resource_id with the new "id" returned from API
nsx_t_resource.resource_id = resource.id
# Save path as runtime property to use it later on
ctx.instance.runtime_properties['path'] = resource.path


@with_nsx_t_client(Tier1state)
def start(nsx_t_resource):
validate_if_resource_started(
'Tier1',
nsx_t_resource,
[STATE_IN_PROGRESS, STATE_PENDING],
[STATE_SUCCESS, STATE_IN_SYNC]
)


@with_nsx_t_client(Tier1)
def delete(nsx_t_resource):
validate_if_resource_deleted(nsx_t_resource)
Loading

0 comments on commit ab0f907

Please sign in to comment.