mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
modifying disk working
This commit is contained in:
parent
3cbe09e2dc
commit
73f4a44112
8 changed files with 223 additions and 12 deletions
|
@ -75,6 +75,8 @@ module Fog
|
|||
request :get_vm_memory
|
||||
request :put_vm_memory
|
||||
request :get_request
|
||||
request :get_vm_disks
|
||||
request :put_vm_disks
|
||||
|
||||
|
||||
|
||||
|
|
105
lib/fog/vcloudng/generators/compute/disks.rb
Normal file
105
lib/fog/vcloudng/generators/compute/disks.rb
Normal file
|
@ -0,0 +1,105 @@
|
|||
module Fog
|
||||
module Generators
|
||||
module Compute
|
||||
module Vcloudng
|
||||
|
||||
class Disks
|
||||
def self.generate_xml(items=[])
|
||||
disks = self.class.new(items)
|
||||
disk.generate
|
||||
end
|
||||
|
||||
def initialize(items=[])
|
||||
@items = items
|
||||
end
|
||||
|
||||
def modify_hard_disk_size(disk_number, new_size)
|
||||
found = false
|
||||
@items.each do |item|
|
||||
if item['resource_type'] == 17
|
||||
if item['element_name'] == "Hard disk #{disk_number}"
|
||||
found = true
|
||||
raise "Hard disk size can't be reduced" if item['capacity'].to_i > new_size.to_i
|
||||
item['capacity'] = new_size
|
||||
end
|
||||
end
|
||||
end
|
||||
raise "Hard disk #{disk_number} not found" unless found
|
||||
true
|
||||
end
|
||||
|
||||
def generate
|
||||
output = ""
|
||||
output << header
|
||||
@items.each do |item|
|
||||
output << case item['resource_type']
|
||||
when 6
|
||||
scsi_controller(item)
|
||||
when 17
|
||||
hard_disk_item(item)
|
||||
when 5
|
||||
ide_controller_item(item)
|
||||
end
|
||||
end
|
||||
output << tail
|
||||
output
|
||||
end
|
||||
|
||||
def header
|
||||
'
|
||||
<vcloud:RasdItemsList xmlns:vcloud="http://www.vmware.com/vcloud/v1.5"
|
||||
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
|
||||
type="application/vnd.vmware.vcloud.rasdItemsList+xml"
|
||||
href="https://devlab.mdsol.com/api/vApp/vm-8b74d95a-ee91-4f46-88d8-fc92be0dbaae/virtualHardwareSection/disks"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
|
||||
xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://10.194.1.65/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">
|
||||
<vcloud:Link
|
||||
href="https://devlab.mdsol.com/api/vApp/vm-8b74d95a-ee91-4f46-88d8-fc92be0dbaae/virtualHardwareSection/disks"
|
||||
rel="edit"
|
||||
type="application/vnd.vmware.vcloud.rasdItemsList+xml"/>
|
||||
'
|
||||
end
|
||||
|
||||
def tail
|
||||
'</vcloud:RasdItemsList>'
|
||||
end
|
||||
|
||||
def hard_disk_item(opts={})
|
||||
"<vcloud:Item>
|
||||
<rasd:AddressOnParent>#{opts['address_on_parent']}</rasd:AddressOnParent>
|
||||
<rasd:Description>#{opts['description']}</rasd:Description>
|
||||
<rasd:ElementName>#{opts['element_name']}</rasd:ElementName>
|
||||
<rasd:HostResource vcloud:capacity=\"#{opts['capacity']}\" vcloud:busSubType=\"#{opts['bus_sub_type']}\" vcloud:busType=\"#{opts['bus_type']}\"></rasd:HostResource>
|
||||
<rasd:InstanceID>#{opts['instance_id']}</rasd:InstanceID>
|
||||
<rasd:Parent>#{opts['parent']}</rasd:Parent>
|
||||
<rasd:ResourceType>17</rasd:ResourceType>
|
||||
</vcloud:Item>"
|
||||
end
|
||||
|
||||
def ide_controller_item(opts={})
|
||||
"<vcloud:Item>
|
||||
<rasd:Address>#{opts['address']}</rasd:Address>
|
||||
<rasd:Description>#{opts['description']}</rasd:Description>
|
||||
<rasd:ElementName>#{opts['element_name']}</rasd:ElementName>
|
||||
<rasd:InstanceID>#{opts['instance_id']}</rasd:InstanceID>
|
||||
<rasd:ResourceType>5</rasd:ResourceType>
|
||||
</vcloud:Item>"
|
||||
end
|
||||
|
||||
def scsi_controller(opts={})
|
||||
"<vcloud:Item>
|
||||
<rasd:Address>#{opts['address']}</rasd:Address>
|
||||
<rasd:Description>#{opts['description']}</rasd:Description>
|
||||
<rasd:ElementName>#{opts['element_name']}</rasd:ElementName>
|
||||
<rasd:InstanceID>#{opts['instance_id']}</rasd:InstanceID>
|
||||
<rasd:ResourceSubType>#{opts['resource_sub_type']}</rasd:ResourceSubType>
|
||||
<rasd:ResourceType>6</rasd:ResourceType>
|
||||
</vcloud:Item>"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -18,7 +18,7 @@ module Fog
|
|||
attribute :ip_address
|
||||
attribute :cpu, :type => :integer
|
||||
attribute :memory
|
||||
# attribute :disks
|
||||
attribute :disks
|
||||
|
||||
def customization
|
||||
data = service.get_vm_customization(id).body
|
||||
|
|
61
lib/fog/vcloudng/parsers/compute/disks.rb
Normal file
61
lib/fog/vcloudng/parsers/compute/disks.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Compute
|
||||
module Vcloudng
|
||||
|
||||
|
||||
|
||||
class Disks < VcloudngParser
|
||||
|
||||
def reset
|
||||
@disk = {}
|
||||
@response = { 'disks' => [] }
|
||||
@host_resource = nil
|
||||
end
|
||||
|
||||
def start_element(name, attributes)
|
||||
super
|
||||
case name
|
||||
when 'HostResource'
|
||||
@host_resource = extract_attributes(attributes)
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'Address'
|
||||
@disk['address'] = value.to_i
|
||||
when 'AddressOnParent'
|
||||
@disk['address_on_parent'] = value.to_i
|
||||
when 'Description'
|
||||
@disk['description'] = value
|
||||
when 'ElementName'
|
||||
@disk['element_name'] = value
|
||||
when 'InstanceID'
|
||||
@disk['instance_id'] = value.to_i
|
||||
when 'ResourceSubType'
|
||||
@disk['resource_sub_type'] = value
|
||||
when 'Parent'
|
||||
@disk['parent'] = value.to_i
|
||||
when 'ResourceType'
|
||||
@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
|
||||
end
|
||||
@response['disks'] << @disk
|
||||
@host_resource = nil
|
||||
@disk = {}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -32,6 +32,8 @@ module Fog
|
|||
@vm['status'] = human_status(@vm['status'])
|
||||
when 'Children'
|
||||
@in_children = true
|
||||
when 'HostResource'
|
||||
@current_host_resource = extract_attributes(attributes)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -47,23 +49,19 @@ module Fog
|
|||
end
|
||||
when 'ResourceType'
|
||||
@resource_type = value
|
||||
case value
|
||||
when '3'
|
||||
@get_cpu = true # cpu
|
||||
when '4' # memory
|
||||
@get_memory = true
|
||||
when '17' # disks
|
||||
@get_disks = true
|
||||
end
|
||||
when 'VirtualQuantity'
|
||||
case @resource_type
|
||||
when '3'
|
||||
@vm['cpu'] = value
|
||||
when '4'
|
||||
@vm['memory'] = value
|
||||
when '17'
|
||||
end
|
||||
when 'ElementName'
|
||||
@element_name = value
|
||||
when 'Item'
|
||||
if @resource_type == '17' # disk
|
||||
@vm['disks'] ||= []
|
||||
@vm['disks'] << value
|
||||
@vm['disks'] << { @element_name => @current_host_resource["capacity"].to_i }
|
||||
end
|
||||
when 'Vm'
|
||||
@response['vms'] << @vm
|
||||
|
|
21
lib/fog/vcloudng/requests/compute/get_vm_disks.rb
Normal file
21
lib/fog/vcloudng/requests/compute/get_vm_disks.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Vcloudng
|
||||
class Real
|
||||
require 'fog/vcloudng/parsers/compute/disks'
|
||||
|
||||
|
||||
def get_vm_disks(vm_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:headers => { 'Accept' => 'application/*+xml;version=1.5' },
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::Compute::Vcloudng::Disks.new,
|
||||
:path => "vApp/#{vm_id}/virtualHardwareSection/disks"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,7 +3,7 @@ module Fog
|
|||
class Vcloudng
|
||||
class Real
|
||||
|
||||
def put_vm_memory(vm_id)
|
||||
def get_vm_memory(vm_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:headers => { 'Accept' => 'application/*+xml;version=1.5' },
|
||||
|
|
24
lib/fog/vcloudng/requests/compute/put_vm_disks.rb
Normal file
24
lib/fog/vcloudng/requests/compute/put_vm_disks.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Vcloudng
|
||||
class Real
|
||||
require 'fog/vcloudng/generators/compute/disks'
|
||||
|
||||
def put_vm_disks(vm_id, items=[])
|
||||
data = Fog::Generators::Compute::Vcloudng::Disks.new(items)
|
||||
data.modify_hard_disk_size(1, 8192*2)
|
||||
puts data.generate
|
||||
request(
|
||||
:body => data.generate,
|
||||
:expects => 202,
|
||||
:headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.rasdItemsList+xml',
|
||||
'Accept' => 'application/*+xml;version=1.5' },
|
||||
:method => 'PUT',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => "vApp/#{vm_id}/virtualHardwareSection/disks"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue