Hi All,
I am trying to fetch the storage profiles but when tried to do so i get an exception of Data Not Found. Can someone please tell me where my code is wrong. Here is my code:
private static vCloudClient client = null;
private static VcloudAdmin admin = null;
private static AdminOrganization SearchAdminOrg(string orgName)
{
try
{
ReferenceType orgRef = admin.GetAdminOrgRefsByName()[orgName];
return AdminOrganization.GetAdminOrgByReference(client, orgRef);
}
catch (Exception ex)
{
throw new VCloudException(ex.Message);
}
}
private static bool ValidateServerCertificate(object sender, X509Certificate
certificate, X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
return true;
}
/// <summary>
/// Defined a fake certificate policy for accepting the certificate temporarily
/// </summary>
public static void FakeCertificatePolicy()
{
ServicePointManager.ServerCertificateValidationCallback += new System.Net.
Security.RemoteCertificateValidationCallback(ValidateServerCertificate);
}
protected void Button1_click(object sender, EventArgs e)
{
try
{
FakeCertificatePolicy();
// here we can set the level
Logger.SourceLevel(Levels.All);
Console.WriteLine("Vcloud Login");
client = new vCloudClient("https://10.109.0.121", com.vmware.vcloud.sdk.constants.Version.V5_1);
string username = "admin@BITS";
string password = "VMware123";
client.Login(username,password);
Console.WriteLine(" Login Success\n");
Console.WriteLine("Get Vcloud Admin");
admin = client.GetVcloudAdmin();
Console.WriteLine(" " + admin.Resource.href + "\n");
Console.WriteLine("Get Admin Organization");
AdminOrganization adminOrg = SearchAdminOrg("BITS");
ReferenceType VdcRef = adminOrg.GetAdminVdcRefByName("BITSvDC");
Vdc vdc = Vdc.GetVdcByReference(client,VdcRef);
List<ReferenceType> storageref = vdc.GetVdcStorageProfileRefs();
string[] sto = new string[storageref.Count()];
int i = 0;
foreach (ReferenceType stor in storageref)
{
if (storageref.Count() == i)
{
sto[i] = stor.name;
i++;
Console.WriteLine(sto[i]);
}
}
DropDownList1.DataSource = null;
DropDownList1.DataSource = sto;
DropDownList1.DataBind();
}
catch(Exception em)
{
Logger.Log(TraceLevel.Critical, em.Message);
throw new IOException(em.Message);
}
}