heat template with powershell execute failed on windows vm

asked 2015-10-05 01:33:32 -0500

Mafer_Jun gravatar image

I am a openstack beginner,I have some problem about heat, here is a hello-world hot template wrote by myself:

heat_template_version: 2013-05-23

description: >
  hello windows
parameters:
  key_name:
    type: string
    default: demo_heat_key

  instance_type:
    type: string
    default: t1.4core-4g-40g
    constraints:
      - allowed_values: [m1.sminy, m1.small, m1.medium, m1.large m1.xlarge, t1.2core-2g-40g, t1.4core-4g-40g]

  image_id:
    default: win2008srv-enterprise-v1.4.1
    type: string
    constraints:
      - allowed_values: [ win2012-srv-v0.1, win2008srv-enterprise-v1.4.1 ]

resources:
  iis:
    type: OS::Nova::Server
    properties:
      image: { get_param: image_id }
      flavor: { get_param: instance_type }
      key_name: { get_param: key_name }
      networks:
        - network : public-ivt-direct-net
      user_data: |
         #ps1_helloworld
         echo "hello world" > C:\hello.txt

but turns out it cannot execute currently.I think it maybe cause by srcipt execute role of windows was not current.so I change my template:

heat_template_version: 2013-05-23

description: >
  hello windows
parameters:
  key_name:
    type: string
    default: demo_heat_key

  instance_type:
    type: string
    default: t1.4core-4g-40g
    constraints:
      - allowed_values: [m1.sminy, m1.small, m1.medium, m1.large m1.xlarge, t1.2core-2g-40g, t1.4core-4g-40g]

  image_id:
    default: win2008srv-enterprise-v1.4.1
    type: string
    constraints:
      - allowed_values: [ win2012-srv-v0.1, win2008srv-enterprise-v1.4.1 ]

resources:
  iis:
    type: OS::Nova::Server
    properties:
      image: { get_param: image_id }
      flavor: { get_param: instance_type }
      key_name: { get_param: key_name }
      networks:
        - network : public-ivt-direct-net
      user_data: |
          #ps1_install
          Function ExecRetry($command){
            $psi = New-object System.Diagnostics.ProcessStartInfo
            $psi.UseShellExecute = $false 
            $psi.RedirectStandardOutput = $true 
            $psi.RedirectStandardError = $true 
            $psi.FileName = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' 
            $psi.Arguments = $command
            $psi.UserName = "Administrator"
            $Password = New-object System.Security.SecureString
            $Password.AppendChar('T')
            $Password.AppendChar('E')
            $Password.AppendChar('S')
            $Password.AppendChar('T')
            $Password.AppendChar('@')
            $Password.AppendChar('l')
            $Password.AppendChar('y')
            $Password.AppendChar('.')
            $Password.AppendChar('c')
            $Password.AppendChar('0')
            $Password.AppendChar('m')
            $psi.Password = $Password
            $psi.Verb = "runas"
            $process = New-Object System.Diagnostics.Process
            $process.StartInfo = $psi
            $process.Start()
          }
          ExecRetry{
            echo "abc" > C:\hello.txt
          }

still it cannot execute.I cannot find why it happen.dose somebody can help me out.

edit retag flag offensive close merge delete