mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
1.Ability to fetch/list Orgs, Vdcs, Vapps, Servers.
2.Support to customize CPUs and Password
This commit is contained in:
parent
69fd1561ac
commit
8554a08ea4
6 changed files with 129 additions and 20 deletions
|
@ -112,8 +112,10 @@ module Fog
|
|||
request :configure_network_ip
|
||||
request :configure_vapp
|
||||
request :configure_vm_memory
|
||||
request :configure_vm_cpus
|
||||
request :configure_vm_name_description
|
||||
request :configure_vm_disks
|
||||
request :configure_vm_password
|
||||
request :delete_vapp
|
||||
request :get_catalog_item
|
||||
request :get_customization_options
|
||||
|
@ -188,12 +190,12 @@ module Fog
|
|||
@username = options[:vcloud_username]
|
||||
@password = options[:vcloud_password]
|
||||
@host = options[:vcloud_host]
|
||||
@vdc_href = options[:vcloud_default_vdc]
|
||||
@base_path = options[:vcloud_base_path] || Fog::Vcloud::Compute::BASE_PATH
|
||||
@version = options[:vcloud_version] || Fog::Vcloud::Compute::DEFAULT_VERSION
|
||||
@path = options[:vcloud_path] || "#{@base_path}/v#{@version}"
|
||||
@port = options[:vcloud_port] || Fog::Vcloud::Compute::PORT
|
||||
@scheme = options[:vcloud_scheme] || Fog::Vcloud::Compute::SCHEME
|
||||
@vdc_href = options[:vcloud_default_vdc]
|
||||
end
|
||||
|
||||
def reload
|
||||
|
@ -201,22 +203,19 @@ module Fog
|
|||
end
|
||||
|
||||
def default_organization_uri
|
||||
@default_organization_uri ||= begin
|
||||
unless @login_results
|
||||
do_login
|
||||
end
|
||||
case @login_results.body[:Org]
|
||||
when Array
|
||||
@login_results.body[:Org].first[:href]
|
||||
when Hash
|
||||
@login_results.body[:Org][:href]
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
@default_organization_uri ||= organizations.first.href
|
||||
@default_organization_uri
|
||||
end
|
||||
|
||||
def default_vdc_href
|
||||
if @vdc_href.nil?
|
||||
unless @login_results
|
||||
do_login
|
||||
end
|
||||
org = organizations.first
|
||||
vdc = get_organization(org.href).links.find { |item| item[:type] == 'application/vnd.vmware.vcloud.vdc+xml'}
|
||||
@vdc_href = vdc[:href]
|
||||
end
|
||||
@vdc_href
|
||||
end
|
||||
|
||||
|
|
|
@ -16,8 +16,7 @@ module Fog
|
|||
else
|
||||
connection.request(connection.basic_request_params("#{connection.base_path_url}/org/"))
|
||||
end
|
||||
data = raw_orgs.body[:Org].select { |org| org[:type] == "application/vnd.vmware.vcloud.org+xml" }
|
||||
data.each { |org| org.delete_if { |key, value| [:rel].include?(key) } }
|
||||
data = raw_orgs.body[:Org]
|
||||
load(data)
|
||||
end
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ module Fog
|
|||
|
||||
def ready?
|
||||
reload_status # always ensure we have the correct status
|
||||
running_tasks = tasks && tasks.flatten.any? {|ti| ti.kind_of?(Hash) && ti[:status] == 'running' }
|
||||
running_tasks = self.tasks && self.tasks.flatten.any? {|ti| ti.kind_of?(Hash) && ti[:status] == 'running' }
|
||||
status != '0' && !running_tasks # 0 is provisioning, and no running tasks
|
||||
end
|
||||
|
||||
|
@ -86,7 +86,15 @@ module Fog
|
|||
attributes[:name] = new_name
|
||||
@changed = true
|
||||
end
|
||||
def password
|
||||
guest_customization[:AdminPassword]
|
||||
end
|
||||
|
||||
def password=(password)
|
||||
return if password.nil? or password.size == 0
|
||||
@changed = true
|
||||
@update_password = password
|
||||
end
|
||||
def cpus
|
||||
if cpu_mess
|
||||
{ :count => cpu_mess[:"rasd:VirtualQuantity"].to_i,
|
||||
|
@ -95,8 +103,11 @@ module Fog
|
|||
end
|
||||
|
||||
def cpus=(qty)
|
||||
return if qty.nil? or qty.size == 0
|
||||
|
||||
@changed = true
|
||||
cpu_mess[:"rasd:VirtualQuantity"] = qty.to_s
|
||||
@update_cpu_value = qty
|
||||
qty
|
||||
end
|
||||
|
||||
def memory
|
||||
|
@ -107,6 +118,7 @@ module Fog
|
|||
end
|
||||
|
||||
def memory=(amount)
|
||||
return if amount.nil? or amount.size == 0
|
||||
@changed = true
|
||||
@update_memory_value = amount
|
||||
amount
|
||||
|
@ -172,26 +184,44 @@ module Fog
|
|||
raise RuntimeError, "Can't save cpu, name or memory changes while the VM is on."
|
||||
end
|
||||
end
|
||||
|
||||
if @update_password
|
||||
guest_customization[:AdminPassword] = @update_password.to_s
|
||||
connection.configure_vm_password(guest_customization)
|
||||
wait_for { ready? }
|
||||
end
|
||||
|
||||
if @update_cpu_value
|
||||
cpu_mess[:"rasd:VirtualQuantity"] = @update_cpu_value.to_s
|
||||
connection.configure_vm_cpus(cpu_mess)
|
||||
wait_for { ready? }
|
||||
end
|
||||
|
||||
if @update_memory_value
|
||||
memory_mess[:"rasd:VirtualQuantity"] = @update_memory_value.to_s
|
||||
connection.configure_vm_memory(memory_mess)
|
||||
wait_for { ready? }
|
||||
end
|
||||
|
||||
if @disk_change == :deleted
|
||||
data = disk_mess.delete_if do |vh|
|
||||
vh[:'rasd:ResourceType'] == '17' &&
|
||||
vh[:'rasd:AddressOnParent'].to_s == @remove_disk.to_s
|
||||
end
|
||||
connection.configure_vm_disks(self.href, data)
|
||||
wait_for { ready? }
|
||||
end
|
||||
if @disk_change == :added
|
||||
data = disk_mess
|
||||
data << @add_disk
|
||||
connection.configure_vm_disks(self.href, data)
|
||||
wait_for { ready? }
|
||||
end
|
||||
if @name_changed || @description_changed
|
||||
edit_uri = links.select {|i| i[:rel] == 'edit'}
|
||||
edit_uri = edit_uri.kind_of?(Array) ? edit_uri.flatten[0][:href] : edit_uri[:href]
|
||||
connection.configure_vm_name_description(edit_uri, self.name, self.description)
|
||||
wait_for { ready? }
|
||||
end
|
||||
end
|
||||
reset_tracking
|
||||
|
@ -215,6 +245,8 @@ module Fog
|
|||
def reset_tracking
|
||||
@disk_change = false
|
||||
@changed = false
|
||||
@update_password = nil
|
||||
@update_cpu_value = nil
|
||||
@update_memory_value = nil
|
||||
@name_changed = false
|
||||
@description_changed = nil
|
||||
|
@ -263,7 +295,9 @@ module Fog
|
|||
end
|
||||
|
||||
def reload_status
|
||||
self.status = connection.get_vapp(href).status
|
||||
server = connection.get_server(href)
|
||||
self.status = server.status
|
||||
self.tasks = server.tasks
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module Fog
|
|||
attribute :href
|
||||
|
||||
def all
|
||||
load([connection.get_vdc(self.href).resource_entities].flatten.select { |re| re[:type] == "application/vnd.vmware.vcloud.vApp+xml" })
|
||||
load([connection.get_vdc(connection.default_vdc_href).resource_entities].flatten.select { |re| re[:type] == "application/vnd.vmware.vcloud.vApp+xml" })
|
||||
end
|
||||
|
||||
def get(uri)
|
||||
|
|
38
lib/fog/vcloud/requests/compute/configure_vm_cpus.rb
Normal file
38
lib/fog/vcloud/requests/compute/configure_vm_cpus.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
module Fog
|
||||
module Vcloud
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
def configure_vm_cpus(vm_data)
|
||||
edit_uri = vm_data.select {|k,v| k == :Link && v[:rel] == 'edit'}
|
||||
edit_uri = edit_uri.kind_of?(Array) ? edit_uri.flatten[1][:href] : edit_uri[:Link][:href]
|
||||
|
||||
body = <<EOF
|
||||
<Item xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vcloud="http://www.vmware.com/vcloud/v1.5" vcloud:href="#{edit_uri}" vcloud:type="application/vnd.vmware.vcloud.rasdItem+xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://#{@host}/api/v1.5/schema/master.xsd http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2.22.0/CIM_ResourceAllocationSettingData.xsd">
|
||||
<rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
|
||||
<rasd:Description>Number of Virtual CPUs</rasd:Description>
|
||||
<rasd:ElementName>#{vm_data[:'rasd:VirtualQuantity']} virtual CPU(s)</rasd:ElementName>
|
||||
<rasd:InstanceID>4</rasd:InstanceID>
|
||||
<rasd:Reservation>0</rasd:Reservation>
|
||||
<rasd:ResourceType>3</rasd:ResourceType>
|
||||
<rasd:VirtualQuantity>#{vm_data[:'rasd:VirtualQuantity']}</rasd:VirtualQuantity>
|
||||
<rasd:Weight>0</rasd:Weight>
|
||||
<Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml" href="#{edit_uri}"/>
|
||||
</Item>
|
||||
EOF
|
||||
request(
|
||||
:body => body,
|
||||
:expects => 202,
|
||||
:headers => {'Content-Type' => vm_data[:"vcloud_type"] },
|
||||
:method => 'PUT',
|
||||
:uri => "#{edit_uri}",
|
||||
:parse => true
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
39
lib/fog/vcloud/requests/compute/configure_vm_password.rb
Normal file
39
lib/fog/vcloud/requests/compute/configure_vm_password.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
module Fog
|
||||
module Vcloud
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
def configure_vm_password(vmdata)
|
||||
edit_uri = vmdata[:href]
|
||||
body = <<EOF
|
||||
<GuestCustomizationSection xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" type="application/vnd.vmware.vcloud.guestCustomizationSection+xml" href="https://zone01.bluelock.com/api/vApp/vm-cc8e27be-f18c-4263-87c5-58a9297bac5b/guestCustomizationSection/" ovf:required="false" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.dmtf.org/ovf/envelope/1 http://schemas.dmtf.org/ovf/envelope/1/dsp8023_1.1.0.xsd http://www.vmware.com/vcloud/v1.5 http://zone01.bluelock.com/api/v1.5/schema/master.xsd">
|
||||
<ovf:Info>Specifies Guest OS Customization Settings</ovf:Info>
|
||||
<Enabled>true</Enabled>
|
||||
<ChangeSid>false</ChangeSid>
|
||||
<VirtualMachineId>#{vmdata[:VirtualMachineId]}</VirtualMachineId>
|
||||
<JoinDomainEnabled>false</JoinDomainEnabled>
|
||||
<UseOrgSettings>false</UseOrgSettings>
|
||||
<AdminPasswordEnabled>true</AdminPasswordEnabled>
|
||||
<AdminPasswordAuto>false</AdminPasswordAuto>
|
||||
<AdminPassword>#{vmdata[:AdminPassword]}</AdminPassword>
|
||||
<ResetPasswordRequired>false</ResetPasswordRequired>
|
||||
<ComputerName>#{vmdata[:ComputerName]}</ComputerName>
|
||||
<Link rel="edit" type="application/vnd.vmware.vcloud.guestCustomizationSection+xml" href="#{edit_uri}"/>
|
||||
</GuestCustomizationSection>
|
||||
EOF
|
||||
request(
|
||||
:body => body,
|
||||
:expects => 202,
|
||||
:headers => {'Content-Type' => vmdata[:type] },
|
||||
:method => 'PUT',
|
||||
:uri => "#{edit_uri}",
|
||||
:parse => true
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue