Ejemplo n.º 1
0
 private static Dictionary <string, ResourcePoolType> GetResourcePools(
     vCloudClient client,
     string url)
 {
     try
     {
         Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.GET_URL_MSG) + " - " + url);
         RestUtil.Get(client, url);
         ResourcePoolListType resourcePoolListType        = SdkUtil.Get <ResourcePoolListType>(client, url, 200);
         Dictionary <string, ResourcePoolType> dictionary = new Dictionary <string, ResourcePoolType>();
         if (resourcePoolListType != null && resourcePoolListType.ResourcePool != null)
         {
             foreach (ResourcePoolType resourcePoolType in resourcePoolListType.ResourcePool)
             {
                 if (!dictionary.ContainsKey(resourcePoolType.name))
                 {
                     dictionary.Add(resourcePoolType.name, resourcePoolType);
                 }
             }
         }
         return(dictionary);
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Ejemplo n.º 2
0
 public static AdminService GetAdminServiceByReference(
     vCloudClient client,
     ReferenceType reference)
 {
     Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.GET_URL_MSG) + " - " + reference.href);
     return(new AdminService(client, VcloudResource <AdminServiceType> .GetResourceByReference(client, reference)));
 }
Ejemplo n.º 3
0
 public string GetOVFDownloadURL()
 {
     try
     {
         string str = string.Empty;
         if (this.Resource.Link != null)
         {
             foreach (LinkType linkType in this.Resource.Link)
             {
                 if (linkType.rel.Equals("download:default"))
                 {
                     str = linkType.href;
                     break;
                 }
             }
         }
         if (str.Trim().Length == 0)
         {
             throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.NO_DOWNLOAD_LINK_MSG));
         }
         return(str);
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
 public static AdminServiceResource GetAdminServiceResourceById(
     vCloudClient client,
     string vCloudId)
 {
     Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.GET_VCLOUD_ID_MSG) + " - " + vCloudId);
     return(new AdminServiceResource(client, VcloudEntity <ServiceResourceType> .GetEntityById(client, vCloudId, "application/vnd.vmware.admin.serviceResource+xml")));
 }
Ejemplo n.º 5
0
        public Task CreateTask(TaskType taskType)
        {
            string requestString = SerializationUtil.SerializeObject <TaskType>(taskType, "com.vmware.vcloud.api.rest.schema");

            Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.POST_URL_MSG) + " - " + this.GetTasksListRef().href);
            return(new Task(this.VcloudClient, SdkUtil.Post <TaskType>(this.VcloudClient, this.GetTasksListRef().href, requestString, "application/vnd.vmware.vcloud.task+xml", 200)));
        }
Ejemplo n.º 6
0
 public Stream DownloadFile(string fileName)
 {
     try
     {
         Stream stream = (Stream)null;
         if (this.Resource.Link != null)
         {
             foreach (LinkType linkType in this.Resource.Link)
             {
                 if (linkType.rel.Equals("download:default"))
                 {
                     return(this.DownloadFile(fileName, linkType.href));
                 }
             }
         }
         if (stream == null)
         {
             throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.NO_DOWNLOAD_LINK_MSG));
         }
         return(stream);
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Ejemplo n.º 7
0
 public VimObjectRefType GetVMVimRef()
 {
     try
     {
         if (this.Resource != null && this.Resource.VCloudExtension != null)
         {
             foreach (VCloudExtensionType vcloudExtensionType in this.Resource.VCloudExtension)
             {
                 if (vcloudExtensionType.Any != null)
                 {
                     foreach (XmlNode xmlNode in vcloudExtensionType.Any)
                     {
                         VmVimInfoType resource = Response.GetResource <VmVimInfoType>(xmlNode.OuterXml);
                         if (resource.VmVimObjectRef.VimObjectType.Equals(VimObjectTypeEnum.VIRTUAL_MACHINE.Value()))
                         {
                             return(resource.VmVimObjectRef);
                         }
                     }
                 }
             }
         }
         throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.VIM_OBJECT_REF_NOT_FOUND_MSG));
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Ejemplo n.º 8
0
        public void SsoLogin(string samlAssertionXML, string orgName)
        {
            HttpClient httpClient = this.HttpClient;

            httpClient.DefaultRequestHeaders.Clear();
            string str = this.GZipEncodeXmlToString(samlAssertionXML);

            if (orgName.Equals("System", StringComparison.OrdinalIgnoreCase))
            {
                httpClient.DefaultRequestHeaders.Add("Authorization", "SIGN token=\"" + str + "\"");
            }
            else
            {
                httpClient.DefaultRequestHeaders.Add("Authorization", "SIGN token=\"" + str + "\",org=\"" + orgName + "\"");
            }
            httpClient.DefaultRequestHeaders.Add("Accept", vCloudClient.SUPPORTED_SDK_VERSIONS[this.VcloudClientVersion]);
            HttpRequestHeaders defaultRequestHeaders = httpClient.DefaultRequestHeaders;
            VersionInfoType    supportedVersion      = this.GetSupportedVersions()[this._vcloudClientVersion.Value()];

            if (supportedVersion == null)
            {
                throw new VCloudException(this._vcloudClientVersion.Value() + " " + SdkUtil.GetI18nString(SdkMessage.VERSION_NOT_SUPPORTED));
            }
            Response response = RestUtil.Login(this, supportedVersion.LoginUrl, defaultRequestHeaders);

            if (!response.IsExpected(200))
            {
                response.HandleUnExpectedResponse();
            }
            SessionType resource = response.GetResource <SessionType>();

            this.setOrgName(resource.org);
            this.setUserName(resource.user);
        }
Ejemplo n.º 9
0
 public VimObjectRefType GetNetworkVimRef(string vAppNetworkName)
 {
     try
     {
         VAppNetworkConfigurationType configurationByName = this.GetVappNetworkConfigurationByName(vAppNetworkName);
         if (configurationByName != null && configurationByName.VCloudExtension != null)
         {
             foreach (VCloudExtensionType vcloudExtensionType in configurationByName.VCloudExtension)
             {
                 if (vcloudExtensionType.Any != null)
                 {
                     XmlElement[] any   = vcloudExtensionType.Any;
                     int          index = 0;
                     if (index < any.Length)
                     {
                         return(Response.GetResource <VimObjectRefType>(any[index].OuterXml));
                     }
                 }
             }
         }
         throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.VIM_OBJECT_REF_NOT_FOUND_MSG));
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Ejemplo n.º 10
0
 public Task UpdateDisk(string name, string description, ReferenceType storageProfileRef)
 {
     try
     {
         string href = this.Resource.href;
         if (name != null)
         {
             this.Resource.name = name;
         }
         if (description != null)
         {
             this.Resource.Description = description;
         }
         if (storageProfileRef != null)
         {
             this.Resource.StorageProfile = storageProfileRef;
         }
         string requestString = SerializationUtil.SerializeObject <DiskType>(this.Resource, "com.vmware.vcloud.api.rest.schema");
         Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.PUT_URL_MSG) + " - " + href);
         return(new Task(this.VcloudClient, SdkUtil.Put <TaskType>(this.VcloudClient, href, requestString, "application/vnd.vmware.vcloud.disk+xml", 202)));
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Ejemplo n.º 11
0
 public VimObjectRefType GetResourcePoolVimRef()
 {
     if (this._primaryResourcePoolVimRef != null)
     {
         return(this._primaryResourcePoolVimRef);
     }
     throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.VIM_OBJECT_REF_NOT_FOUND_MSG));
 }
Ejemplo n.º 12
0
 public SnapshotSectionType GetSnapshotSection()
 {
     if (this.snapshotSection == null)
     {
         throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.DATA_NOT_FOUND));
     }
     return(this.snapshotSection);
 }
Ejemplo n.º 13
0
 public ReferenceType GetVdcStorageProfileReference()
 {
     if (this._storageProfileRef != null)
     {
         return(this._storageProfileRef);
     }
     throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.REFERENCE_NOT_FOUND_MSG));
 }
Ejemplo n.º 14
0
 public List <ReferenceType> GetProviderVdcStorageProfileRefs()
 {
     if (this.Resource.StorageProfiles == null)
     {
         throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.DATA_NOT_FOUND));
     }
     return(((IEnumerable <ReferenceType>) this.Resource.StorageProfiles.ProviderVdcStorageProfile).ToList <ReferenceType>());
 }
Ejemplo n.º 15
0
 public int GetVMDiskChainLength()
 {
     if (this.vmVimInfoType != null)
     {
         return(this.vmVimInfoType.VirtualDisksMaxChainLength);
     }
     throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.DATA_NOT_FOUND));
 }
Ejemplo n.º 16
0
 public string GetMetadataEntry(string key)
 {
     if (this._metadataEntries.ContainsKey(key))
     {
         return(this._metadataEntries[key]);
     }
     throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.DATA_NOT_FOUND));
 }
Ejemplo n.º 17
0
 public ReferenceType GetNetworkPoolRef()
 {
     if (this.Resource.NetworkPoolReference != null)
     {
         return(this.Resource.NetworkPoolReference);
     }
     throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.REFERENCE_NOT_FOUND_MSG));
 }
Ejemplo n.º 18
0
 public ReferenceType GetAdminVdcReference()
 {
     if (this.adminVdcReference != null)
     {
         return(this.adminVdcReference);
     }
     throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.REFERENCE_NOT_FOUND_MSG));
 }
Ejemplo n.º 19
0
 public ReferenceResult GetEdgeGatewayRefs()
 {
     foreach (LinkType linkType in this.Resource.Link)
     {
         if (linkType.rel.Equals("edgeGateways"))
         {
             return(this.VcloudClient.GetQueryService().ExecuteQuery <ReferenceResult, ReferencesType, QueryResultEdgeGatewayRecordType>(linkType.href + "?" + this.VcloudClient.GetQueryService().BuildQuery(FormatType.REFERENCE_VIEW)));
         }
     }
     throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.LINK_NOT_FOUND_MSG));
 }
Ejemplo n.º 20
0
 public MetadataEntryType GetTypedMetadataEntry(string key)
 {
     foreach (MetadataEntryType typedMetadataEntry in this.typedMetadataEntries)
     {
         if (typedMetadataEntry.Key.Equals(key) && typedMetadataEntry.Domain == null)
         {
             return(typedMetadataEntry);
         }
     }
     throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.DATA_NOT_FOUND));
 }
Ejemplo n.º 21
0
 public Stream DownloadLosslessOVF()
 {
     foreach (LinkType linkType in this.Resource.Link)
     {
         if (linkType.rel.Equals("download:identity"))
         {
             return(RestUtil.DownloadFile(this.VcloudClient, linkType.href));
         }
     }
     throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.NO_DOWNLOAD_LINK_MSG));
 }
Ejemplo n.º 22
0
 public AdminService GetAdminServiceByName(string serviceName)
 {
     foreach (ReferenceType reference in this.GetAdminServiceRefs().GetReferences())
     {
         if (reference.name.Equals(serviceName))
         {
             return(AdminService.GetAdminServiceByReference(this._client, reference));
         }
     }
     throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.SERVICE_NOT_FOUND) + " - " + serviceName);
 }
Ejemplo n.º 23
0
 public static Task GetTaskById(vCloudClient client, string vCloudId)
 {
     try
     {
         Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.GET_VCLOUD_ID_MSG) + " - " + vCloudId);
         return(new Task(client, VcloudEntity <TaskType> .GetEntityById(client, vCloudId, "application/vnd.vmware.vcloud.task+xml")));
     }
     catch (VCloudException ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Ejemplo n.º 24
0
 public static Media GetMediaById(vCloudClient client, string vCloudId)
 {
     try
     {
         Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.GET_VCLOUD_ID_MSG) + " - " + vCloudId);
         return(new Media(client, VcloudEntity <com.vmware.vcloud.api.rest.schema.MediaType> .GetEntityById(client, vCloudId, "application/vnd.vmware.vcloud.media+xml")));
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Ejemplo n.º 25
0
 public static VMWVimServer GetVMWVimServerById(vCloudClient client, string vCloudId)
 {
     try
     {
         Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.GET_VCLOUD_ID_MSG) + " - " + vCloudId);
         return(new VMWVimServer(client, VcloudEntity <VimServerType> .GetEntityById(client, vCloudId, "application/vnd.vmware.admin.vmwvirtualcenter+xml")));
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Ejemplo n.º 26
0
 public static Group GetGroupByReference(vCloudClient client, ReferenceType groupRef)
 {
     try
     {
         Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.GET_URL_MSG) + " - " + groupRef.href);
         return(new Group(client, VcloudResource <GroupType> .GetResourceByReference(client, groupRef)));
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Ejemplo n.º 27
0
 internal string GetHostResourceAttributeValue(string attributeName)
 {
     if (this.GetItemResource() != null && this.GetItemResource().ResourceType.Value.Equals("17") && (this.GetItemResource().HostResource != null && ((IEnumerable <cimString>) this.GetItemResource().HostResource).ToList <cimString>().Count > 0))
     {
         string stringAttributeValue = this.GetCimStringAttributeValue(this.GetItemResource().HostResource[0], attributeName);
         if (stringAttributeValue != null)
         {
             return(stringAttributeValue);
         }
     }
     throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.NOT_HARD_DISK_MSG) + " - " + this.GetItemResource().ElementName.Value);
 }
Ejemplo n.º 28
0
 public static Task GetTaskByReference(vCloudClient client, ReferenceType taskRef)
 {
     try
     {
         Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.GET_URL_MSG) + " - " + taskRef.href);
         return(new Task(client, VcloudResource <TaskType> .GetResourceByReference(client, taskRef)));
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Ejemplo n.º 29
0
 public static AdminVdc GetAdminVdcByReference(vCloudClient client, ReferenceType vdcRef)
 {
     try
     {
         Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.GET_URL_MSG) + " - " + vdcRef.href);
         return(new AdminVdc(client, VcloudResource <AdminVdcType> .GetResourceByReference(client, vdcRef)));
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Ejemplo n.º 30
0
 public static AdminVdc GetAdminVdcById(vCloudClient client, string vCloudId)
 {
     try
     {
         Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.GET_VCLOUD_ID_MSG) + " - " + vCloudId);
         return(new AdminVdc(client, VcloudEntity <AdminVdcType> .GetEntityById(client, vCloudId, "application/vnd.vmware.admin.vdc+xml")));
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }