Deploying VMware on AWS SDDC with the Native RESTful API

    No Comments

    VMware Cloud on AWS includes a comprehensive RESTful API that can perform a number of functions that include adding, modifying and deleting SDDCs.  Through the course of this module, you will learn about the RESTful APIs and how to leverage them to automate common operations.

    This is indicated for any company that adopt a DevOps methodology for application development and would like to automatically create and delete SDDCs via their development pipeline.

    When a pipeline is completed in order to minimize costs we have to delete the environments, ruthlessly” automating the deployment. Developer Center is where automation begins

    What is a RESTful API?

    REST stands for REpresentational State Transfer. This essentially refers to a style of web architecture that has many underlying characteristics and governs the behavior of clients and servers. REST is defined by 6 constraints: client-server, stateless, Cacheable, Layered system, Uniform Interface, Code on Demand (optional).

    This kind of API works pretty much as any website. You send your request to a server via HTTP and you will get a website in response.

    A REST API defines a set of functions which developers can perform requests and receive responses via HTTP protocol such as GET, DELETE and POST.

    If an API follows the REST “rules”, it can be called RESTful API. Thanks to this interface, resources can be called upon singularly.

    If you came from Operations and you are wondering why you need to start learning about this, have a look at this video by Iwan Hoodendoom using NSX and RESTful API for deploy and successfully authenticate a REST API client construct and execute an API call using correct syntax and formatting. Analyze, modify, and successfully retrieve configuration data using an existing API call. All of this using just the NSX Api Guide and Postman on Google Chrome. Here is the link of the video:

    If you would like a more formal explanation you should visit

    https://blogs.vmware.com/code/2017/11/30/overview-vmware-cloud-aws-apis/

    In this case we have to automate so we are going to Developer Center.

    Developer Center is a great resource area allowing developers to get up and running quickly with VMware Cloud on AWS. Developers can gain access to this information using the “Developer Center” tab in the VMware Cloud on AWS console.

    Let’s check out a code sample that was uploaded by VMware API developers. If you scroll through this screen you will see there are code samples for Postman (a REST API Development Environment), Python, PowerCLI, and many others. Anyone can contribute code samples to the community, if that interests you go to http://code.vmware.com or click on the link “VMware{code} Sample Exchange”.

    1. Click on Code Samples in the menu
    2. Scroll down until you see the PowerCLI – VMC Example Scripts box
    3. Click on Download
    4. Click on Save in the pop up box to save the file

    1. Navigate to \PowerCLI-Example-Scripts-master.zip\PowerCLI-Example-Scripts-master\Scripts\VMware_Cloud_on_AWS
    2. Right click on VMC Example Script.ps1 and click Open

    This will open a text document where you can see the PowerShell commands you can use with your SDDC.

    1. Close the text document and file explorer windows

    # Author: Kyle Ruddy
    # Product: VMware Cloud on AWS
    # Description: VMware Cloud on AWS Single Host Deployment Script using PowerCLI
    # Requirements:
    #  - PowerShell 3.x or newer
    #  - PowerCLI 6.5.4 or newer
    
    # Set details for SDDC
    $oauthToken = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"
    $sddcName = "PowerCLI-1Node-SDDC"
    $hostCount = "1"
    $awsRegion = "US_WEST_2"
    
    # --- Deployment code  ---
    # Connect to VMware Cloud Service
    Connect-Vmc -RefreshToken $oauthToken | Out-Null
    
    # Get ORG ID
    $orgSvc = Get-VmcService -Name com.vmware.vmc.orgs
    $org = $orgSvc.List()
    Write-Host "Org:"$org.display_name" ID:"$org.id
    
    # Get Linked Account ID
    $connAcctSvc = Get-VmcService -Name com.vmware.vmc.orgs.account_link.connected_accounts
    $connAcctId = $connAcctSvc.get($org.id) | Select-Object -ExpandProperty id
    Write-Host "Account ID: $connAcctId"
    
    # Get Subnet ID
    $compSubnetSvc = Get-VmcService -Name com.vmware.vmc.orgs.account_link.compatible_subnets
    $vpcMap = $compSubnetSvc.Get($org.id, $connAcctId, $region) | Select-Object -ExpandProperty vpc_map 
    $compSubnets = $vpcMap | Select-Object -ExpandProperty Values | Select-Object -ExpandProperty subnets
    $compSubnet = $compSubnets | where {$_.name -ne $null} | Select-Object -first 1
    Write-Host "Subnet CIDR"$compSubnet.subnet_cidr_block"ID:"$compSubnet.subnet_id
    
    # Deploy the SDDC
    $sddcSvc = Get-VmcService com.vmware.vmc.orgs.sddcs
    $sddcCreateSpec = $sddcSvc.Help.create.sddc_config.Create()
    $sddcCreateSpec.region = $awsRegion
    $sddcCreateSpec.Name = $sddcName
    $sddcCreateSpec.num_hosts = $hostCount
    if ($org.properties.values.sddcTypes) {$sddcCreateSpec.sddc_type = "1NODE"}
    $sddcCreateSpec.Provider = "AWS"
    $accountLinkSpec = $sddcSvc.Help.create.sddc_config.account_link_sddc_config.Element.Create()
    $accountLinkSpec.connected_account_id = $connAcctId
    $custSubId0 = $sddcSvc.Help.create.sddc_config.account_link_sddc_config.Element.customer_subnet_ids.Element.Create()
    $custSubId0 = $compSubnet.subnet_id
    $accountLinkSpec.customer_subnet_ids.Add($custSubId0) | Out-Null
    $sddcCreateSpec.account_link_sddc_config.Add($accountLinkSpec) | Out-Null
    $sddcCreateSpec
    $newSddc = $sddcSvc.create($org.Id, $sddcCreateSpec)
    $newSddc

    Software Development Kits (SDKs)

    There is a wide variety of Software Development Kits (SDKs) available to interact with the VMware Cloud on AWS APIs and the deployed SDDC products. The SDK section provides easy access to each of these open-sourced SDKs that are available on GitHub.

    Click on the Downloads tab

    There are command line resources like Datacenter CLI (DCLI) and PowerCLI.

    API Explorer

    The API Explorer section brings easy access to interact directly with the RESTful APIs available from the Cloud Services API and the VMware Cloud on AWS API.

    These APIs are presented as an interactive API browser with some useful integrations to make it easier to work with.

    The API Explorer being internal to the Cloud console allows us to use the existing refresh token to authenticate. We can also automatically populate certain fields, such as the Organization ID, to help improve the experience of learning and using these APIs.

    Learning the API and seeing the responses from within the API Explorer could not be easier with the ability to “Execute” these APIs and see the live responses.

    Let’s now run some simple REST API commands built into the Developer Center

    1. Click on the API Explorer tab
    2. Select your SDDC (ex, HOL-SDDC-01)
    3. Click on the drop down arrow next to Organizations
    4. Click on the drop down arrow next to the first “GET” API
    5. Click on Execute

    API Explorer – SDDC GET Response

    Now let’s look at the response body

    1. Click on Sddc (HOL-SDDC-01) to expand the response body
    2. The creation date of the SDDC
    3. The SDDC ID
    4. The SDDC state

    Deploying SDDC with Native RESTful APIs

    Deploying a Software Defined Data Center (SDDC) is the first step in making use of the VMware Cloud on AWS service.

    In this module, we will discuss how to programmatically create an SDDC leveraging Native APIs.

    The first time you’re deploying an SDDC, one of the key requirements is that you will need to link an AWS account to the VMware Cloud on AWS service. This allows you to do many things but the main reason is that it will allow you to connect your SDDC to an existing AWS VPC which is mandatory for a real environment.

    It is also worth noting that the Management Subnet parameter is optional but for a production environment it is important to define it properly, since it cannot be changed later and will require you to destroy the SDDC to do so.

    These are the rules:

    • Specify a private subnet range (RFC 1918) to be used for vCenter Server, NSX Manager, and ESXi hosts.
    • Choose a range that will not conflict with other networks you will connect to this SDDC.
    • Minimum CIDR sizes: /23 for up to 27 hosts, /20 for up to 251 hosts, /16 for up to 4091 hosts.
    • Reserved CIDRs: 10.0.0.0/15, 172.31.0.0/16.

    For the purpose of this lab there is no need to link any AWS account, nor to define a Management Subnet, together with VPC and subnets and a lot of other optional parameters (i.e. Stretched Cluster) since we are going to use the defaults for most of them and a special “cloud provider” called ZEROCLOUD.

    API Explorer

    API Explorer is the quickest and easiest way to interact with Native RESTful API. It doesn’t require any code skills and provides an intuitive UI using the browser.

    The API Explorer can be found in the Developer Center Tab:

    1. Select the Developer Center tab from the top menu
    2. Click on the API Explorer sub-tab

    Browsing the API to Provision an SDDC

    Browsing APIs using the API Explorer is integrated into the UI and has been designed to be intuitive and quick to validate API executions.

    In this section, we will navigate to the API specific for creating an SDDC, which is a POST call that submits a set of configuration parameters that need to be defined and set in the API Call.

    Now that we’re in the API Explorer, we are going to:

    1.  Browse to the SDDCs section and click the drop down arrow to expand it
    2.  Expand the following top section labeled POST /orgs/{org}/sddcs
    3. We’ll see the org parameter already has our Org Id filled in as well as a blank sddcConfig value
    4.  We can populate that value with an example JSON body containing empty values by clicking on the AwsSddcConfig link in the Data Type column.

    Configure JSON Parameters and Execute

    The sddcConfig text area is where we are going to define the configuration parameters that will be sent during the POST API call.

    Most of the sddcConfig parameters have defaults and are optional, we are going to configure just the bare minimum mandatory one to execute that task.

    1. Click on the AwsSddcConfig: the sddcConfig area will get populated with an empty template of the parameters
    2. Edit the  sddcConfig text area to look EXACTLY like the below JSON (avoid any blank line at the beginning and end, remove the last comma after “region”);
    3. Click Execute

    Please note that for simplicity purpose, we omitted most of the parameters, especially the account_link_sddc_config since we are using ZEROCLOUD provider.

    Make sure to fill in ONLY the information provided in the example below in the sddcConfig Value.

    {
        "name": "APIExplorer-Example-SDDC",
        "num_hosts": 4,
        "provider": "ZEROCLOUD",
        "region": "EU_CENTRAL_1"
    }

    Confirm JSON Parameters

    In a real environment you can retrieve:

    •  the  connected_account_id from the API with the following:

    Method: GET /orgs/{org}/account-link/connected-accounts

    Property: ID

    • customer_subnet_ids:  (desired subnet ID for VPC traffic)

    Method: GET /orgs/{org}/account-link/compatible-subnets

    Property: subnet_id

    Validating the API execution

    If the POST is successfully executed you should get a Task ID in the Response, similar to the picture.

    Once you see the successful Response with a Task ID, you can go to the main SDDC Menu and follow the progress of it.

    View Progress of SDDC Creation

    1. Click on SDDCs on the top menu
    2. You should see a progress bar configuring the just created SDDC

    After a few minutes, you should see your brand new SDDC card with its parameters in the SDDCs main page.

    You can also find the PowerShell version of the same API calls in the code samples.

    If you would like to have more information I suggest have some practice on VMware HOL Labs and visit William Lam website (Staff Solutions Architect working in the VMware Cloud on AWS team within the Cloud Platform Business Unit (CPBU) at VMware) 

    Using VMC API to answer commonly asked questions about your SDDC

    Automation with the VMware Cloud Services Platform (CSP)

    Here is bash script provided by Willial Lam to have a summary of SDDC

    #!/bin/bash
    
    if [ ${#} -ne 3 ]; then
        echo -e "Usage: \n\t$0 [REFRESH_TOKEN] [ORGID] [SDDCID]\n"
        exit 1
    fi
    
    type jq > /dev/null 2&>1
    if [ $? -eq 1 ]; then
        echo "It does not look like you have jq installed. This script uses jq to parse the JSON output"
        exit 1
    fi
    
    REFRESH_TOKEN=$1
    ORGID=$2
    SDDCID=$3
    
    RESULTS=$(curl -s -X POST -H "Content-Type: application/json" -H "csp-auth-token: ${REFRESH_TOKEN}" "https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize?refresh_token=${REFRESH_TOKEN}")
    CSP_ACCESS_TOKEN=$(echo $RESULTS | jq -r .access_token)
    
    RESULTS=$(curl -s -X GET -H "Content-Type: application/json" -H "csp-auth-token: ${CSP_ACCESS_TOKEN}" "https://vmc.vmware.com/vmc/api/orgs/${ORGID}/sddcs/${SDDCID}")
    
    SDDC_VERSION=$(echo ${RESULTS}|jq .resource_config.sddc_manifest.vmc_version)
    CREATE_DATE=$(echo ${RESULTS}|jq .created)
    DEPLOYMENT_TYPE=$(echo ${RESULTS}|jq .resource_config.deployment_type)
    REGION=$(echo ${RESULTS}|jq .resource_config.region)
    AVAILABILITY_ZONE=$(echo ${RESULTS}|jq .resource_config.availability_zones)
    INSTANCE_TYPE=$(echo ${RESULTS}|jq .resource_config.sddc_manifest.esx_ami.instance_type)
    VPC_CIDR=$(echo ${RESULTS}|jq .resource_config.vpc_info.vpc_cidr)
    NSXT=$(echo ${RESULTS}|jq .resource_config.nsxt)
    EXPIRATION_DATE=$(echo ${RESULTS}|jq .expiration_date)
    
    cat << EOF
    Version: ${SDDC_VERSION}
    CreateDate: ${CREATE_DATE}
    ExpirationDate: ${EXPIRATION_DATE}
    DeploymentType: ${DEPLOYMENT_TYPE}
    Region: ${REGION}
    AvaiabilityZone: ${AVAILABILITY_ZONE}
    InstanceType: ${INSTANCE_TYPE}
    VpcCIDR: ${VPC_CIDR}
    NSXT: ${NSXT}
    EOF

    Here is a PowerCli function by William Lam to provide SDDC summary

    https://github.com/lamw/PowerCLI-Example-Scripts/blob/master/Modules/VMware.VMC/VMware.VMC.psm1#L858

    Function Get-VMCCommand {
    <#
        .NOTES
        ===========================================================================
        Created by:    VMware
        Date:          11/17/2017
        Organization:  VMware
        Blog:          http://vmware.com/go/powercli
        Twitter:       @powercli
        ===========================================================================
        .SYNOPSIS
            Returns all cmdlets for VMware Cloud on AWS
        .DESCRIPTION
            This cmdlet will allow you to return all cmdlets included in the VMC module
        .EXAMPLE
            Get-VMCCommand
        .EXAMPLE
            Get-Command -Module VMware.VMC
        .NOTES
            You can either use this cmdlet or the Get-Command cmdlet as seen in Example 2
    #>
        Get-command -Module VMware.VimAutomation.Vmc
        Get-Command -Module VMware.VMC
    
    }
    Function Connect-VMCVIServer {
    <#
        .NOTES
        ===========================================================================
        Created by:    VMware
        Date:          11/17/2017
        Organization:  VMware
        Blog:          http://vmware.com/go/powercli
        Twitter:       @powercli
        ===========================================================================
        .SYNOPSIS
            Cmdlet to connect to your VMC vCenter Server
        .DESCRIPTION
            This will connect you to both the VMC ViServer as well as the CiSServer at the same time.
        .EXAMPLE
            Connect-VMCVIServer -Server <VMC vCenter address> -User <Username> -Password <Password>
        .NOTES
            Easiest way is to pipe through your credentials from Get-VMCSDDCDefaultCredential
    #>
        Param (
            [Parameter(Mandatory=$true)]$Org,
            [Parameter(Mandatory=$true)]$Sddc,
            [switch]$Autologin
        )
    
        If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else {
            $creds = Get-VMCSDDCDefaultCredential -Org $Org -Sddc $Sddc
            Write-Host "Connecting to VMC vCenter Server" $creds.vc_public_ip
            Connect-VIServer -Server $creds.vc_public_ip -User $creds.cloud_username -Password $creds.cloud_password | Add-Member -MemberType Noteproperty -Name Location -Value "VMC"
            Write-Host "Connecting to VMC CIS Endpoint" $creds.vc_public_ip
            Connect-CisServer -Server $creds.vc_public_ip -User $creds.cloud_username -Password $creds.cloud_password | Add-Member -MemberType Noteproperty -Name Location -Value "VMC"
        }
    }
    Function Get-VMCOrg {
    <#
        .NOTES
        ===========================================================================
        Created by:    VMware
        Date:          11/17/2017
        Organization:  VMware
        Blog:          http://vmware.com/go/powercli
        Twitter:       @powercli
        ===========================================================================
        .SYNOPSIS
            Return the Orgs that you are a part of
        .DESCRIPTION
            Depending on what you've purchased, you may be a part of one or more VMC Orgs. This will return your orgs
        .EXAMPLE
            Get-VMCOrg
        .EXAMPLE
            Get-VMCOrg -Name <Org Name>
        .NOTES
            Return all the info about the orgs you are a part of
    #>
        Param (
           [Parameter(Mandatory=$false)]$Name
        )
    
        If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use Connect-VMC to connect" } Else {
            $orgService = Get-VMCService com.vmware.vmc.orgs
            if ($PSBoundParameters.ContainsKey("Name")){
                $orgs = $orgService.list() | Where {$_.display_name -match $Name}
            } Else {
                $orgs = $orgService.list()
            }
            $Orgs | Select display_name, name, user_name, created, id
        }
    }
    Function Get-VMCSDDC {
    <#
        .NOTES
        ===========================================================================
        Created by:    VMware
        Date:          11/17/2017
        Organization:  VMware
        Blog:          http://vmware.com/go/powercli
        Twitter:       @powercli
        ===========================================================================
        .SYNOPSIS
            Returns all of the SDDCs you are associated to
        .DESCRIPTION
            Returns all of the SDDCs ayou are associated to
        .EXAMPLE
            Get-VMCSDDC -Org <Org Name>
        .EXAMPLE
            Get-VMCSDDC -Name <SDDC Name> -Org <Org Name>
    #>
        Param (
            [Parameter(Mandatory=$True)]$Org,
            [Parameter(Mandatory=$false)]$Name
        )
    
        If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else {
            if ($PSBoundParameters.ContainsKey("Org")){
                $orgs = Get-VMCOrg -Name $Org
            } else {
                $orgs = Get-VMCOrg
            }
    
            foreach ($org in $orgs) {
                $orgID = $org.ID
                $sddcService = Get-VMCService com.vmware.vmc.orgs.sddcs
                if ($PSBoundParameters.ContainsKey("Name")){
                    $sddcService.list($OrgID) | Where {$_.name -match $Name}
                } Else {
                    $sddcService.list($OrgID)
                }
            }
        }
    }
    Function Get-VMCTask {
    <#
        .NOTES
        ===========================================================================
        Created by:    VMware
        Date:          11/17/2017
        Organization:  VMware
        Blog:          http://vmware.com/go/powercli
        Twitter:       @powercli
        ===========================================================================
        .SYNOPSIS
            Returns all of the VMC Tasks
        .DESCRIPTION
            Returns all of the VMC Tasks that have either occurred or are in process
        .EXAMPLE
            Get-VMCTask
    #>
        Param (
            [Parameter(Mandatory=$True)]$Org
        )
    
        If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else {
            if ($PSBoundParameters.ContainsKey("Org")){
                $orgs = Get-VMCOrg -Name $Org
            } else {
                $orgs = Get-VMCOrg
            }
    
            foreach ($org in $orgs) {
                $orgID = $org.ID
                $taskService = Get-VMCService com.vmware.vmc.orgs.tasks
                $taskService.list($OrgID) | Select * -ExcludeProperty Help
            }
        }
    }
    Function Get-VMCSDDCDefaultCredential {
    <#
        .NOTES
        ===========================================================================
        Created by:    VMware
        Date:          11/17/2017
        Organization:  VMware
        Blog:          http://vmware.com/go/powercli
        Twitter:       @powercli
        ===========================================================================
        .SYNOPSIS
            Returns the default credential for the SDDC
        .DESCRIPTION
            Returns the default credential for the sddc
        .EXAMPLE
            Get-VMCSDDCDefaultCredential -Org <Org Name>
        .EXAMPLE
            Get-VMCSDDCDefaultCredential -Sddc <SDDC Name> -Org <Org Name>
    #>
        Param (
            [Parameter(Mandatory=$true)]$Org,
            [Parameter(Mandatory=$false)]$Sddc
        )
    
        If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else {
            if ($PSBoundParameters.ContainsKey("Sddc")){
                $sddcs = Get-VMCSDDC -Name $Sddc -Org $Org
            } else {
                $sddcs = Get-VMCSDDC -Org $Org
            }
    
            foreach ($sddc in $sddcs) {
                $sddc.resource_config | Select-object vc_url, vc_management_ip, vc_public_ip, cloud_username, cloud_password
            }
        }
    }
    Function Get-VMCSDDCPublicIP {
    <#
        .NOTES
        ===========================================================================
        Created by:    VMware
        Date:          11/17/2017
        Organization:  VMware
        Blog:          http://vmware.com/go/powercli
        Twitter:       @powercli
        ===========================================================================
        .SYNOPSIS
            Returns your Public IPs
        .DESCRIPTION
            Returns your Public IPs
        .EXAMPLE
            Get-VMCSDDCPublicIP -Org <Org Name>
        .EXAMPLE
            Get-VMCSDDCPublicIP -Sddc <SDDC Name> -Org <Org Name>
        .NOTES
            Return your Public IPs that you have assigned to your account
    #>
        Param (
            [Parameter(Mandatory=$true)]$Org,
            [Parameter(Mandatory=$false)]$Sddc
        )
    
        If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else {
            if ($PSBoundParameters.ContainsKey("Sddc")){
                $sddcs = Get-VMCSDDC -Name $Sddc -Org $Org
            } else {
                $sddcs = Get-VMCSDDC -Org $Org
            }
    
            foreach ($sddc in $sddcs) {
                $sddc.resource_config.Public_ip_pool
            }
        }
    }
    Function Get-VMCVMHost {
        Param (
            [Parameter(Mandatory=$false)]$Sddc,
            [Parameter(Mandatory=$true)]$Org
        )
    
        If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else {
            if ($PSBoundParameters.ContainsKey("Sddc")){
                $sddcs = Get-VMCSDDC -Name $Sddc -Org $Org
            } else {
                $sddcs = Get-VMCSDDC -Org $Org
            }
    
            $results = @()
            foreach ($sddc in $sddcs) {
                foreach ($vmhost in $sddc.resource_config.esx_hosts) {
                    $tmp = [pscustomobject] @{
                        esx_id = $vmhost.esx_id;
                        name = $vmhost.name;
                        hostname = $vmhost.hostname;
                        esx_state = $vmhost.esx_state;
                        sddc_id = $sddc.id;
                        org_id = $sddc.org_id;
                    }
                    $results += $tmp
                }
                $results
            }
        }
    }
    Function Get-VMCSDDCVersion {
    <#
        .NOTES
        ===========================================================================
        Created by:    VMware
        Date:          11/17/2017
        Organization:  VMware
        Blog:          http://vmware.com/go/powercli
        Twitter:       @powercli
        ===========================================================================
        
        .SYNOPSIS
            Returns SDDC Version
        .DESCRIPTION
            Returns Version of the SDDC
        .EXAMPLE
            Get-VMCSDDCVersion -Name <SDDC Name> -Org <Org Name>
    #>
        Param (
            [Parameter(Mandatory=$True)]$Org,
            [Parameter(Mandatory=$false)]$Name
        )
    
        If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else {
            if ($PSBoundParameters.ContainsKey("Org")){
                $orgs = Get-VMCOrg -Name $Org
            } else {
                $orgs = Get-VMCOrg
            }
    
            foreach ($org in $orgs) {
                $orgID = $org.ID
                $sddcService = Get-VMCService com.vmware.vmc.orgs.sddcs
                if ($PSBoundParameters.ContainsKey("Name")){
                    ($sddcService.list($OrgID) | Where {$_.name -match $Name}).resource_config.sddc_manifest | Select *version
                } Else {
                    ($sddcService.list($OrgID)).resource_config.sddc_manifest | Select *version
                }
            }
        }
    }
    
    Function Get-VMCFirewallRule {
        <#
            .NOTES
            ===========================================================================
            Created by:     William Lam
            Date:          11/19/2017
            Organization: 	VMware
            Blog:          https://www.virtuallyghetto.com
            Twitter:       @lamw
            ===========================================================================
            .SYNOPSIS
                Retruns VMC Firewall Rules for a given Gateway (MGW or CGW)
            .DESCRIPTION
                Retruns VMC Firewall Rules for a given Gateway (MGW or CGW)
            .EXAMPLE
                Get-VMCFirewallRule -OrgName <Org Name> -SDDCName <SDDC Name> -GatewayType <MGW or CGW>
            .EXAMPLE
                Get-VMCFirewallRule -OrgName <Org Name> -SDDCName <SDDC Name> -GatewayType <MGW or CGW> -ShowAll
        #>
            param(
                [Parameter(Mandatory=$false)][String]$SDDCName,
                [Parameter(Mandatory=$false)][String]$OrgName,
                [Parameter(Mandatory=$false)][Switch]$ShowAll,
                [Parameter(Mandatory=$true)][ValidateSet("MGW","CGW")][String]$GatewayType
            )
    
            if($GatewayType -eq "MGW") {
                $EdgeId = "edge-1"
            } else {
                $EdgeId = "edge-2"
            }
    
            $orgId = (Get-VMCOrg -Name $OrgName).Id
            $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id
    
            $firewallConfigService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config
    
            $firewallRules = ($firewallConfigService.get($orgId, $sddcId, $EdgeId)).firewall_rules.firewall_rules
            if(-not $ShowAll) {
                $firewallRules = $firewallRules | where { $_.rule_type -ne "default_policy" -and $_.rule_type -ne "internal_high" -and $_.name -ne "vSphere Cluster HA" -and $_.name -ne "Outbound Access" } | Sort-Object -Property rule_tag
            } else {
                $firewallRules = $firewallRules | Sort-Object -Property rule_tag
            }
    
            $results = @()
            foreach ($firewallRule in $firewallRules) {
                if($firewallRule.source.ip_address.Count -ne 0) {
                    $source = $firewallRule.source.ip_address
                } else { $source = "ANY" }
    
                if($firewallRule.application.service.protocol -ne $null) {
                    $protocol = $firewallRule.application.service.protocol
                } else { $protocol = "ANY" }
    
                if($firewallRule.application.service.port -ne $null) {
                    $port = $firewallRule.application.service.port
                } else { $port = "ANY" }
    
                $tmp = [pscustomobject] @{
                    ID = $firewallRule.rule_id;
                    Name = $firewallRule.name;
                    Type = $firewallRule.rule_type;
                    Action = $firewallRule.action;
                    Protocol = $protocol;
                    Port = $port;
                    SourceAddress = $source
                    DestinationAddress = $firewallRule.destination.ip_address;
                }
                $results+=$tmp
            }
            $results
        }
    
        Function Export-VMCFirewallRule {
        <#
            .NOTES
            ===========================================================================
            Created by:     William Lam
            Date:          11/19/2017
            Organization: 	VMware
            Blog:          https://www.virtuallyghetto.com
            Twitter:       @lamw
            ===========================================================================
            .SYNOPSIS
                Exports all "customer" created VMC Firewall Rules to JSON file
            .DESCRIPTION
                Exports all "customer" created VMC Firewall Rules to JSON file
            .EXAMPLE
                Export-VMCFirewallRule -OrgName <Org Name> -SDDCName <SDDC Name> -GatewayType <MGW or CGW> -Path "C:\Users\lamw\Desktop\VMCFirewallRules.json"
        #>
            param(
                [Parameter(Mandatory=$false)][String]$SDDCName,
                [Parameter(Mandatory=$false)][String]$OrgName,
                [Parameter(Mandatory=$true)][ValidateSet("MGW","CGW")][String]$GatewayType,
                [Parameter(Mandatory=$false)][String]$Path
            )
    
            if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break }
    
            if($GatewayType -eq "MGW") {
                $EdgeId = "edge-1"
            } else {
                $EdgeId = "edge-2"
            }
    
            $orgId = (Get-VMCOrg -Name $OrgName).Id
            $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id
    
            if(-not $orgId) {
                Write-Host -ForegroundColor red "Unable to find Org $OrgName, please verify input"
                break
            }
            if(-not $sddcId) {
                Write-Host -ForegroundColor red "Unable to find SDDC $SDDCName, please verify input"
                break
            }
    
            $firewallConfigService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config
    
            $firewallRules = ($firewallConfigService.get($orgId, $sddcId, $EdgeId)).firewall_rules.firewall_rules
            if(-not $ShowAll) {
                $firewallRules = $firewallRules | where { $_.rule_type -ne "default_policy" -and $_.rule_type -ne "internal_high" -and $_.name -ne "vSphere Cluster HA" -and $_.name -ne "Outbound Access" } | Sort-Object -Property rule_tag
            } else {
                $firewallRules = $firewallRules | Sort-Object -Property rule_tag
            }
    
            $results = @()
            $count = 0
            foreach ($firewallRule in $firewallRules) {
                if($firewallRule.source.ip_address.Count -ne 0) {
                    $source = $firewallRule.source.ip_address
                } else {
                    $source = "ANY"
                }
    
                $tmp = [pscustomobject] @{
                    Name = $firewallRule.name;
                    Action = $firewallRule.action;
                    Protocol = $firewallRule.application.service.protocol;
                    Port = $firewallRule.application.service.port;
                    SourcePort = $firewallRule.application.service.source_port;
                    ICMPType = $firewallRule.application.service.icmp_type;
                    SourceAddress = $firewallRule.source.ip_address;
                    DestinationAddress = $firewallRule.destination.ip_address;
                    Enabled = $firewallRule.enabled;
                    Logging = $firewallRule.logging_enabled;
                }
                $count+=1
                $results+=$tmp
            }
            if($Path) {
                Write-Host -ForegroundColor Green "Exporting $count VMC Firewall Rules to $Path ..."
                $results | ConvertTo-Json | Out-File $Path
            } else {
                $results | ConvertTo-Json
            }
        }
    
        Function Import-VMCFirewallRule {
        <#
            .NOTES
            ===========================================================================
            Created by:     William Lam
            Date:          11/19/2017
            Organization: 	VMware
            Blog:          https://www.virtuallyghetto.com
            Twitter:       @lamw
            ===========================================================================
            .SYNOPSIS
                Imports VMC Firewall Rules from exported JSON configuration file
            .DESCRIPTION
                Imports VMC Firewall Rules from exported JSON configuration file
            .EXAMPLE
                Import-VMCFirewallRule -OrgName <Org Name> -SDDCName <SDDC Name> -GatewayType <MGW or CGW> -Path "C:\Users\lamw\Desktop\VMCFirewallRules.json"
        #>
            param(
                [Parameter(Mandatory=$false)][String]$SDDCName,
                [Parameter(Mandatory=$false)][String]$OrgName,
                [Parameter(Mandatory=$true)][ValidateSet("MGW","CGW")][String]$GatewayType,
                [Parameter(Mandatory=$false)][String]$Path
            )
    
            if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break }
    
            if($GatewayType -eq "MGW") {
                $EdgeId = "edge-1"
            } else {
                $EdgeId = "edge-2"
            }
    
            $orgId = (Get-VMCOrg -Name $OrgName).Id
            $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id
    
            if(-not $orgId) {
                Write-Host -ForegroundColor red "Unable to find Org $OrgName, please verify input"
                break
            }
            if(-not $sddcId) {
                Write-Host -ForegroundColor red "Unable to find SDDC $SDDCName, please verify input"
                break
            }
    
            $firewallService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config.rules
    
            $vmcFirewallRulesJSON = Get-Content -Raw $Path | ConvertFrom-Json
    
            # Create top level Firewall Rules Object
            $firewallRules = $firewallService.Help.add.firewall_rules.Create()
            # Create top top level Firewall Rule Spec which will be an array of individual Firewall rules as we process them in next section
            $ruleSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Create()
    
            foreach ($vmcFirewallRule in $vmcFirewallRulesJSON) {
                # Create Individual Firewall Rule Element Spec
                $ruleElementSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Element.Create()
    
                # AppSpec
                $appSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Element.application.Create()
                # ServiceSpec
                $serviceSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Element.application.service.Element.Create()
    
                $protocol = $null
                if($vmcFirewallRule.Protocol -ne $null) {
                    $protocol = $vmcFirewallRule.Protocol
                }
                $serviceSpec.protocol = $protocol
    
                # Process ICMP Type from JSON
                $icmpType = $null
                if($vmcFirewallRule.ICMPType -ne $null) {
                    $icmpType = $vmcFirewallRule.ICMPType
                }
                $serviceSpec.icmp_type = $icmpType
    
                # Process Source Ports from JSON
                $sourcePorts = @()
                if($vmcFirewallRule.SourcePort -eq "any" -or $vmcFirewallRule.SourcePort -ne $null) {
                    foreach ($port in $vmcFirewallRule.SourcePort) {
                        $sourcePorts+=$port
                    }
                } else {
                    $sourcePorts = @("any")
                }
                $serviceSpec.source_port = $sourcePorts
    
                # Process Ports from JSON
                $ports = @()
                if($vmcFirewallRule.Port -ne "null") {
                    foreach ($port in $vmcFirewallRule.Port) {
                        $ports+=$port
                    }
                }
                $serviceSpec.port = $ports
                $addSpec = $appSpec.service.Add($serviceSpec)
    
                # Create Source Spec
                $srcSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Element.source.Create()
                $srcSpec.exclude = $false
                # Process Source Address from JSON
                $sourceAddess = @()
                if($vmcFirewallRule.SourceAddress -ne "null") {
                    foreach ($address in $vmcFirewallRule.SourceAddress) {
                        $sourceAddess+=$address
                    }
                }
                $srcSpec.ip_address = $sourceAddess;
    
                # Create Destination Spec
                $destSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Element.destination.Create()
                $destSpec.exclude = $false
                # Process Destination Address from JSON
                $destinationAddess = @()
                if($vmcFirewallRule.DestinationAddress -ne "null") {
                    foreach ($address in $vmcFirewallRule.DestinationAddress) {
                        $destinationAddess+=$address
                    }
                }
                $destSpec.ip_address = $destinationAddess
    
                # Add various specs
                if($vmcFirewallRule.Protocol -ne $null -and $vmcFirewallRule.port -ne $null) {
                    $ruleElementSpec.application = $appSpec
                }
    
                $ruleElementSpec.source = $srcSpec
                $ruleElementSpec.destination = $destSpec
                $ruleElementSpec.rule_type = "user"
    
                # Process Enabled from JSON
                $fwEnabled = $false
                if($vmcFirewallRule.Enabled -eq "true") {
                    $fwEnabled = $true
                }
                $ruleElementSpec.enabled = $fwEnabled
    
                # Process Logging from JSON
                $loggingEnabled = $false
                if($vmcFirewallRule.Logging -eq "true") {
                    $loggingEnabled = $true
                }
                $ruleElementSpec.logging_enabled = $loggingEnabled
    
                $ruleElementSpec.action = $vmcFirewallRule.Action
                $ruleElementSpec.name = $vmcFirewallRule.Name
    
                # Add the individual FW rule spec into our overall firewall rules array
                Write-host "Creating VMC Firewall Rule Spec:" $vmcFirewallRule.Name "..."
                $ruleSpecAdd = $ruleSpec.Add($ruleElementSpec)
            }
            $firewallRules.firewall_rules = $ruleSpec
    
            Write-host "Adding VMC Firewall Rules ..."
            $firewallRuleAdd = $firewallService.add($orgId,$sddcId,$EdgeId,$firewallRules)
        }
    
        Function Remove-VMCFirewallRule {
        <#
            .NOTES
            ===========================================================================
            Created by:     William Lam
            Date:          11/19/2017
            Organization: 	VMware
            Blog:          https://www.virtuallyghetto.com
            Twitter:       @lamw
            ===========================================================================
            .SYNOPSIS
                Removes VMC Firewall Rule given Rule Id
            .DESCRIPTION
                Removes VMC Firewall Rule given Rule Id
            .EXAMPLE
                Remove-VMCFirewallRule -OrgName <Org Name> -SDDCName <SDDC Name> -GatewayType <MGW or CGW> -RuleId <Rule Id>
        #>
            param(
                [Parameter(Mandatory=$false)][String]$SDDCName,
                [Parameter(Mandatory=$false)][String]$OrgName,
                [Parameter(Mandatory=$true)][ValidateSet("MGW","CGW")][String]$GatewayType,
                [Parameter(Mandatory=$false)][String]$RuleId
            )
    
            if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break }
    
            if($GatewayType -eq "MGW") {
                $EdgeId = "edge-1"
            } else {
                $EdgeId = "edge-2"
            }
    
            $orgId = (Get-VMCOrg -Name $OrgName).Id
            $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id
    
            if(-not $orgId) {
                Write-Host -ForegroundColor red "Unable to find Org $OrgName, please verify input"
                break
            }
            if(-not $sddcId) {
                Write-Host -ForegroundColor red "Unable to find SDDC $SDDCName, please verify input"
                break
            }
    
            $firewallService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config.rules
            Write-Host "Removing VMC Firewall Rule Id $RuleId ..."
            $firewallService.delete($orgId,$sddcId,$EdgeId,$RuleId)
        }
    
    Function Get-VMCLogicalNetwork {
        <#
            .NOTES
            ===========================================================================
            Created by:     Kyle Ruddy
            Date:          03/06/2018
            Organization: 	VMware
            Blog:          https://thatcouldbeaproblem.com
            Twitter:       @kmruddy
            ===========================================================================
            .SYNOPSIS
                Retruns VMC Logical Networks for a given SDDC
            .DESCRIPTION
                Retruns VMC Logical Networks for a given SDDC
            .EXAMPLE
                Get-VMCLogicalNetwork -OrgName <Org Name> -SDDCName <SDDC Name> 
            .EXAMPLE
                Get-VMCLogicalNetwork -OrgName <Org Name> -SDDCName <SDDC Name> -LogicalNetworkName <Logical Network Name>
        #>
        param(
            [Parameter(Mandatory=$true)][String]$SDDCName,
            [Parameter(Mandatory=$true)][String]$OrgName,
            [Parameter(Mandatory=$false)][String]$LogicalNetworkName
    
        )
    
        $orgId = (Get-VMCOrg -Name $OrgName).Id
        $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id
    
        if(-not $orgId) {
            Write-Host -ForegroundColor red "Unable to find Org $OrgName, please verify input"
            break
        }
        if(-not $sddcId) {
            Write-Host -ForegroundColor red "Unable to find SDDC $SDDCName, please verify input"
            break
        }
    
        $logicalNetworkService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.logical
    
        $logicalNetworks = ($logicalNetworkService.get_0($orgId, $sddcId)).data | Sort-Object -Property id
    
        if($LogicalNetworkName) {
            $logicalNetworks = $logicalNetworks | Where-Object {$_.Name -eq $LogicalNetworkName}
        }
    
        $results = @()
        foreach ($logicalNetwork in $logicalNetworks) {
            $tmp = [pscustomobject] @{
                ID = $logicalNetwork.id;
                Name = $logicalNetwork.name;
                SubnetMask = $logicalNetwork.subnets.address_groups.prefix_length;
                Gateway = $logicalNetwork.subnets.address_groups.primary_address;
                DHCPipRange = $logicalNetwork.dhcp_configs.ip_pools.ip_range;
                DHCPdomain = $logicalNetwork.dhcp_configs.ip_pools.domain_name;
                CGatewayID = $logicalNetwork.cgw_id;
                CGateway = $logicalNetwork.cgw_name;
            }
            $results+=$tmp
        }
        $results
    }
    
    Function Remove-VMCLogicalNetwork {
        <#
            .NOTES
            ===========================================================================
            Created by:     Kyle Ruddy
            Date:          03/06/2018
            Organization: 	VMware
            Blog:          https://thatcouldbeaproblem.com
            Twitter:       @kmruddy
            ===========================================================================
            .SYNOPSIS
                Removes Logical Network given ID
            .DESCRIPTION
                Removes Logical Network given ID
            .EXAMPLE
                Remove-VMCLogicalNetwork -OrgName <Org Name> -SDDCName <SDDC Name> -LogicalNetworkName <LogicalNetwork Name>
        #>
        [cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact='High')]
        param(
            [Parameter(Mandatory=$true)][String]$SDDCName,
            [Parameter(Mandatory=$true)][String]$OrgName,
            [Parameter(Mandatory=$true)][String]$LogicalNetworkName
        )
    
        if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break }
    
        $orgId = (Get-VMCOrg -Name $OrgName).Id
        $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id
        $lsId = (Get-VMCLogicalNetwork -OrgName $OrgName -SDDCName $SDDCName -LogicalNetworkName $LogicalNetworkName).Id
    
        if(-not $orgId) {
            Write-Host -ForegroundColor red "Unable to find Org $OrgName, please verify input"
            break
        }
        if(-not $sddcId) {
            Write-Host -ForegroundColor red "Unable to find SDDC $SDDCName, please verify input"
            break
        }
        if(-not $lsId) {
            Write-Host -ForegroundColor red "Unable to find SDDC $LogicalNetworkName, please verify input"
            break
        }
    
        $logicalNetworkService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.logical
        $logicalNetworkService.delete($orgId,$sddcId,$lsId)
    }
    
    Function New-VMCLogicalNetwork {
        <#
            .NOTES
            ===========================================================================
            Created by:     Kyle Ruddy
            Date:          03/06/2018
            Organization: 	VMware
            Blog:          https://thatcouldbeaproblem.com
            Twitter:       @kmruddy
            ===========================================================================
            .SYNOPSIS
                Creates a new Logical Network
            .DESCRIPTION
                Creates a new Logical Network
            .EXAMPLE
                New-VMCLogicalNetwork -OrgName <Org Name> -SDDCName <SDDC Name> -LogicalNetworkName <LogicalNetwork Name> -SubnetMask <Subnet Mask Prefix> -Gateway <Gateway IP Address>
        #>
        [cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact='High')]
        param(
            [Parameter(Mandatory=$true)][String]$SDDCName,
            [Parameter(Mandatory=$true)][String]$OrgName,
            [Parameter(Mandatory=$true)][String]$LogicalNetworkName,
            [Parameter(Mandatory=$true)][String]$SubnetMask,
            [Parameter(Mandatory=$true)][String]$Gateway
        )
    
        if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break }
    
        $orgId = (Get-VMCOrg -Name $OrgName).Id
        $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id
        
        if(-not $orgId) {
            Write-Host -ForegroundColor red "Unable to find Org $OrgName, please verify input"
            break
        }
        if(-not $sddcId) {
            Write-Host -ForegroundColor red "Unable to find SDDC $SDDCName, please verify input"
            break
        }
    
        $logicalNetworkService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.logical
        $logicalNetworkSpec = $logicalNetworkService.Help.create.sddc_network.Create()
        $logicalNetworkSpec.name = $LogicalNetworkName
        $logicalNetworkSpec.cgw_id = "edge-2"
        $logicalNetworkSpec.cgw_name = "SDDC-CGW-1"
        $logicalNetworkAddressGroupSpec = $logicalNetworkService.Help.create.sddc_network.subnets.address_groups.Element.Create()
        $logicalNetworkAddressGroupSpec.prefix_length = $SubnetMask
        $logicalNetworkAddressGroupSpec.primary_address = $Gateway
    
        $logicalNetworkSpec.subnets.address_groups.Add($logicalNetworkAddressGroupSpec) | Out-Null
        $logicalNetworkService.create($orgId, $sddcId, $logicalNetworkSpec)
        Get-VMCLogicalNetwork -OrgName $OrgName -SDDCName $SDDCName -LogicalNetworkName $LogicalNetworkName
    }
    
    Function Get-VMCSDDCSummary {
        <#
            .NOTES
            ===========================================================================
            Created by:    VMware
            Date:          09/04/18
            Organization:  VMware
            Blog:          https://www.virtuallyghetto.com
            Twitter:       @lamw
            ===========================================================================
            .SYNOPSIS
                Returns a number of useful informational data about a given SDDC within VMC Org
            .DESCRIPTION
                Returns Version, Create/Expiration Date, Deployment Type, Region, AZ, Instance Type, VPC CIDR & NSX-T
            .EXAMPLE
                Get-VMCSDDCSummary -Name <SDDC Name> -Org <Org Name>
        #>
            Param (
                [Parameter(Mandatory=$True)]$OrgName,
                [Parameter(Mandatory=$True)]$SDDCName
            )
    
            If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else {
                $orgId = (Get-VMCOrg -Name $Org).Id
                $sddcId = (Get-VMCSDDC -Name $Name -Org $Org).Id
    
                $sddcService = Get-VmcService "com.vmware.vmc.orgs.sddcs"
                $sddc = $sddcService.get($orgId,$sddcId)
    
                $results = [pscustomobject] @{
                    Version = $sddc.resource_config.sddc_manifest.vmc_version;
                    CreateDate = $sddc.created;
                    ExpirationDate = $sddc.expiration_date;
                    DeploymentType = $sddc.resource_config.deployment_type;
                    Region = $sddc.resource_config.region;
                    AvailabilityZone = $sddc.resource_config.availability_zones;
                    InstanceType = $sddc.resource_config.sddc_manifest.esx_ami.instance_type;
                    VpcCIDR = $sddc.resource_config.vpc_info.vpc_cidr;
                    NSXT = $sddc.resource_config.nsxt;
                }
                $results
            }
    }
    
    Function Get-VMCPublicIP {
        <#
            .NOTES
            ===========================================================================
            Created by:    William Lam
            Date:          09/12/2018
            Organization:  VMware
            Blog:          http://www.virtuallyghetto.com
            Twitter:       @lamw
            ===========================================================================
            .SYNOPSIS
                Retrieves all public IP Addresses for a given SDDC
            .DESCRIPTION
                This cmdlet retrieves all public IP Address for a given SDDC
            .EXAMPLE
                Get-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName
        #>
            Param (
                [Parameter(Mandatory=$True)]$OrgName,
                [Parameter(Mandatory=$True)]$SDDCName
            )
    
            If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else {
                $orgId = (Get-VMCOrg -Name $OrgName).Id
                $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id
    
                $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips"
                $publicIPs = $publicIPService.list($orgId,$sddcId)
    
                $publicIPs | select public_ip, name, allocation_id
            }
        }
    
        Function New-VMCPublicIP {
        <#
            .NOTES
            ===========================================================================
            Created by:    William Lam
            Date:          09/12/2018
            Organization:  VMware
            Blog:          http://www.virtuallyghetto.com
            Twitter:       @lamw
            ===========================================================================
            .SYNOPSIS
                Request a new public IP Address for a given SDDC
            .DESCRIPTION
                This cmdlet requests a new public IP Address for a given SDDC
            .EXAMPLE
                New-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName -Description "Test for Randy"
        #>
            Param (
                [Parameter(Mandatory=$True)]$OrgName,
                [Parameter(Mandatory=$True)]$SDDCName,
                [Parameter(Mandatory=$False)]$Description
            )
    
            If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else {
                $orgId = (Get-VMCOrg -Name $OrgName).Id
                $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id
    
                $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips"
    
                $publicIPSpec = $publicIPService.Help.create.spec.Create()
                $publicIPSpec.count = 1
                $publicIPSpec.names = @($Description)
    
                Write-Host "Requesting a new public IP Address for your SDDC ..."
                $results = $publicIPService.create($orgId,$sddcId,$publicIPSpec)
            }
        }
    
        Function Remove-VMCPublicIP {
        <#
            .NOTES
            ===========================================================================
            Created by:    William Lam
            Date:          09/12/2018
            Organization:  VMware
            Blog:          http://www.virtuallyghetto.com
            Twitter:       @lamw
            ===========================================================================
            .SYNOPSIS
                Removes a specific public IP Addresses for a given SDDC
            .DESCRIPTION
                This cmdlet removes a specific public IP Address for a given SDDC
            .EXAMPLE
                Remove-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName -AllocationId "eipalloc-0567acf34e436c01f"
        #>
            Param (
                [Parameter(Mandatory=$True)]$OrgName,
                [Parameter(Mandatory=$True)]$SDDCName,
                [Parameter(Mandatory=$True)]$AllocationId
            )
    
            If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else {
                $orgId = (Get-VMCOrg -Name $OrgName).Id
                $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id
    
                $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips"
    
                Write-Host "Deleting public IP Address with ID $AllocationId ..."
                $results = $publicIPService.delete($orgId,$sddcId,$AllocationId)
            }
        }
    
    Export-ModuleMember -Function 'Get-VMCCommand', 'Connect-VMCVIServer', 'Get-VMCOrg', 'Get-VMCSDDC', 'Get-VMCTask', 'Get-VMCSDDCDefaultCredential', 'Get-VMCSDDCPublicIP', 'Get-VMCVMHost', 'Get-VMCSDDCVersion', 'Get-VMCFirewallRule', 'Export-VMCFirewallRule', 'Import-VMCFirewallRule', 'Remove-VMCFirewallRule', 'Get-VMCLogicalNetwork', 'Remove-VMCLogicalNetwork', 'New-VMCLogicalNetwork', 'Get-VMCSDDCSummary', 'Get-VMCPublicIP', 'New-VMCPublicIP', 'Remove-VMCPublicIP'

    As you can see we have new cmd-lets. After you had import the module you can use this cmd-lets

    Get-VMCSDDCSummary -Org $OrgName -Name $SddcName
    List services in VMware Cloud Services Platform using PowerShell
    Function Get-CSPAccessToken {
        <#
            .NOTES
            ===========================================================================
            Created by:     William Lam
            Date:           07/23/2018
            Organization:   VMware
            Blog:           https://www.virtuallyghetto.com
            Twitter:        @lamw
            ===========================================================================
    
            .DESCRIPTION
                Converts a Refresh Token from the VMware Console Services Portal
                to CSP Access Token to access CSP API
            .PARAMETER RefreshToken
                The Refresh Token from the VMware Console Services Portal
            .EXAMPLE
                Get-CSPAccessToken -RefreshToken $RefreshToken
        #>
        Param (
            [Parameter(Mandatory=$true)][String]$RefreshToken
        )
    
        $results = Invoke-WebRequest -Uri "https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize?refresh_token=$RefreshToken" -Method POST -ContentType "application/json" -UseBasicParsing -Headers @{"csp-auth-token"="$RefreshToken"}
        if($results.StatusCode -ne 200) {
            Write-Host -ForegroundColor Red "Failed to retrieve Access Token, please ensure your VMC Refresh Token is valid and try again"
            break
        }
        $accessToken = ($results | ConvertFrom-Json).access_token
        Write-Host "CSP Auth Token has been successfully retrieved and saved to `$env:cspAuthToken"
        $env:cspAuthToken = $accessToken
    }
    
    Function Get-CSPServices {
        <#
            .NOTES
            ===========================================================================
            Created by:     William Lam
            Date:           07/23/2018
            Organization:   VMware
            Blog:           https://www.virtuallyghetto.com
            Twitter:        @lamw
            ===========================================================================
    
            .DESCRIPTION
                Returns the list of CSP Services avialable for given user
            .EXAMPLE
                Get-CSPServices
        #>
        If (-Not $env:cspAuthToken) { Write-error "CSP Auth Token not found, please run Get-CSPAccessToken" } Else {
            $results = Invoke-WebRequest -Uri "https://console.cloud.vmware.com/csp/gateway/slc/api/definitions?expand=1" -Method GET -ContentType "application/json" -UseBasicParsing -Headers @{"csp-auth-token"="$env:cspAuthToken"}
            ((($results.Content) | ConvertFrom-Json).results | where {$_.visible -eq $true}).displayName
        }
    }

    To interact with this API you have first to import the module.

    Import-Module VMware.CSP.psm1
    Get-CSPAccessToken -RefreshToken $RefreshToken
    Get-CSPServices

    Credits @ Vmware

    https://code.vmware.com/samples/4384/list-services-in-vmware-cloud-services-portal-using-powershell

    That’s all for now.

     

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.