Skip to content

Commit

Permalink
Merge pull request #59 from ggoodvmw/master
Browse files Browse the repository at this point in the history
Upgrade NSX-T libraries to M7
  • Loading branch information
kunalpmj authored May 30, 2019
2 parents 75124b9 + f36ba08 commit 7f01715
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 12 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,15 @@ The API documentation can be accessed from here:

[VMware Cloud on AWS APIs](https://vmware.github.io/vsphere-automation-sdk-java/vmc/index.html).

[VMware NSX-T APIs](https://vmware.github.io/vsphere-automation-sdk-java/nsx/nsx/index.html).
[VMware NSX-T Manager APIs (for on-prem customers)](https://vmware.github.io/vsphere-automation-sdk-java/nsx/nsx/index.html).

[VMware NSX-T Policy APIs](https://vmware.github.io/vsphere-automation-sdk-java/nsx/nsx-policy/index.html).
[VMware NSX-T Policy APIs (for on-prem customers)](https://vmware.github.io/vsphere-automation-sdk-java/nsx/nsx-policy/index.html).

[VMware NSX-T VMC app APIs](https://vmware.github.io/vsphere-automation-sdk-java/nsx/vmc-app/index.html).
[VMware NSX-T Policy APIs (for VMC customers)](https://vmware.github.io/vsphere-automation-sdk-java/nsx/nsx-vmc-policy/index.html).

[VMware NSX-T VMC AWS Integration APIs (for VMC customers)](https://vmware.github.io/vsphere-automation-sdk-java/nsx/nsx-vmc-aws-integration/index.html).

[VMware NSX-T VMC Common APIs (for VMC customers)](https://vmware.github.io/vsphere-automation-sdk-java/nsx/nsx-vmc-sdk-common/index.html).

## Submitting samples

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed lib/vmc-app-java-sdk-2.3.0.0.2.11053635-javadoc.jar
Binary file not shown.
Binary file removed lib/vmc-app-java-sdk-2.3.0.0.2.11053635.jar
Binary file not shown.
52 changes: 43 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
<vspherewssdk.version>6.7.2</vspherewssdk.version>
<vmc.version>1.4.0</vmc.version>
<vsphereautomationsdk.version>3.0.0</vsphereautomationsdk.version>
<nsxpolicysdk.version>2.3.0.0.2.11053635</nsxpolicysdk.version>
<vmcappsdk.version>2.3.0.0.2.11053635</vmcappsdk.version>
<nsxpolicysdk.version>2.3.0.0.3.13851140</nsxpolicysdk.version>
<nsxvmcawsint.version>2.3.0.0.3.13851140</nsxvmcawsint.version>
<nsxvmcsdkcommon.version>2.3.0.0.3.13851140</nsxvmcsdkcommon.version>
</properties>
<build>
<plugins>
Expand Down Expand Up @@ -190,17 +191,45 @@
</configuration>
</execution>
<execution>
<id>install-vmc-app-sdk</id>
<id>install-nsx-vmc-policy-sdk</id>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<groupId>com.vmware.nsx</groupId>
<artifactId>vmc-app-java-sdk</artifactId>
<version>${vmcappsdk.version}</version>
<file>./lib/vmc-app-java-sdk-${vmcappsdk.version}.jar</file>
<artifactId>nsx-vmc-policy-java-sdk</artifactId>
<version>${nsxpolicysdk.version}</version>
<file>./lib/nsx-vmc-policy-java-sdk-${nsxpolicysdk.version}.jar</file>
</configuration>
</execution>
<execution>
<id>install-nsx-vmc-aws-integration-sdk</id>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<groupId>com.vmware.nsx</groupId>
<artifactId>nsx-vmc-aws-integration-sdk</artifactId>
<version>${nsxvmcawsint.version}</version>
<file>./lib/nsx-vmc-aws-integration-java-sdk-${nsxvmcawsint.version}.jar</file>
</configuration>
</execution>
<execution>
<id>install-nsx-vmc-sdk-common</id>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<groupId>com.vmware.nsx</groupId>
<artifactId>nsx-vmc-sdk-common</artifactId>
<version>${nsxvmcsdkcommon.version}</version>
<file>./lib/nsx-vmc-sdk-common-${nsxvmcsdkcommon.version}.jar</file>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -284,13 +313,18 @@
</dependency>
<dependency>
<groupId>com.vmware.nsx</groupId>
<artifactId>nsx-policy-java-sdk</artifactId>
<artifactId>nsx-vmc-policy-java-sdk</artifactId>
<version>${nsxpolicysdk.version}</version>
</dependency>
<dependency>
<groupId>com.vmware.nsx</groupId>
<artifactId>vmc-app-java-sdk</artifactId>
<version>${vmcappsdk.version}</version>
<artifactId>nsx-vmc-aws-integration-sdk</artifactId>
<version>${nsxvmcawsint.version}</version>
</dependency>
<dependency>
<groupId>com.vmware.nsx</groupId>
<artifactId>nsx-vmc-sdk-common</artifactId>
<version>${nsxvmcsdkcommon.version}</version>
</dependency>
<dependency>
<groupId>com.vmware.vim25</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* *******************************************************
* Copyright VMware, Inc. 2019. All Rights Reserved.
* SPDX-License-Identifier: MIT
* *******************************************************
*
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
*/
package vmware.samples.common.authentication;

import com.vmware.nsx_vmc.client.VmcNsxClients;
import com.vmware.vapi.client.ApiClient;

/**
* Helper class which provides methods for creating a new <code>ApiClient</code>
* for VMC APIs
*/
public class VmcNsxAuthenticationHelper {
public static final String CSP_AUTHORIZATION_URL = "/csp/gateway/am/api/auth/api-tokens/authorize";

/**
* Instantiates an ApiClient using a refresh token which can be used for
* creating stubs.
*
* @param refreshToken
* refresh token of the user
* @param verifyServerCertificate
* if true, verify the server's certificate
* @param verifyServerHostname
* if true, verify the server's hostname
* @return
*/
public ApiClient newVmcNsxPolicyClient(String organizationId, String sddcId,
String refreshToken, boolean verifyServerCertificate,
boolean verifyServerHostname) {
return VmcNsxClients.custom()
.setRefreshToken(refreshToken.toCharArray())
.setOrganizationId(organizationId).setSddcId(sddcId)
.setVerifyServerCertificate(verifyServerCertificate)
.setVerifyServerHostname(verifyServerHostname).build();
}
}
127 changes: 127 additions & 0 deletions src/main/java/vmware/samples/vmc/networks/NsxTAuth.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* *******************************************************
* Copyright VMware, Inc. 2018. All Rights Reserved.
* SPDX-License-Identifier: MIT
* *******************************************************
*
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
*/

package vmware.samples.vmc.networks;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.cli.Option;

import com.vmware.nsx_policy.Infra;
import com.vmware.nsx_policy.infra.Domains;
import com.vmware.nsx_policy.model.DomainListResult;
import com.vmware.nsx_vmc_app.infra.LinkedVpcs;
import com.vmware.nsx_vmc_app.model.LinkedVpcsListResult;
import com.vmware.vapi.client.ApiClient;

import vmware.samples.common.VmcSamplesAbstractBase;
import vmware.samples.common.authentication.VmcNsxAuthenticationHelper;

/*-
* This example shows how to authenticate to the VMC (VMware Cloud on AWS)
* service, using a VMC refresh token to obtain an authentication token that
* can then be used to authenticate to the NSX-T instance in a Software
* Defined Data Center (SDDC). It also shows how to list several types
* of entities.
*/
public class NsxTAuth extends VmcSamplesAbstractBase {

private String orgId;
private String sddcId;
private ApiClient apiClient;
private Infra infraService;
private Domains domainsService;
private LinkedVpcs lvpcService;

public static String VMC_SERVER = "vmc.vmware.com";
public static String CSP_SERVER = "console.cloud.vmware.com";

/**
* Define the options specific to this sample and configure the sample using
* command-line arguments or a config file
*
* @param args command line arguments passed to the sample
*/
@Override
protected void parseArgs(String[] args) {
Option orgOption = Option.builder()
.longOpt("org_id")
.desc("Specify the organization id")
.argName("ORGANIZATION ID")
.required(true)
.hasArg()
.build();
Option sddcOption = Option.builder()
.longOpt("sddc_id")
.desc("Specify the SDDC id")
.argName("SDDC ID")
.required(true)
.hasArg()
.build();
List<Option> optionList =
Arrays.asList(orgOption, sddcOption);

super.parseArgs(optionList, args);
this.orgId = (String) parsedOptions.get("org_id");
this.sddcId = (String) parsedOptions.get("sddc_id");
}

@Override
protected void setup() throws Exception {
// Create the API client. This client will automatically obtain
// and use an authentication token from the VMC CSP service,
// and will automatically refresh it when it expires.
this.apiClient = new VmcNsxAuthenticationHelper()
.newVmcNsxPolicyClient(this.orgId,
this.sddcId, this.refreshToken,
false, false);
this.infraService = apiClient.createStub(Infra.class);
this.domainsService = apiClient.createStub(Domains.class);
this. lvpcService = apiClient.createStub(LinkedVpcs.class);
}

public void listDomains() {
com.vmware.nsx_policy.model.Infra infra = this.infraService.get(null);
System.out.println(infra);

DomainListResult domainsList = this.domainsService.list(null, null, 1000L, false, null);
System.out.println(domainsList);

LinkedVpcsListResult results = this.lvpcService.list();
System.out.println(results);
}

@Override
protected void run() throws Exception {
listDomains();
}

@Override
protected void cleanup() throws Exception {
}

public static void main(String[] args) throws Exception {
/*
* Execute the sample using the command line arguments or parameters
* from the configuration file. This executes the following steps:
* 1. Parse the arguments required by the sample
* 2. Login to the server
* 3. Setup any resources required by the sample run
* 4. Run the sample
* 5. Cleanup any data created by the sample run, if cleanup=true
* 6. Logout of the server
*/
new NsxTAuth().execute(args);
}
}

0 comments on commit 7f01715

Please sign in to comment.