-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2,203 changed files
with
234,542 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="nsxt_policyClient.orig" /> | ||
<None Remove="vcenter.json" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="vcenter.json" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="CaseExtensions" Version="1.1.0" /> | ||
<PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="6.0.5"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | ||
<PackageReference Include="NJsonSchema" Version="10.6.10" /> | ||
<PackageReference Include="NSwag.ApiDescription.Client" Version="13.15.10"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="NSwag.Core" Version="13.15.10" /> | ||
<PackageReference Include="Nustache" Version="1.16.0.10" /> | ||
<PackageReference Include="System.Management.Automation" Version="7.2.3" /> | ||
<PackageReference Include="System.Runtime" Version="4.3.1" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace vspheresdk.{{rootmodule}}.Models.Enums | ||
{ | ||
/// <summary> | ||
/// {{ToXmlDoc currentEnum.description}} | ||
/// </summary> | ||
public enum {{currentEnum.EnumName}} | ||
{ | ||
{{#currentEnum.Values}} | ||
[EnumMember(Value = "{{JsonEnumValue}}")] | ||
{{EnumValue}} = {{EnumIndex}}, | ||
{{/currentEnum.Values}} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Newtonsoft.Json; | ||
using System.Collections.Generic; | ||
using System.Collections; | ||
using System.Linq; | ||
using System.ComponentModel; | ||
using NJsonSchema.Converters; | ||
using Newtonsoft.Json.Converters; | ||
using vspheresdk.{{rootmodule}}.Models.Enums; | ||
|
||
namespace vspheresdk.{{rootmodule}}.Models | ||
{ | ||
public class {{clz}} {{referenced}} | ||
{ | ||
{{#properties.Values}} | ||
/// <summary> | ||
/// {{ToXmlDoc description "wrap"}} | ||
/// </summary> | ||
/// </summary> | ||
{{#if isRequired}} | ||
[JsonProperty(PropertyName = "{{name}}", Required = Required.AllowNull)] | ||
{{#else}} | ||
[JsonProperty(PropertyName = "{{name}}")] | ||
{{/if}} | ||
{{#IsEnumeration}} | ||
[JsonConverter(typeof(StringEnumConverter))] | ||
{{/IsEnumeration}} | ||
public {{GetDotNetType . name clz}} {{GetDotNetName name "field"}} { get; set; } | ||
{{/properties.Values}} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using RestSharp; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Threading; | ||
using Newtonsoft.Json; | ||
using System.Net; | ||
using vspheresdk; | ||
using vspheresdk.{{rootmodule}}.Models; | ||
|
||
namespace vspheresdk.{{rootmodule}}.Modules | ||
{ | ||
public class {{module}}Module | ||
{ | ||
private RestClient restClient; | ||
private int retry; | ||
private int timeout; | ||
private CancellationToken cancellationToken; | ||
|
||
public {{module}}Module(RestClient Client, CancellationToken _cancellationToken, int _timeout, int _retry) | ||
{ | ||
restClient = Client; | ||
retry = _retry; | ||
timeout = _timeout; | ||
cancellationToken = _cancellationToken; | ||
} | ||
{{#operations}} | ||
public async {{GetOperationReturnType . "full"}} {{GetMethodName .}}Async({{GetOperationPathParams .}}) | ||
{ | ||
{{#Item4.Parameters}} | ||
{{#isRequired}} | ||
ArgumentNullException.ThrowIfNull({{GetParameterPascalCase name}}, "{{GetParameterPascalCase name}} cannot be null"); | ||
{{/isRequired}} | ||
{{/Item4.Parameters}} | ||
StringBuilder {{GetMethodName .}}ServiceURL = new StringBuilder("{{ GetServiceUrl operations.Current }}"); | ||
var request = new RestRequest | ||
{ | ||
RequestFormat = DataFormat.Json, | ||
Method = Method.{{GetOperationHttpMethod .}} | ||
}; | ||
{{#Item4.Parameters}} | ||
{{GetOperationPathInjectionCode . }} | ||
{{/Item4.Parameters}} | ||
request.Resource = {{GetMethodName .}}ServiceURL.ToString(); | ||
RestResponse{{GetOperationReturnType . "bare"}} response = await restClient.ExecuteTaskAsyncWithPolicy{{GetOperationReturnType . "bare"}}(request, cancellationToken, timeout, retry); | ||
if (response.StatusCode != HttpStatusCode.OK) | ||
{ | ||
var message = "HTTP {{GetOperationHttpMethod .}} operation to " + {{GetMethodName .}}ServiceURL.ToString() + " did not complete successfull"; | ||
throw new vSphereException(message, (int)response.StatusCode, response.Content, response.Headers, response.ErrorException); | ||
} | ||
{{GetOperationReturnType . "return"}} | ||
} | ||
{{/operations}} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// <auto-generated> | ||
// Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
// </auto-generated> | ||
|
||
using nsxtapi; | ||
using vspheresdk.Models; | ||
using vspheresdk.Powershell; | ||
using System.Management.Automation; | ||
using Newtonsoft.Json; | ||
|
||
|
||
namespace nsxtcli.CmdLet | ||
{ | ||
{{#operations}} | ||
{{#each value}} | ||
[Cmdlet({{GetPSVerb . module}})] | ||
{{GetOperationReturnType . "cmdlet"}} | ||
public class {{module}}{{GetMethodName .}}CmdLet : Cmdlet | ||
{ | ||
[Parameter(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 0)] | ||
[ValidateNotNullOrEmpty] | ||
public CredentialParmeters Credentials { get; set; } | ||
{{#each value.parameters}} | ||
[Parameter(Mandatory = {{GetLowerCase isRequired}})] | ||
public {{GetPSValueDefinition . }} { get; set; } | ||
{{/each}} | ||
[Parameter(Mandatory = false)] | ||
public bool PrettyJson { get; set; } | ||
|
||
protected override void ProcessRecord() | ||
{ | ||
NSXTClient _client = new NSXTClient(Credentials._host, Credentials._username, Credentials._password, Credentials._remoteCertificateValidation); | ||
{{GetOperationReturnType . "cmdletreturn" module}} | ||
if (returnobject != null) | ||
{ | ||
if (PrettyJson) | ||
{ | ||
WriteObject(JsonConvert.SerializeObject(returnobject, Formatting.Indented)); | ||
} | ||
else | ||
{ | ||
WriteObject(returnobject); | ||
} | ||
} | ||
} | ||
} | ||
{{/each}} | ||
{{/operations}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// <auto-generated> | ||
// Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
// </auto-generated> | ||
using vspheresdk.ManagerModels; | ||
|
||
namespace vspheresdk.Models | ||
{ | ||
{{#each responses}} | ||
/// <summary> | ||
/// {{ToXmlDoc value.description}} | ||
/// </summary> | ||
[NSXTProperty(Description: @"{{ToXmlDoc value.description}}")] | ||
public class NSXT{{GetResponseName .}}Type : {{GetResponseTypeName value}} | ||
{ | ||
} | ||
{{/each}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using Newtonsoft.Json; | ||
using RestSharp; | ||
using RestSharp.Authenticators; | ||
using RestSharp.Serializers.NewtonsoftJson; | ||
using System; | ||
using System.Linq; | ||
using vspheresdk.Authentication; | ||
|
||
namespace vspheresdk | ||
{ | ||
public class vSphereClient | ||
{ | ||
private RestClient tokenRestClient { get; set; } | ||
private RestClient sessionRestClient { get; set; } | ||
private CancellationToken cancellationToken; | ||
private int timeout; | ||
private int retry; | ||
public LoginResponseType LoginResponseDetails; | ||
|
||
public vSphereClient(string Host, string Username, string Password, bool? RemoteCertificateValidation = true, JsonSerializerSettings? DefaultSerializationSettings = null, CancellationToken _cancellationToken = default(CancellationToken), int Port = 443, int _timeout = 100, int _retry = 2, string _defaultXAviVerion = null) | ||
{ | ||
cancellationToken = _cancellationToken; | ||
timeout = _timeout; | ||
retry = _retry; | ||
|
||
|
||
var tokenUri = new UriBuilder(Host) | ||
{ | ||
Scheme = Uri.UriSchemeHttps, | ||
Port = Port, | ||
}.Uri; | ||
var sessionUri = new UriBuilder(Host) | ||
{ | ||
Scheme = Uri.UriSchemeHttps, | ||
Port = Port, | ||
Path = "" | ||
}.Uri; | ||
var tokenRestOptions = new RestClientOptions() { BaseUrl = tokenUri }; | ||
var sessionRestOptions = new RestClientOptions() { BaseUrl = sessionUri }; | ||
if (!RemoteCertificateValidation ?? false) | ||
{ | ||
tokenRestOptions.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; | ||
sessionRestOptions.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; | ||
}; | ||
tokenRestClient = new RestClient(tokenRestOptions); | ||
sessionRestClient = new RestClient(sessionRestOptions); | ||
sessionRestClient.AcceptedContentTypes = new string[] { "application/json" }; | ||
sessionRestClient.AcceptedContentTypes = new string[] { "application/json" }; | ||
sessionRestClient.Authenticator = new HttpBasicAuthenticator(Username, Password); | ||
|
||
if (DefaultSerializationSettings == null) | ||
{ | ||
DefaultSerializationSettings = new JsonSerializerSettings | ||
{ | ||
Error = (se, ev) => { ev.ErrorContext.Handled = true; }, | ||
DefaultValueHandling = DefaultValueHandling.Include, | ||
TypeNameHandling = TypeNameHandling.Auto, | ||
NullValueHandling = NullValueHandling.Ignore, | ||
Formatting = Formatting.None, | ||
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor, | ||
Converters = new List<JsonConverter>() { new Newtonsoft.Json.Converters.StringEnumConverter() } | ||
}; | ||
}; | ||
tokenRestClient.UseNewtonsoftJson(DefaultSerializationSettings); | ||
sessionRestClient.UseNewtonsoftJson(DefaultSerializationSettings); | ||
} | ||
public async Task<LoginResponseType> LoginAsync() | ||
{ | ||
RestResponse<LoginResponseType> response = await AuthenticationHelper.LoginAsync(sessionRestClient, cancellationToken, timeout, retry); | ||
ArgumentNullException.ThrowIfNull(response.Data.Value); | ||
|
||
tokenRestClient.AddDefaultHeader("vmware-api-session-id", response.Data.Value); | ||
sessionRestClient.AddDefaultHeader("vmware-api-session-id", response.Data.Value); | ||
return response.Data; | ||
} | ||
public async Task LogoutAsync() | ||
{ | ||
await AuthenticationHelper.LogoutAsync(sessionRestClient, cancellationToken, timeout, retry); | ||
} | ||
{{#submodules}} | ||
public {{.}}SubModule {{.}}SubModule => new {{.}}SubModule(tokenRestClient, cancellationToken, timeout, retry); | ||
{{/submodules}} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using RestSharp; | ||
using RestSharp.Authenticators; | ||
using RestSharp.Serializers.NewtonsoftJson; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Serialization; | ||
using vspheresdk.{{rootmodule}}.Modules; | ||
using vspheresdk; | ||
using System.Threading; | ||
|
||
namespace vspheresdk | ||
{ | ||
public class {{rootmodule}}SubModule | ||
{ | ||
JsonSerializerSettings defaultSerializationSettings; | ||
RestClient restClient; | ||
private CancellationToken cancellationToken; | ||
private int timeout; | ||
private int retry; | ||
public {{rootmodule}}SubModule(RestClient RestClient, CancellationToken _cancellationToken = default(CancellationToken), int Port = 443, int _timeout = 5, int _retry = 2) | ||
{ | ||
cancellationToken = _cancellationToken; | ||
timeout = _timeout; | ||
retry = _retry; | ||
restClient = RestClient; | ||
} | ||
{{#modules}} | ||
public {{.}}Module {{.}}Module => new {{.}}Module(restClient, cancellationToken, timeout, retry); | ||
{{/modules}} | ||
} | ||
} |
Oops, something went wrong.