Skip to content

Commit

Permalink
timeout fix
Browse files Browse the repository at this point in the history
  • Loading branch information
phspies committed May 17, 2022
1 parent d6413fd commit 5bc0fef
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 163 deletions.
3 changes: 1 addition & 2 deletions SDKGenerator/Templates/SubModule.cs.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ 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)
public {{rootmodule}}SubModule(RestClient RestClient, CancellationToken _cancellationToken = default(CancellationToken), int _timeout = 5, int _retry = 2)
{
cancellationToken = _cancellationToken;
timeout = _timeout;
Expand Down
220 changes: 76 additions & 144 deletions vSphereSDKTesting/BasicTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -18,196 +19,127 @@ public async void Test1()
vSphereClient vsphere = new vSphereClient("vc01.lab.local", "[email protected]", "VMware1!", false);
await vsphere.LoginAsync();
var vms = await vsphere.VcenterSubModule.VMModule.ListAsync();
var templateimage = await vsphere.VcenterSubModule.VMModule.GetAsync(vms.Single(x => x.Name.Equals("ubuntutemplate")).Vm);
var clusters = await vsphere.VcenterSubModule.ClusterModule.ListAsync();
var cluster = clusters.Single(x => x.Name.Equals("BaseCluster01"));
var datacenters = await vsphere.VcenterSubModule.DatacenterModule.ListAsync();
var datacenter = await vsphere.VcenterSubModule.DatacenterModule.GetAsync(datacenters.First().Datacenter);
var libids = await vsphere.LibrarySubModule.LibraryModule.ListAsync();
List<ContentLibraryModelType> libs = new List<ContentLibraryModelType>();
foreach (string id in libids)
{
libs.Add(await vsphere.LibrarySubModule.LibraryModule.GetAsync(id));
}
var templateid = await vsphere.LibrarySubModule.LibraryItemModule.ListAsync(libs.Single(x => x.Name == "Templates").Id);
var template = await vsphere.LibrarySubModule.LibraryItemModule.GetAsync(templateid.First());
var testvm = await vsphere.VcenterSubModule.VMModule.GetAsync(vms[0].Vm);

var resourcepools = await vsphere.VcenterSubModule.ResourcePoolModule.ListAsync();
var resourcepools = await vsphere.VcenterSubModule.ResourcePoolModule.ListAsync(Clusters: cluster.Cluster);
var rpdetails = await vsphere.VcenterSubModule.ResourcePoolModule.GetAsync(resourcepools[0].ResourcePool);

//create base resource pool
var createrp = await vsphere.VcenterSubModule.ResourcePoolModule.CreateAsync(
new VcenterResourcePoolCreateType()
{
Parent = resourcepools[0].ResourcePool,
Name = "TestCodeResourcePool",
CpuAllocation = new VcenterResourcePoolResourceAllocationCreateSpecType()
{
ExpandableReservation = true,
Limit = 300,
Reservation = 0,
Shares = new VcenterResourcePoolSharesInfoType()
{
Level = VcenterResourcePoolSharesInfoLevelEnumType.NORMAL
}
},
MemoryAllocation = new VcenterResourcePoolResourceAllocationCreateSpecType()
{
ExpandableReservation = true,
Limit = 50,
Reservation = 0,
Shares = new VcenterResourcePoolSharesInfoType()
{
Level = VcenterResourcePoolSharesInfoLevelEnumType.NORMAL
}
}
}
);
Assert.NotNull(createrp);

//create nested resource pool
var createrp2 = await vsphere.VcenterSubModule.ResourcePoolModule.CreateAsync(
new VcenterResourcePoolCreateType()
{
Parent = createrp,
Name = "NestedTestCodeResourcePool",
CpuAllocation = new VcenterResourcePoolResourceAllocationCreateSpecType()
{
ExpandableReservation = true,
Limit = 300,
Reservation = 0,
Shares = new VcenterResourcePoolSharesInfoType()
{
Level = VcenterResourcePoolSharesInfoLevelEnumType.NORMAL
}
},
MemoryAllocation = new VcenterResourcePoolResourceAllocationCreateSpecType()
{
ExpandableReservation = true,
Limit = 50,
Reservation = 0,
Shares = new VcenterResourcePoolSharesInfoType()
{
Level = VcenterResourcePoolSharesInfoLevelEnumType.NORMAL
}
}
}
);
Assert.NotNull(createrp2);

await Task.Delay(10000);
//delete nested resource pools
await vsphere.VcenterSubModule.ResourcePoolModule.DeleteAsync(createrp);

var networkList = await vsphere.VcenterSubModule.NetworkModule.ListAsync();
var hostList = await vsphere.VcenterSubModule.HostModule.ListAsync();
var clusterList = await vsphere.VcenterSubModule.ClusterModule.ListAsync();
var datatoreList = await vsphere.VcenterSubModule.DatastoreModule.ListAsync();
var storagepolicyList = await vsphere.VcenterSubModule.StoragePoliciesModule.ListAsync();


var createCustSpec = await vsphere.VcenterSubModule.GuestCustomizationSpecsModule.CreateAsync(new VcenterGuestCustomizationSpecsCreateType()
{
Name = "TestCodeCustomization",
Spec = new VcenterGuestCustomizationSpecType()
{
Interfaces = new Dictionary<string, VcenterGuestAdapterMappingType>() {
{
"2000", new VcenterGuestAdapterMappingType() {
Adapter = new VcenterGuestIpsettingsType()
{
Ipv4 = new VcenterGuestIpv4Type()
{
IpAddress = "10.200.0.10",
Prefix = 24,
Gateways = new List<string>() { "10.0.0.1" },
Type = VcenterGuestIpv4TypeEnum.STATIC
},
Windows = new VcenterGuestWindowsNetworkAdapterSettingsType()
{

}

}

}
}
},
ConfigurationSpec = new VcenterGuestConfigurationSpecType()
{
CloudConfig = new VcenterGuestCloudConfigurationType()
{
Cloudinit = new VcenterGuestCloudinitConfigurationType()
{
Metadata = "",
Userdata = ""
}
}
}
}
});



string deployedVM = await vsphere.VcenterSubModule.VmTemplateLibraryItemsModule.DeployAsync("item", new VcenterVmTemplateLibraryItemsDeployType()
var cloneVMObject = new VcenterVmTemplateLibraryItemsDeployType()
{
Name = "testdeployVM",
Description = "Test deployment VM for SDK",
Placement = new VcenterVmTemplateLibraryItemsDeployPlacementSpecType()
{
Cluster = "cluster",
ResourcePool = "ResourcePool"
Cluster = clusterList.Single(x => x.Name.Equals("BaseCluster01")).Cluster,
ResourcePool = resourcepools[0].ResourcePool,
Folder = datacenter.VmFolder
},
DiskStorage = new VcenterVmTemplateLibraryItemsDeploySpecDiskStorageType()
{
Datastore = "datastorename",
Datastore = datatoreList.Single(x => x.Name.Equals("BaseCluster-datastore")).Datastore,
StoragePolicy = new VcenterVmTemplateLibraryItemsDeploySpecDiskStoragePolicyType()
{
Policy = "policyname",
Policy = storagepolicyList.Single(x => x.Name.Equals("Default TKG Storage Policy")).Policy,
Type = VcenterVmTemplateLibraryItemsDeploySpecDiskStoragePolicyTypeEnum.USESPECIFIEDPOLICY
}
},
GuestCustomization = new VcenterVmTemplateLibraryItemsGuestCustomizationSpecType()
{
Name = "customizationspecname"
},
PoweredOn = true,
HardwareCustomization = new VcenterVmTemplateLibraryItemsHardwareCustomizationSpecType()
{
CpuUpdate = new VcenterVmTemplateLibraryItemsCpuUpdateSpecType()
{
NumCoresPerSocket = 1,
NumCpus = 1
NumCoresPerSocket = 2,
NumCpus = 2
},
MemoryUpdate = new VcenterVmTemplateLibraryItemsMemoryUpdateSpecType()
{
Memory = 4096
},
Nics = new Dictionary<string, VcenterVmTemplateLibraryItemsEthernetUpdateSpecType>()
{
{
"200",
new VcenterVmTemplateLibraryItemsEthernetUpdateSpecType()
{
Network = "network"
}
}
}
{
{
templateimage.Nics.First().Key,
new VcenterVmTemplateLibraryItemsEthernetUpdateSpecType()
{
Network = networkList.Single(x => x.Name.Equals("BaseNetwork")).Network
}
}
}
}
});
string clonedVM = await vsphere.VcenterSubModule.VMModule.CloneAsync(new VcenterVmcloneType()
{
GuestCustomizationSpec = new VcenterVmguestCustomizationSpecType()
{
Name = "TestCodeCustomization"
},
Source = "test",
Placement = new VcenterVmclonePlacementSpecType()
{
Cluster = "Cluster",
Datastore = "datastore",
ResourcePool = "resource pool"
},
Name = "Name",
};

var json = JsonConvert.SerializeObject(cloneVMObject, Formatting.Indented);

});
string deployedVM = await vsphere.VcenterSubModule.VmTemplateLibraryItemsModule.DeployAsync(template.Id, cloneVMObject);


await vsphere.VcenterSubModule.VmPowerModule.StopAsync(deployedVM);
await vsphere.VcenterSubModule.VMModule.DeleteAsync(deployedVM);
await vsphere.LogoutAsync();



//var createCustSpec = await vsphere.VcenterSubModule.GuestCustomizationSpecsModule.CreateAsync(new VcenterGuestCustomizationSpecsCreateType()
//{
// Name = "TestCodeCustomization",
// Spec = new VcenterGuestCustomizationSpecType()
// {
// Interfaces = new Dictionary<string, VcenterGuestAdapterMappingType>() {
// {
// "2000", new VcenterGuestAdapterMappingType() {
// Adapter = new VcenterGuestIpsettingsType()
// {
// Ipv4 = new VcenterGuestIpv4Type()
// {
// IpAddress = "10.200.0.10",
// Prefix = 24,
// Gateways = new List<string>() { "10.0.0.1" },
// Type = VcenterGuestIpv4TypeEnum.STATIC
// },
// Windows = new VcenterGuestWindowsNetworkAdapterSettingsType()
// {

// }

// }

// }
// }
// },
// ConfigurationSpec = new VcenterGuestConfigurationSpecType()
// {
// CloudConfig = new VcenterGuestCloudConfigurationType()
// {
// Cloudinit = new VcenterGuestCloudinitConfigurationType()
// {
// Metadata = "",
// Userdata = ""
// }
// }
// }
// }
//});

}
}
}
3 changes: 1 addition & 2 deletions vspheresdk/ApplianceModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ namespace vspheresdk
{
public class ApplianceSubModule
{
JsonSerializerSettings defaultSerializationSettings;
RestClient restClient;
private CancellationToken cancellationToken;
private int timeout;
private int retry;
public ApplianceSubModule(RestClient RestClient, CancellationToken _cancellationToken = default(CancellationToken), int Port = 443, int _timeout = 5, int _retry = 2)
public ApplianceSubModule(RestClient RestClient, CancellationToken _cancellationToken = default(CancellationToken), int _timeout = 5, int _retry = 2)
{
cancellationToken = _cancellationToken;
timeout = _timeout;
Expand Down
3 changes: 1 addition & 2 deletions vspheresdk/CisModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ namespace vspheresdk
{
public class CisSubModule
{
JsonSerializerSettings defaultSerializationSettings;
RestClient restClient;
private CancellationToken cancellationToken;
private int timeout;
private int retry;
public CisSubModule(RestClient RestClient, CancellationToken _cancellationToken = default(CancellationToken), int Port = 443, int _timeout = 5, int _retry = 2)
public CisSubModule(RestClient RestClient, CancellationToken _cancellationToken = default(CancellationToken), int _timeout = 5, int _retry = 2)
{
cancellationToken = _cancellationToken;
timeout = _timeout;
Expand Down
3 changes: 1 addition & 2 deletions vspheresdk/EsxModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ namespace vspheresdk
{
public class EsxSubModule
{
JsonSerializerSettings defaultSerializationSettings;
RestClient restClient;
private CancellationToken cancellationToken;
private int timeout;
private int retry;
public EsxSubModule(RestClient RestClient, CancellationToken _cancellationToken = default(CancellationToken), int Port = 443, int _timeout = 5, int _retry = 2)
public EsxSubModule(RestClient RestClient, CancellationToken _cancellationToken = default(CancellationToken), int _timeout = 5, int _retry = 2)
{
cancellationToken = _cancellationToken;
timeout = _timeout;
Expand Down
3 changes: 1 addition & 2 deletions vspheresdk/HvcModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ namespace vspheresdk
{
public class HvcSubModule
{
JsonSerializerSettings defaultSerializationSettings;
RestClient restClient;
private CancellationToken cancellationToken;
private int timeout;
private int retry;
public HvcSubModule(RestClient RestClient, CancellationToken _cancellationToken = default(CancellationToken), int Port = 443, int _timeout = 5, int _retry = 2)
public HvcSubModule(RestClient RestClient, CancellationToken _cancellationToken = default(CancellationToken), int _timeout = 5, int _retry = 2)
{
cancellationToken = _cancellationToken;
timeout = _timeout;
Expand Down
2 changes: 1 addition & 1 deletion vspheresdk/Library/Modules/libraryitem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public async Task<List<string>> FindAsync(ContentLibraryItemFindType RequestBody
public async Task<List<string>> ListAsync(string LibraryId)
{
ArgumentNullException.ThrowIfNull(LibraryId, "LibraryId cannot be null");
StringBuilder ListServiceURL = new StringBuilder("/api/content/library/item?library_id");
StringBuilder ListServiceURL = new StringBuilder("/api/content/library/item");
var request = new RestRequest
{
RequestFormat = DataFormat.Json,
Expand Down
3 changes: 1 addition & 2 deletions vspheresdk/LibraryModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ namespace vspheresdk
{
public class LibrarySubModule
{
JsonSerializerSettings defaultSerializationSettings;
RestClient restClient;
private CancellationToken cancellationToken;
private int timeout;
private int retry;
public LibrarySubModule(RestClient RestClient, CancellationToken _cancellationToken = default(CancellationToken), int Port = 443, int _timeout = 5, int _retry = 2)
public LibrarySubModule(RestClient RestClient, CancellationToken _cancellationToken = default(CancellationToken), int _timeout = 5, int _retry = 2)
{
cancellationToken = _cancellationToken;
timeout = _timeout;
Expand Down
3 changes: 1 addition & 2 deletions vspheresdk/StatsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ namespace vspheresdk
{
public class StatsSubModule
{
JsonSerializerSettings defaultSerializationSettings;
RestClient restClient;
private CancellationToken cancellationToken;
private int timeout;
private int retry;
public StatsSubModule(RestClient RestClient, CancellationToken _cancellationToken = default(CancellationToken), int Port = 443, int _timeout = 5, int _retry = 2)
public StatsSubModule(RestClient RestClient, CancellationToken _cancellationToken = default(CancellationToken), int _timeout = 5, int _retry = 2)
{
cancellationToken = _cancellationToken;
timeout = _timeout;
Expand Down
3 changes: 1 addition & 2 deletions vspheresdk/VapiModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ namespace vspheresdk
{
public class VapiSubModule
{
JsonSerializerSettings defaultSerializationSettings;
RestClient restClient;
private CancellationToken cancellationToken;
private int timeout;
private int retry;
public VapiSubModule(RestClient RestClient, CancellationToken _cancellationToken = default(CancellationToken), int Port = 443, int _timeout = 5, int _retry = 2)
public VapiSubModule(RestClient RestClient, CancellationToken _cancellationToken = default(CancellationToken), int _timeout = 5, int _retry = 2)
{
cancellationToken = _cancellationToken;
timeout = _timeout;
Expand Down
Loading

0 comments on commit 5bc0fef

Please sign in to comment.