Friday, April 4, 2014

Create Windows stack using Heat Orchestration Template in Openstack

The blog explains the process of creating a basic Windows stack in Openstack using Heat Orchestration Template. The hypervisor being used is VMware ESXi5.5.

Image preparation to upload in glance

  • Lets start with creating a Windows 2012 R2 VM in ESXi. In this server, download and install the cloudbase-init package for windows .The beta version is available at this link:

https://www.cloudbase.it/downloads/CloudbaseInitSetup_Beta.msi


Follow the steps in this link for installation : http://www.cloudbase.it/cloud-init-for-windows-instances/

  • Once installation is completed, edit the 'setup.exe" registry key at HKLocal machine/SYSTEM/SETUP/STATUS/ChildCompletion and change the value from 1 to 3. This is to avoid a system restart exception when the image boots up for the first time in openstack
  • If you want to do any custom configurations in the windows machine, like open a specific firewall port, enable ping ,rdp etc..you can do it at this point
  •  Run Syprep and shutdown the VM
 C:\Windows\System32\sysprep\sysprep.exe /generalize /oobe /shutdown

  • Use a VMware standalone convertor ,select the prepared VM as source and convert it to a VM suitable for Vmware workstation 10.0.x. When the conversion process is completed, you will get a vmdk and .vmx file at the destination
  • Using winscp or any other similar tools, copy the converted vmdk to your openstack glance  server. 
  • Create an image from this vmdk using the following command

glance image-create --name <image name>--disk-format=vmdk --container-format=bare --is-public=true --property vmware_disktype="sparse" --property vmware_adaptertype="ide" --property vmware_ostype="windows8Server64Guest" < Openstack_win2012.vmdk


Sample yaml template

The template given below uses heat orchestrator to spin up an instance with the image that we created and install IIS in it

------------------------------------------------------------------------------------------------------------------------------------------
heat_template_version: 2013-05-23

description: >
  Basic windows+IIS installation

parameters:

  key_name:
    type: string
    description : Name of a KeyPair to enable access to the instance
  instance_type:
    type: string
    description: Instance type for Windows server
    default: m1.small
    constraints:
      - allowed_values: [m1.small, m1.medium, m1.large]
        description: instance_type must be one of m1.small, m1.medium or m1.large
  image_id:
    type: string
    description: ID of the image to use for the Windows erver
    default:
  windows_feature:
   type: string
   description: windows feature to be installed

resources:
  windows_instance:
    type: OS::Nova::Server
    properties:
      image: { get_param: image_id }
      flavor: { get_param: instance_type }
      key_name: { get_param: key_name }
      user_data:
        str_replace:
          template: |
            #ps1

            Install-WindowsFeature -Name feature -IncludeManagementTools
          params:
            feature: { get_param: windows_feature }


--------------------------------------------------------------------------------------------------------------------------------------------------


 Get password of the instance

Once the instance is up and running, you can use the keypair used while spinning up the stack to retrieve the password. In your openstance machine, run the following command

nova get-password <instance-id> <private key>

instance - id: This is the Id of instance created by the stack , can be obtained from horizon dashboard
privaye key : This is the pem file you downloaded while creating the keypair. Please note that you should copy it over to openstack machine using winscp before running the get-password command



 
Reference: 

The VMware specific configuration options for creating glance image
  http://docs.openstack.org/trunk/config-reference/content/vmware.html
 
The Vmware_ostype derived from the enumerator VirtualMachineGuestOsIdentifier in the API reference: http://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.vm.GuestOsDescriptor.GuestOsIdentifier.html