Exemplo n.º 1
0
 public Dictionary <string, FileType> MonitorUpload()
 {
     try
     {
         Dictionary <string, FileType> dictionary = new Dictionary <string, FileType>();
         VappTemplate templateByReference         = VappTemplate.GetVappTemplateByReference(this.VcloudClient, this.Reference);
         if (templateByReference != null && templateByReference.Resource != null && templateByReference.Resource.Files != null)
         {
             FilesListType files = templateByReference.Resource.Files;
             if (files != null && files.File != null)
             {
                 List <FileType> list = ((IEnumerable <FileType>)files.File).ToList <FileType>();
                 if (list != null)
                 {
                     dictionary = list.ToDictionary <FileType, string, FileType>((Func <FileType, string>)(file => file.name), (Func <FileType, FileType>)(file => file));
                 }
             }
         }
         return(dictionary);
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Exemplo n.º 2
0
        private static VappTemplate ExecuteVappTemplateUpload(
            vCloudClient client,
            string vdcActionUrl,
            string reqPayload,
            string contentType)
        {
            ReferenceType entity = new CatalogItem(client, SdkUtil.Post <CatalogItemType>(client, vdcActionUrl, reqPayload, contentType, 201)).Resource.Entity;

            return(VappTemplate.GetVappTemplateByReference(client, entity));
        }
Exemplo n.º 3
0
 public Task EnableDownload()
 {
     try
     {
         return(VappTemplate.ExecuteVappTemplateAction(this.VcloudClient, this.Reference.href + "/action/enableDownload", (string)null, (string)null, 202));
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Exemplo n.º 4
0
 public static Task Delete(vCloudClient client, ReferenceType vAppTemplateRef)
 {
     try
     {
         return(VappTemplate.DeletevAppTemplate(client, vAppTemplateRef.href));
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Exemplo n.º 5
0
 public Task Delete()
 {
     try
     {
         return(VappTemplate.DeletevAppTemplate(this.VcloudClient, this.Reference.href));
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Exemplo n.º 6
0
 public EnvelopeType GetOvf()
 {
     try
     {
         return(VappTemplate.GetOvf(this.VcloudClient, this.Reference.href + "/ovf"));
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Exemplo n.º 7
0
 public static Task EnableDownload(vCloudClient client, ReferenceType vAppTemplateRef)
 {
     try
     {
         string vappActionUrl = vAppTemplateRef.href + "/action/enableDownload";
         return(VappTemplate.ExecuteVappTemplateAction(client, vappActionUrl, (string)null, (string)null, 202));
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Exemplo n.º 8
0
 public static EnvelopeType GetOvf(
     vCloudClient client,
     ReferenceType vappTemplateRef)
 {
     try
     {
         return(VappTemplate.GetOvf(client, vappTemplateRef.href + "/ovf"));
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Exemplo n.º 9
0
        private static Task DeleteVappTemplateWithCatalogItem(
            vCloudClient client,
            ReferenceType vappTemplRef)
        {
            VappTemplate templateByReference = VappTemplate.GetVappTemplateByReference(client, vappTemplRef);
            string       href = vappTemplRef.href;

            if (templateByReference.IsPartOfCatalogItem())
            {
                CatalogItem.Delete(client, templateByReference.GetCatalogItemReference());
            }
            return(new Task(client, SdkUtil.Delete <TaskType>(client, href, 202)));
        }
Exemplo n.º 10
0
 public ulong GetVappTemplateSize()
 {
     try
     {
         ulong num = 0;
         if (this.Reference.type.Equals("application/vnd.vmware.vcloud.vm+xml"))
         {
             EnvelopeType ovf = VappTemplate.GetVappTemplateByReference(this.VcloudClient, this.GetParentVappTemplateReference()).GetOvf();
             if (ovf.Item != null)
             {
                 if (ovf.Item is VirtualSystemCollection_Type)
                 {
                     foreach (VirtualSystem_Type virtualSystemType in ((VirtualSystemCollection_Type)ovf.Item).Items1)
                     {
                         if (virtualSystemType.id.Equals(this.Reference.name))
                         {
                             num += VappTemplate.GetVmSize(virtualSystemType);
                         }
                     }
                 }
                 else if (ovf.Item is VirtualSystem_Type)
                 {
                     num += VappTemplate.GetVmSize((VirtualSystem_Type)ovf.Item);
                 }
             }
         }
         else
         {
             EnvelopeType ovf = this.GetOvf();
             if (ovf.Item != null)
             {
                 if (ovf.Item is VirtualSystemCollection_Type)
                 {
                     foreach (Content_Type contentType in ((VirtualSystemCollection_Type)ovf.Item).Items1)
                     {
                         num += VappTemplate.GetVmSize((VirtualSystem_Type)contentType);
                     }
                 }
                 else if (ovf.Item is VirtualSystem_Type)
                 {
                     num += VappTemplate.GetVmSize((VirtualSystem_Type)ovf.Item);
                 }
             }
         }
         return(num);
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Exemplo n.º 11
0
        public VappTemplate CloneVappTemplate(
            CloneVAppTemplateParamsType cloneVappTemplateParamsType,
            ReferenceType catalogRef)
        {
            if (cloneVappTemplateParamsType.name == null)
            {
                throw new MissingPropertyException(SdkUtil.GetI18nString(SdkMessage.MISSING_PROPERTY));
            }
            Catalog      catalog      = this.CheckCatalogForDuplicates(catalogRef, cloneVappTemplateParamsType.name);
            VappTemplate vappTemplate = this.CloneVappTemplate(cloneVappTemplateParamsType);

            this.AddResourceToCatalog(vappTemplate.Reference, catalog);
            return(VappTemplate.GetVappTemplateByReference(this.VcloudClient, vappTemplate.Reference));
        }
Exemplo n.º 12
0
 private static VappTemplate GetVappTemplate(vCloudClient client, string url)
 {
     try
     {
         Response     response     = RestUtil.Get(client, url);
         VappTemplate vappTemplate = (VappTemplate)null;
         if (response.IsExpected(200))
         {
             VAppTemplateType resource = response.GetResource <VAppTemplateType>();
             vappTemplate = new VappTemplate(client, resource);
         }
         else
         {
             response.HandleUnExpectedResponse();
         }
         return(vappTemplate);
     }
     catch (Exception ex)
     {
         throw new VCloudException(ex.Message);
     }
 }
Exemplo n.º 13
0
 public static Task DeleteVappTemplate(vCloudClient client, ReferenceType vAppTemplateRef)
 {
     return(VappTemplate.DeleteVappTemplateWithCatalogItem(client, vAppTemplateRef));
 }
Exemplo n.º 14
0
        public VappTemplate UploadVappTemplate(
            string vAppTemplateName,
            string vAppTemplateDesc,
            string localOvfFileLocation,
            bool manifestRequired,
            ReferenceType vdcStorageRef)
        {
            UploadVAppTemplateParamsType vappTemplParams = new UploadVAppTemplateParamsType();

            vappTemplParams.Description       = vAppTemplateDesc;
            vappTemplParams.name              = vAppTemplateName;
            vappTemplParams.manifestRequired  = manifestRequired;
            vappTemplParams.VdcStorageProfile = vdcStorageRef;
            VappTemplate vappTemplate = this.CreateVappTemplate(vappTemplParams);
            FileStream   fileStream1;

            try
            {
                fileStream1 = File.OpenRead(localOvfFileLocation);
            }
            catch (FileNotFoundException ex)
            {
                throw new VCloudRuntimeException((Exception)ex);
            }
            string fileName = Path.GetFileName(localOvfFileLocation);

            vappTemplate.UploadOVFFile((Stream)fileStream1, fileStream1.Length);
            VappTemplate templateByReference1 = VappTemplate.GetVappTemplateByReference(this.VcloudClient, vappTemplate.Reference);

            while (!templateByReference1.Resource.ovfDescriptorUploaded)
            {
                templateByReference1 = VappTemplate.GetVappTemplateByReference(this.VcloudClient, templateByReference1.Reference);
            }
            try
            {
                fileStream1.Close();
            }
            catch (IOException ex)
            {
                throw new VCloudRuntimeException((Exception)ex);
            }
            foreach (string uploadFileName in templateByReference1.GetUploadFileNames())
            {
                string     path = localOvfFileLocation.Replace(fileName, uploadFileName);
                FileStream fileStream2;
                try
                {
                    fileStream2 = File.OpenRead(path);
                }
                catch (FileNotFoundException ex)
                {
                    throw new VCloudRuntimeException((Exception)ex);
                }
                templateByReference1.UploadFile(uploadFileName, (Stream)fileStream2, fileStream2.Length);
                try
                {
                    fileStream2.Close();
                }
                catch (IOException ex)
                {
                    throw new VCloudRuntimeException((Exception)ex);
                }
            }
            VappTemplate templateByReference2 = VappTemplate.GetVappTemplateByReference(this.VcloudClient, templateByReference1.Reference);

            while (templateByReference2.Resource.status == VappTemplateStatus.UNRESOLVED.Value())
            {
                templateByReference2 = VappTemplate.GetVappTemplateByReference(this.VcloudClient, templateByReference2.Reference);
            }
            return(VappTemplate.GetVappTemplateByReference(this.VcloudClient, templateByReference2.Reference));
        }