Computing > 9 - Manipulation of Personal Templates > Create a Personal Template

9.2 Create a Personal Template

By using the Aruba WsEndUser method SetEnqueuePersonalTemplateCreation it is possible to create a new customized template starting from the primary disk of a cloud server that is active on the system.
The method exports the primary disk of the virtual machine in the FTP area of the user, if active in a read-only dedicated folder.
The method associates certain details required for the characterization and identification of the template in the system to the template itself.
In input it requires a NewPersonalTemplate item which requires the following details:
• VirtualMachineID int: distinct ID on the Datacenter of the originating server from which to export the disk
• TemplateDescription string: description (brief) of the personal template
• TemplateExternalDescription optional string. Detailed description of the Personal Template
• OSVersion optional string version of the operating system
• OSFamilyID int of the operating system
• ApplianceTypeID optional int type of appliance
• Revision string version of the template
• TemplateUsername optional string: username to access server with which the template was created and which must be used to access the servers which will be created with the new template
• TemplatePassword optional string password related to username
• TemplateBounds data structure which identifies the acceptable maximum and minimum values of the Cpu, Ram, Disk resources for the creation of a new server
• Icon byte[] optional icon 128x128 png, gif, jpeg of the template.

Parameters
NewPersonalTemplate
Type: NewPersonalTemplate
NewPersonalTemplate type item which contains all the information required for the creation of the template.
Returns
The method returns a WsResult item with information on the result of the call to the method.
//BaseWsEndUser.SetEnqueuePersonalTemplateCreation Method (c# .NET) 
private static void SetEnqueuePersonalTemplateCreation(WsEndUserClient client)
{
    try
    {
        //create a new item called personalTemplate,
        //NewPersonalTemplate class
        NewPersonalTemplate personalTemplate = new NewPersonalTemplate()
        {
            VirtualMachineID = 1,
            TemplateDescription = "Personal template",
            TemplateExternalDescription = "Extended Description",
            OSVersion = "Windows server 2008",
            OSFamilyID = 1,
            ApplianceTypeID = 1,
            Revision = "1.0",
            TemplateUsername = "username",
            TemplatePassword = "password",
            TemplateBound = new List<TemplateBound>(){ 
                    new TemplateBound(){
                        TemplateBoundID = 1,
                        ResourceType = ResourceTypes.Cpu,
                        DefaultValue = 1,
                        MinValue = 1,
                        MaxValue = 4
                    },                       
                    new TemplateBound(){
                        TemplateBoundID = 1,
                        ResourceType = ResourceTypes.Ram,
                        DefaultValue = 2,
                        MinValue = 1,
                        MaxValue = 6
                    },                       
                    new TemplateBound(){
                        TemplateBoundID = 1,
                        ResourceType = ResourceTypes.HardDisk0,
                        DefaultValue = 20,
                        MinValue = 10,
                        MaxValue = 50
                    }                     
                }.ToArray(),
            Icon = File.ReadAllBytes("C:\\temp\\icon.jpg")
        };

        //call method SetEnqueuePersonalTemplateCreation,
        //obtaining a WsResult item
        WsResult result = client.SetEnqueuePersonalTemplateCreation(personalTemplate);

        //if the call is not successful, re-run the error indicating the message
        if (!result.Success)
            throw new ApplicationException(result.ResultMessage);
    }
    catch (Exception ex)
    {
        //re-run the generic error
        throw new ApplicationException(ex.Message);
    }
}
//BaseWsEndUser.setEnqueuePersonalTemplateCreation Method (JAVA) 
private static void setEnqueuePersonalTemplateCreation(IWsEndUser client)
{
    try
    {
        //create a new item called personalTemplate,
        //NewPersonalTemplate class
        NewPersonalTemplate personalTemplate = new NewPersonalTemplate();
        personalTemplate.setVirtualMachineID(1);       
        personalTemplate.setTemplateDescription("Personal template");
        personalTemplate.setTemplateExternalDescription("Extended Description");
        personalTemplate.setOSVersion("Windows server 2008");
        personalTemplate.setOSFamilyID(1);
        personalTemplate.setApplianceTypeID(1);
        personalTemplate.setRevision("1.0");
        personalTemplate.setTemplateUsername("username");
        personalTemplate.setTemplatePassword("password");
        
        File f = new File("C:\\temp\\icon.jpg");
        byte[] data = new byte[(int)f.length()];
        InputStream inStream = new FileInputStream(f);
        inStream.read(data);
        inStream.close();
        personalTemplate.setIcon(data);
      
        ArrayOfTemplateBound templateBound = new ArrayOfTemplateBound();
        TemplateBound template1 = new TemplateBound();
        template1.setTemplateBoundID(1);
        template1.setResourceType(ResourceTypes.CPU);
        template1.setDefaultValue(1);
        template1.setMinValue(1);
        template1.setMaxValue(4);
        templateBound.getTemplateBound().add(template1);
        TemplateBound template2 = new TemplateBound();
        template2.setTemplateBoundID(1);
        template2.setResourceType(ResourceTypes.RAM);
        template2.setDefaultValue(2);
        template2.setMinValue(1);
        template2.setMaxValue(6);
        templateBound.getTemplateBound().add(template2);
        TemplateBound template3 = new TemplateBound();
        template3.setTemplateBoundID(1);
        template3.setResourceType(ResourceTypes.HARD_DISK_0);
        template3.setDefaultValue(20);
        template3.setMinValue(10);
        template3.setMaxValue(50);
        templateBound.getTemplateBound().add(template3);            
        personalTemplate.setTemplateBound(templateBound);

        //call method setEnqueuePersonalTemplateCreation,
        //obtaining a WsResult item
        WsResult result = client.setEnqueuePersonalTemplateCreation(personalTemplate);

        //if the call is not successful, re-run the error indicating the message
        if (!result.isSuccess())
        {
            throw new Exception(result.getResultMessage());
        }
    }
    catch (Exception ex)
    {
        //generic exception
        System.out.println(ex);
    }
}
Version
API: v2.8 URL: https://api.dc1.computing.cloud.it/WsEndUser/v2.8/WsEndUser.svc?wsdl
See also