1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

vm customizations first try: it fails when it puts

This commit is contained in:
Rodrigo Estebanez 2013-06-28 15:03:38 +02:00
parent 8635dd42d9
commit e0e7ba9ed7
8 changed files with 144 additions and 21 deletions

View file

@ -71,6 +71,7 @@ module Fog
request :get_task
request :get_tasks_list
request :get_vm_customization
request :put_vm_customization
request :get_network
request :get_vm_cpu
request :put_vm_cpu

View file

@ -0,0 +1,89 @@
# This is the data structure it accepts, this is the output of get_vm_disks
#
# {"type"=>"application/vnd.vmware.vcloud.guestCustomizationSection+xml",
# "href"=>
# "https://devlab.mdsol.com/api/vApp/vm-2bbbf556-55dc-4974-82e6-aa6e814f0b64/guestCustomizationSection/",
# "id"=>"vm-2bbbf556-55dc-4974-82e6-aa6e814f0b64",
# "enabled"=>false,
# "change_sid"=>false,
# "virtual_machine_id"=>"2bbbf556-55dc-4974-82e6-aa6e814f0b64",
# "join_domain_enabled"=>false,
# "use_org_settings"=>false,
# "admin_password_enabled"=>false,
# "admin_password_auto"=>true,
# "reset_password_required"=>false,
# "customization_script"=>"hola\nmundo",
# "has_customization_script"=>true,
# "computer_name"=>"DEVWEB-001"}
#
#
# This is what it generates
#
# <vcloud:GuestCustomizationSection
# xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
# xmlns:vcloud="http://www.vmware.com/vcloud/v1.5"
# href="https://vcloud.example.com/api/vApp/vm-55cc91f2-7e12-48d4-ad90-6f637a51fd88/guestCustomizationSection/"
# ovf:required="false"
# type="application/vnd.vmware.vcloud.guestCustomizationSection+xml">
# <ovf:Info>Specifies Guest OS Customization Settings</ovf:Info>
# <vcloud:Enabled>true</vcloud:Enabled>
# <vcloud:ChangeSid>true</vcloud:ChangeSid>
# <vcloud:VirtualMachineId>55cc91f2-7e12-48d4-ad90-6f637a51fd88</vcloud:VirtualMachineId>
# <vcloud:JoinDomainEnabled>false</vcloud:JoinDomainEnabled>
# <vcloud:UseOrgSettings>false</vcloud:UseOrgSettings>
# <vcloud:AdminPasswordEnabled>true</vcloud:AdminPasswordEnabled>
# <vcloud:AdminPasswordAuto>true</vcloud:AdminPasswordAuto>
# <vcloud:ResetPasswordRequired>false</vcloud:ResetPasswordRequired>
# <vcloud:ComputerName>DEVWEB-001</vcloud:ComputerName>
# </vcloud:GuestCustomizationSection>
#
module Fog
module Generators
module Compute
module Vcloudng
class Customization
def initialize(attrs={})
@attrs = attrs
end
def generate_xml
output = ""
output << header
output << body(@attrs)
output << tail
output
end
def header
'<GuestCustomizationSection
xmlns="http://www.vmware.com/vcloud/v1.5"
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
ovf:required="false">
<ovf:Info>Specifies Guest OS Customization Settings</ovf:Info>
'
end
def body(opts={})
"<Enabled>#{opts[:enabled]}</Enabled>
<ChangeSid>#{opts[:change_sid]}</ChangeSid>
<VirtualMachineId>#{opts[:virtual_machine_id]}</VirtualMachineId>
<JoinDomainEnabled>#{opts[:join_domain_enabled]}</JoinDomainEnabled>
<UseOrgSettings>#{opts[:use_org_settings]}</UseOrgSettings>
<AdminPasswordEnabled>#{opts[:admin_password_enabled]}</AdminPasswordEnabled>
<AdminPasswordAuto>#{opts[:admin_password_auto]}</AdminPasswordAuto>
<ResetPasswordRequired>#{opts[:reset_password_required]}</ResetPasswordRequired>
<ComputerName>#{opts[:computer_name]}</ComputerName>
<CustomizationScript>#{CGI.escapeHTML(opts[:customization_script])}</CustomizationScript>"
end
def tail
'</GuestCustomizationSection>'
end
end
end
end
end
end

View file

@ -21,6 +21,7 @@
# "element_name"=>"IDE Controller 0",
# "instance_id"=>3,
# "resource_type"=>5}]}
#
# This is what it generates
#
# <vcloud:RasdItemsList xmlns:vcloud="http://www.vmware.com/vcloud/v1.5"

View file

@ -22,7 +22,6 @@ module Fog
def customization
data = service.get_vm_customization(id).body
puts data
service.vm_customizations.new(data)
end

View file

@ -13,21 +13,29 @@ module Fog
attribute :enabled
attribute :change_sid
attribute :join_domain_enabled
attribute :use_org_settings
attribute :admin_password_enabled
attribute :reset_password_required
attribute :virtual_machine_id
attribute :computer_name
attribute :has_customization_script
def initialize(new_attributes = {})
@customization_script = new_attributes['customization_script']
super(new_attributes)
def script
attributes[:customization_script]
end
def customization_script
@customization_script
def script=(new_script)
attributes[:customization_script] = new_script
end
def save
response = service.put_vm_customization(id, attributes)
task = response.body
task[:id] = task[:href].split('/').last
attributes[:customization_task] = service.tasks.new(task)
end
end
end
end

View file

@ -41,7 +41,6 @@ module Fog
@disk['resource_type'] = value.to_i
when 'Item'
if @host_resource
puts @host_resource['busSubType']
@disk['capacity'] = @host_resource['capacity'].to_i
@disk['bus_sub_type'] = @host_resource['busSubType']
@disk['bus_type'] = @host_resource['busType'].to_i

View file

@ -14,34 +14,37 @@ module Fog
case name
when 'GuestCustomizationSection'
customizations = extract_attributes(attributes)
@response.merge!(customizations.reject {|key,value| !['href', 'type'].include?(key)})
@response['id'] = @response['href'].split('/').last
@response[:href] = customizations['href']
@response[:type] = customizations['type']
# href looks like this:
# "https://devlab.mdsol.com/api/vApp/vm-2bbbf556-55dc-4974-82e6-aa6e814f0b64/guestCustomizationSection/"
@response[:id] = @response[:href].split('/')[-2]
end
end
def end_element(name)
case name
when 'Enabled',
@response['enabled'] = (value == "true")
@response[:enabled] = (value == "true")
when 'ChangeSid'
@response['change_sid'] = (value == "true")
@response[:change_sid] = (value == "true")
when 'JoinDomainEnabled'
@response['join_domain_enabled'] = (value == "true")
@response[:join_domain_enabled] = (value == "true")
when 'UseOrgSettings'
@response['use_org_settings'] = (value == "true")
@response[:use_org_settings] = (value == "true")
when 'AdminPasswordEnabled'
@response['admin_password_enabled'] = (value == "true")
@response[:admin_password_enabled] = (value == "true")
when 'AdminPasswordAuto'
@response['admin_password_auto'] = (value == "true")
@response[:admin_password_auto] = (value == "true")
when 'ResetPasswordRequired'
@response['reset_password_required'] = (value == "true")
@response[:reset_password_required] = (value == "true")
when 'VirtualMachineId'
@response['virtual_machine_id'] = value
@response[:virtual_machine_id] = value
when 'ComputerName'
@response['computer_name'] = value
@response[:computer_name] = value
when 'CustomizationScript'
@response['customization_script'] = value
@response['has_customization_script'] = !value.empty?
@response[:customization_script] = value
@response[:has_customization_script] = !value.empty?
end
end

View file

@ -0,0 +1,23 @@
module Fog
module Compute
class Vcloudng
class Real
require 'fog/vcloudng/generators/compute/customization'
def put_vm_customization(vm_id, customization={})
data = Fog::Generators::Compute::Vcloudng::Customization.new(customization)
request(
:body => data.generate_xml,
:expects => 202,
:headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.guestCustomizationSection+xml',
'Accept' => 'application/*+xml;version=1.5' },
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/guestCustomizationSection"
)
end
end
end
end
end