Skip to content

Instantly share code, notes, and snippets.

@sneal
Created December 20, 2019 16:02
Show Gist options
  • Save sneal/894d67d4d516a5b3108d091c2aa002ff to your computer and use it in GitHub Desktop.
Save sneal/894d67d4d516a5b3108d091c2aa002ff to your computer and use it in GitHub Desktop.
NSX-T Concourse Tasks

create-transport-node-profile

This task creates a nsx-t transport node profile.

inputs:

  • nsx-t-installation: a git resource containing this repo's tasks

params:

  • NSXT_MANAGER_URL: where nsx-t manager lives, eg nsxmgr-01.haas-417.example.com
  • NSXT_ADMIN_USERNAME: eg admin
  • NSXT_ADMIN_PASSWORD: the password for the above user
  • TRANSPORT_NODE_PROFILE_NAME: name of transport node profile this task creates
  • TRANSPORT_ZONE_NAME: name of the transport zone associated with the profile
  • NVDS_NAME: name of the N-VDS switch associated with this profile
  • UPLINK_PROFILE_NAME: host overlay uplink profile name
  • NIOC_PROFILE_NAME: NIOC profile name
  • IP_POOL_NAME: TEP IP pool name
  • PHYSICAL_NIC_1_NAME: physical nic associated with the first uplink
  • PHYSICAL_NIC_2_NAME: (optional) another physical nic name
  • UPLINK_1_NAME: uplink name to associated with the primary physical nic
  • UPLINK_2_NAME: (optional) another uplink name

outputs:

  • transport-node-profile: a directory containing transport_node_profile.json which looks something like:
{
  "results" : [ {
    "transport_zone_endpoints" : [ {
      "transport_zone_id" : "25e5ab97-b7e2-4153-8e62-e30c47f1cedb"
    } ],
    "host_switch_spec" : {
      "host_switches" : [ {
        "host_switch_name" : "n-vds-overlay",
        "host_switch_profile_ids" : [ {
          "key" : "UplinkHostSwitchProfile",
          "value" : "775709e6-3c20-40dd-8602-307148c28052"
        }, {
          "key" : "NiocProfile",
          "value" : "8cb3de94-2834-414c-b07d-c034d878db56"
        }, {
          "key" : "LldpHostSwitchProfile",
          "value" : "306c9a2a-7c3d-47f2-a1e1-0b27ce4c3914"
        } ],
        "pnics" : [ {
          "device_name" : "vmnic8",
          "uplink_name" : "uplink-1"
        }, {
          "device_name" : "vmnic9",
          "uplink_name" : "uplink-2"
        } ],
        "is_migrate_pnics" : false,
        "ip_assignment_spec" : {
          "ip_pool_id" : "80e09594-1cb1-43c0-8b8b-f035d7686e56",
          "resource_type" : "StaticIpPoolSpec"
        },
        "cpu_config" : [ ],
        "vmk_install_migration" : [ ],
        "pnics_uninstall_migration" : [ ],
        "vmk_uninstall_migration" : [ ],
        "not_ready" : false
      } ],
      "resource_type" : "StandardHostSwitchSpec"
    },
    "resource_type" : "TransportNodeProfile",
    "id" : "2f471438-837a-4edc-8b38-9a3370abccbb",
    "display_name" : "host-overlay-transport-node-profile",
    "description" : "",
    "tags" : [ ],
    "_create_user" : "admin",
    "_create_time" : 1574381596230,
    "_last_modified_user" : "admin",
    "_last_modified_time" : 1574787311038,
    "_system_owned" : false,
    "_protection" : "NOT_PROTECTED",
    "_revision" : 3
  } ],
  "result_count" : 1,
  "sort_by" : "display_name",
  "sort_ascending" : true
}

example:

NSXT_MANAGER_URL='nsxmgr-01.example.com' \
NSXT_ADMIN_USERNAME='admin' \
NSXT_ADMIN_PASSWORD='[redacted]' \
TRANSPORT_NODE_PROFILE_NAME='new-tx-node-profile' \
TRANSPORT_ZONE_NAME='tz-overlay' \
NVDS_NAME='n-vds-overlay' \
UPLINK_PROFILE_NAME='host-overlay-uplink-profile' \
NIOC_PROFILE_NAME='nsx-default-nioc-hostswitch-profile' \
IP_POOL_NAME='tep-esxi-pool' \
PHYSICAL_NIC_1_NAME='vmnic4' \
PHYSICAL_NIC_2_NAME='vmnic5' \
UPLINK_1_NAME='uplink-1' \
UPLINK_2_NAME='uplink-2' \
fly -t hulk execute -c tasks/create-transport-node-profile/task.yml \
--input nsx-t-installation=. --output transport-node-profile=/tmp/transport-node-profile
#!/bin/bash -e
# check to see if there already exists a transport node profile with the same name
EXISTS=$(curl -f "https://${NSXT_MANAGER_URL}/api/v1/transport-node-profiles" \
-u "${NSXT_ADMIN_USERNAME}:${NSXT_ADMIN_PASSWORD}" \
-sk | jq ".results[] | select(.display_name == \"${TRANSPORT_NODE_PROFILE_NAME}\")")
if [ "${EXISTS}" != "" ]; then
echo "${EXISTS}" > transport-node-profile/transport_node_profile.json
echo "transport-node-profile already exists!"
echo "${EXISTS}"
exit 0
fi
TRANSPORT_ZONE_ID=$(curl -f "https://${NSXT_MANAGER_URL}/api/v1/transport-zones" \
-u "${NSXT_ADMIN_USERNAME}:${NSXT_ADMIN_PASSWORD}" \
-sk | jq -r ".results[] | select(.display_name == \"${TRANSPORT_ZONE_NAME}\") | .id")
IP_POOL_ID=$(curl -f "https://${NSXT_MANAGER_URL}/api/v1/pools/ip-pools" \
-u "${NSXT_ADMIN_USERNAME}:${NSXT_ADMIN_PASSWORD}" \
-sk | jq -r ".results[] | select(.display_name == \"${IP_POOL_NAME}\") | .id")
curl -f "https://${NSXT_MANAGER_URL}/api/v1/host-switch-profiles?include_system_owned=true" \
-u "${NSXT_ADMIN_USERNAME}:${NSXT_ADMIN_PASSWORD}" \
-sk > /tmp/host-switch-profiles.json
UPLINK_PROFILE_ID=$(jq -r ".results[] | select(.display_name == \"${UPLINK_PROFILE_NAME}\") | .id" < /tmp/host-switch-profiles.json)
NIOC_PROFILE_ID=$(jq -r ".results[] | select(.display_name == \"${NIOC_PROFILE_NAME}\") | .id" < /tmp/host-switch-profiles.json)
LLDP_PROFILE_ID=$(jq -r ".results[] | select(.display_name == \"LLDP [Send Packet Disabled]\") | .id" < /tmp/host-switch-profiles.json)
echo "transport zone: ${TRANSPORT_ZONE_NAME} - ${TRANSPORT_ZONE_ID}"
echo "ip pool: ${IP_POOL_NAME} - ${IP_POOL_ID}"
echo "uplink profile: ${UPLINK_PROFILE_NAME} - ${UPLINK_PROFILE_ID}"
echo "nioc profile: ${NIOC_PROFILE_NAME} - ${NIOC_PROFILE_ID}"
echo "lldp profile: LLDP [Send Packet Disabled] - ${LLDP_PROFILE_ID}"
echo "creating transport node profile"
curl -v -f -k -u "${NSXT_ADMIN_USERNAME}:${NSXT_ADMIN_PASSWORD}" \
--trace-ascii /tmp/transport-node-profiles.txt \
-X POST "https://${NSXT_MANAGER_URL}/api/v1/transport-node-profiles" \
-H "Content-Type: application/json" \
-d @- << EOF > transport-node-profile/transport_node_profile.json
{
"resource_type": "TransportNodeProfile",
"display_name": "${TRANSPORT_NODE_PROFILE_NAME}",
"description": "Transport Node Profile to be applied to a cluster",
"host_switch_spec" : {
"host_switches" : [ {
"host_switch_name" : "${NVDS_NAME}",
"host_switch_profile_ids" : [ {
"key" : "UplinkHostSwitchProfile",
"value" : "${UPLINK_PROFILE_ID}"
}, {
"key" : "NiocProfile",
"value" : "${NIOC_PROFILE_ID}"
}, {
"key" : "LldpHostSwitchProfile",
"value" : "${LLDP_PROFILE_ID}"
} ],
"pnics" : [ {
"device_name" : "${PHYSICAL_NIC_1_NAME}",
"uplink_name" : "${UPLINK_1_NAME}"
}, {
"device_name" : "${PHYSICAL_NIC_2_NAME}",
"uplink_name" : "${UPLINK_2_NAME}"
} ],
"is_migrate_pnics" : false,
"ip_assignment_spec" : {
"ip_pool_id" : "${IP_POOL_ID}",
"resource_type" : "StaticIpPoolSpec"
},
"cpu_config" : [ ],
"vmk_install_migration" : [ ],
"pnics_uninstall_migration" : [ ],
"vmk_uninstall_migration" : [ ],
"not_ready" : false
} ],
"resource_type" : "StandardHostSwitchSpec"
},
"transport_zone_endpoints": [
{
"transport_zone_id": "${TRANSPORT_ZONE_ID}"
}
]
}
EOF
cat transport-node-profile/transport_node_profile.json
---
platform: linux
inputs:
- name: nsx-t-installation
outputs:
- name: transport-node-profile
params:
NSXT_MANAGER_URL:
NSXT_ADMIN_USERNAME:
NSXT_ADMIN_PASSWORD:
TRANSPORT_NODE_PROFILE_NAME:
TRANSPORT_ZONE_NAME:
NVDS_NAME:
UPLINK_PROFILE_NAME:
NIOC_PROFILE_NAME: nsx-default-nioc-hostswitch-profile
IP_POOL_NAME:
PHYSICAL_NIC_1_NAME:
PHYSICAL_NIC_2_NAME:
UPLINK_1_NAME:
UPLINK_2_NAME:
run:
path: sh
args:
- -c
- nsx-t-installation/tasks/create-transport-node-profile/task.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment