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

[vcloud_director] whitespace cleanup

This commit is contained in:
Nick Osborn 2013-09-16 18:13:09 +01:00
parent 0130f4b21c
commit bf38e751ac
67 changed files with 778 additions and 803 deletions

View file

@ -3,7 +3,6 @@ require 'fog/compute'
require 'fog/vcloud_director/requests/compute/helper'
class VcloudDirectorParser < Fog::Parsers::Base
def extract_attributes(attributes_xml)
attributes = {}
until attributes_xml.empty?
@ -19,8 +18,6 @@ class VcloudDirectorParser < Fog::Parsers::Base
end
attributes
end
end
class NonLoaded
@ -29,280 +26,276 @@ end
module Fog
module Compute
class VcloudDirector < Fog::Service
module Defaults
PATH = '/api'
PORT = 443
SCHEME = 'https'
API_VERSION = '5.1'
end
module Errors
class ServiceError < Fog::Errors::Error; end
class Task < ServiceError; end
end
requires :vcloud_director_username, :vcloud_director_password, :vcloud_director_host
recognizes :vcloud_director_api_version
secrets :vcloud_director_password
model_path 'fog/vcloud_director/models/compute'
model :catalog
collection :catalogs
model :organization
collection :organizations
model :catalog_item
collection :catalog_items
model :vdc
collection :vdcs
model :vapp
collection :vapps
model :task
collection :tasks
model :vm
collection :vms
model :vm_customization
collection :vm_customizations
model :network
collection :networks
model :disk
collection :disks
model :vm_network
collection :vm_networks
model :tag # this is called metadata in vcloud
collection :tags
request_path 'fog/vcloud_director/requests/compute'
request :get_organizations
request :get_organization
request :get_catalog
request :get_catalog_item
request :get_vdc
request :get_vapp_template
request :get_vapp
request :get_vms
request :instantiate_vapp_template
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
request :get_vm_memory
request :put_vm_memory
request :get_vm_disks
request :put_vm_disks
request :get_vm_network
request :put_vm_network
request :get_metadata
request :post_vm_metadata
request :put_metadata_value
request :delete_metadata
request :post_vm_poweron
request :get_request # this is used for manual testing
request :get_href # this is used for manual testing
request :get_vms_by_metadata
request :get_vm
request :post_task_cancel
request :undeploy
module Defaults
PATH = '/api'
PORT = 443
SCHEME = 'https'
API_VERSION = '5.1'
end
class Model < Fog::Model
def initialize(attrs={})
super(attrs)
lazy_load_attrs.each do |attr|
attributes[attr]= NonLoaded if attributes[attr].nil?
make_lazy_load_method(attr)
end
self.class.attributes.each{|attr| make_attr_loaded_method(attr) }
end
def lazy_load_attrs
@lazy_load_attrs ||= self.class.attributes - attributes.keys
end
def make_lazy_load_method(attr)
self.class.instance_eval do
define_method(attr) do
reload if attributes[attr] == NonLoaded and !@inspecting
attributes[attr]
end
end
end
# it adds an attr_loaded? method to know if the value has been loaded yet or not: ie description_loaded?
def make_attr_loaded_method(attr)
self.class.instance_eval do
define_method("#{attr}_loaded?") do
attributes[attr] != NonLoaded
end
end
end
def inspect
@inspecting = true
out = super
@inspecting = false
out
end
end
class Collection < Fog::Collection
def all(lazy_load=true)
lazy_load ? index : get_everyone
end
def get(item_id)
item = get_by_id(item_id)
return nil unless item
new(item)
end
def get_by_name(item_name)
item_found = item_list.detect{|item| item[:name] == item_name }
return nil unless item_found
get(item_found[:id])
end
def index
load(item_list)
end
def get_everyone
items = item_list.map {|item| get_by_id(item[:id]) }
load(items)
end
end
module Errors
class ServiceError < Fog::Errors::Error; end
class Task < ServiceError; end
end
class Real
include Fog::Compute::Helper
attr_reader :end_point, :api_version
requires :vcloud_director_username, :vcloud_director_password, :vcloud_director_host
recognizes :vcloud_director_api_version
def initialize(options={})
@vcloud_director_password = options[:vcloud_director_password]
@vcloud_director_username = options[:vcloud_director_username]
@connection_options = options[:connection_options] || {}
@host = options[:vcloud_director_host]
@path = options[:path] || Fog::Compute::VcloudDirector::Defaults::PATH
@persistent = options[:persistent] || false
@port = options[:port] || Fog::Compute::VcloudDirector::Defaults::PORT
@scheme = options[:scheme] || Fog::Compute::VcloudDirector::Defaults::SCHEME
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
@end_point = "#{@scheme}://#{@host}#{@path}/"
@api_version = options[:vcloud_director_api_version] || Fog::Compute::VcloudDirector::Defaults::API_VERSION
end
def auth_token
login if @auth_token.nil?
@auth_token
end
secrets :vcloud_director_password
def org_name
login if @org_name.nil?
@org_name
end
def reload
@cookie = nil # verify that this makes the connection to be restored, if so use Excon::Errors::Forbidden instead of Excon::Errors::Unauthorized
@connection.reset
end
def request(params)
unless @cookie
@cookie = auth_token
end
begin
do_request(params)
# this is to know if Excon::Errors::Unauthorized really happens
#rescue Excon::Errors::Unauthorized
# @cookie = auth_token
# do_request(params)
end
end
def do_request(params)
headers = { 'Accept' => 'application/*+xml;version=' + @api_version }
if @cookie
headers.merge!('Cookie' => @cookie)
end
if params[:path]
if params[:override_path] == true
path = params[:path]
else
path = "#{@path}/#{params[:path]}"
end
else
path = "#{@path}"
end
@connection.request({
:body => params[:body],
:expects => params[:expects],
:headers => headers.merge!(params[:headers] || {}),
:host => @host,
:method => params[:method],
:parser => params[:parser],
:path => path
})
rescue => @e
raise @e unless @e.class.to_s =~ /^Excon::Errors/
if @e.respond_to?(:response)
puts @e.response.status
puts CGI::unescapeHTML(@e.response.body)
end
raise @e
end
def process_task(response_body)
task = make_task_object(response_body)
wait_and_raise_unless_success(task)
true
end
def make_task_object(task_response)
task_response[:id] = task_response[:href].split('/').last
tasks.new(task_response)
end
def wait_and_raise_unless_success(task)
task.wait_for { non_running? }
raise Errors::Task.new "status: #{task.status}, error: #{task.error}" unless task.success?
end
def add_id_from_href!(data={})
data[:id] = data[:href].split('/').last
end
private
model_path 'fog/vcloud_director/models/compute'
model :catalog
collection :catalogs
model :organization
collection :organizations
model :catalog_item
collection :catalog_items
model :vdc
collection :vdcs
model :vapp
collection :vapps
model :task
collection :tasks
model :vm
collection :vms
model :vm_customization
collection :vm_customizations
model :network
collection :networks
model :disk
collection :disks
model :vm_network
collection :vm_networks
model :tag # this is called metadata in vcloud
collection :tags
def login
headers = {
'Authorization' => "Basic #{Base64.encode64("#{@vcloud_director_username}:#{@vcloud_director_password}").delete("\r\n")}",
'Accept' => 'application/*+xml;version=' + @api_version
}
response = @connection.request({
:expects => 200,
:headers => headers,
:host => @host,
:method => 'POST',
:parser => Fog::ToHashDocument.new,
:path => '/api/sessions' # curl http://example.com/api/versions | grep LoginUrl
})
@auth_token = response.headers['Set-Cookie'] || response.headers['set-cookie']
@org_name = response.body[:org]
end
request_path 'fog/vcloud_director/requests/compute'
request :get_organizations
request :get_organization
request :get_catalog
request :get_catalog_item
request :get_vdc
request :get_vapp_template
request :get_vapp
request :get_vms
request :instantiate_vapp_template
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
request :get_vm_memory
request :put_vm_memory
request :get_vm_disks
request :put_vm_disks
request :get_vm_network
request :put_vm_network
request :get_metadata
request :post_vm_metadata
request :put_metadata_value
request :delete_metadata
request :post_vm_poweron
request :get_request # this is used for manual testing
request :get_href # this is used for manual testing
request :get_vms_by_metadata
request :get_vm
request :post_task_cancel
request :undeploy
end
class Model < Fog::Model
def initialize(attrs={})
super(attrs)
lazy_load_attrs.each do |attr|
attributes[attr]= NonLoaded if attributes[attr].nil?
make_lazy_load_method(attr)
end
self.class.attributes.each {|attr| make_attr_loaded_method(attr)}
end
class Mock
end
def lazy_load_attrs
@lazy_load_attrs ||= self.class.attributes - attributes.keys
end
end
def make_lazy_load_method(attr)
self.class.instance_eval do
define_method(attr) do
reload if attributes[attr] == NonLoaded and !@inspecting
attributes[attr]
end
end
end
# it adds an attr_loaded? method to know if the value has been loaded
# yet or not: ie description_loaded?
def make_attr_loaded_method(attr)
self.class.instance_eval do
define_method("#{attr}_loaded?") do
attributes[attr] != NonLoaded
end
end
end
def inspect
@inspecting = true
out = super
@inspecting = false
out
end
end
class Collection < Fog::Collection
def all(lazy_load=true)
lazy_load ? index : get_everyone
end
def get(item_id)
item = get_by_id(item_id)
return nil unless item
new(item)
end
def get_by_name(item_name)
item_found = item_list.detect {|item| item[:name] == item_name}
return nil unless item_found
get(item_found[:id])
end
def index
load(item_list)
end
def get_everyone
items = item_list.map {|item| get_by_id(item[:id])}
load(items)
end
end
class Real
include Fog::Compute::Helper
attr_reader :end_point, :api_version
def initialize(options={})
@vcloud_director_password = options[:vcloud_director_password]
@vcloud_director_username = options[:vcloud_director_username]
@connection_options = options[:connection_options] || {}
@host = options[:vcloud_director_host]
@path = options[:path] || Fog::Compute::VcloudDirector::Defaults::PATH
@persistent = options[:persistent] || false
@port = options[:port] || Fog::Compute::VcloudDirector::Defaults::PORT
@scheme = options[:scheme] || Fog::Compute::VcloudDirector::Defaults::SCHEME
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
@end_point = "#{@scheme}://#{@host}#{@path}/"
@api_version = options[:vcloud_director_api_version] || Fog::Compute::VcloudDirector::Defaults::API_VERSION
end
def auth_token
login if @auth_token.nil?
@auth_token
end
def org_name
login if @org_name.nil?
@org_name
end
def reload
@cookie = nil # verify that this makes the connection to be restored, if so use Excon::Errors::Forbidden instead of Excon::Errors::Unauthorized
@connection.reset
end
def request(params)
unless @cookie
@cookie = auth_token
end
begin
do_request(params)
# this is to know if Excon::Errors::Unauthorized really happens
#rescue Excon::Errors::Unauthorized
# @cookie = auth_token
# do_request(params)
end
end
def do_request(params)
headers = { 'Accept' => 'application/*+xml;version=' + @api_version }
if @cookie
headers.merge!('Cookie' => @cookie)
end
if params[:path]
if params[:override_path] == true
path = params[:path]
else
path = "#{@path}/#{params[:path]}"
end
else
path = "#{@path}"
end
@connection.request({
:body => params[:body],
:expects => params[:expects],
:headers => headers.merge!(params[:headers] || {}),
:host => @host,
:method => params[:method],
:parser => params[:parser],
:path => path
})
rescue => @e
raise @e unless @e.class.to_s =~ /^Excon::Errors/
if @e.respond_to?(:response)
puts @e.response.status
puts CGI::unescapeHTML(@e.response.body)
end
raise @e
end
def process_task(response_body)
task = make_task_object(response_body)
wait_and_raise_unless_success(task)
true
end
def make_task_object(task_response)
task_response[:id] = task_response[:href].split('/').last
tasks.new(task_response)
end
def wait_and_raise_unless_success(task)
task.wait_for { non_running? }
raise Errors::Task.new "status: #{task.status}, error: #{task.error}" unless task.success?
end
def add_id_from_href!(data={})
data[:id] = data[:href].split('/').last
end
private
def login
headers = {
'Authorization' => "Basic #{Base64.encode64("#{@vcloud_director_username}:#{@vcloud_director_password}").delete("\r\n")}",
'Accept' => 'application/*+xml;version=' + @api_version
}
response = @connection.request({
:expects => 200,
:headers => headers,
:host => @host,
:method => 'POST',
:parser => Fog::ToHashDocument.new,
:path => '/api/sessions' # curl http://example.com/api/versions | grep LoginUrl
})
@auth_token = response.headers['Set-Cookie'] || response.headers['set-cookie']
@org_name = response.body[:org]
end
end
class Mock
end
end
end
end

View file

@ -15,7 +15,6 @@
# "customization_script"=>"hola\nmundo",
# "has_customization_script"=>true,
# "computer_name"=>"DEVWEB-001"}
#
#
# This is what it generates
#
@ -36,18 +35,18 @@
# <vcloud:ResetPasswordRequired>false</vcloud:ResetPasswordRequired>
# <vcloud:ComputerName>DEVWEB-001</vcloud:ComputerName>
# </vcloud:GuestCustomizationSection>
#
#
module Fog
module Generators
module Compute
module VcloudDirector
class Customization
def initialize(attrs={})
@attrs = attrs
end
def generate_xml
output = ""
output << header
@ -55,48 +54,47 @@ module Fog
output << tail
output
end
def header
'<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"
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">'
'<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"
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">'
end
# the order maters http://communities.vmware.com/thread/448760?start=0&tstart=0
# http://www.vmware.com/support/vcd/doc/rest-api-doc-1.5-html/types/GuestCustomizationSectionType.html
# CustomizationScript
# Script to run on guest customization. You could use xml escape sequence &#13; to make multiple lines script. The script could contain any UNICODE symbol by specifying its number in format &#xxxx; where xxxx is the number. The predefined symbols in the XML are: * & &amp; * < &lt; * > &gt; * " &quot; * ' &apos;
def body(opts={})
body = "
<ovf:Info>Specifies Guest OS Customization Settings</ovf:Info>
<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>
<CustomizationScript>#{CGI::escapeHTML(opts[:customization_script]).gsub(/\r/, "&#13;")}</CustomizationScript>
<ComputerName>#{opts[:computer_name]}</ComputerName>"
<ovf:Info>Specifies Guest OS Customization Settings</ovf:Info>
<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>
<CustomizationScript>#{CGI::escapeHTML(opts[:customization_script]).gsub(/\r/, "&#13;")}</CustomizationScript>
<ComputerName>#{opts[:computer_name]}</ComputerName>"
end
def tail
'</GuestCustomizationSection>'
end
end
end
end
end
end
end

View file

@ -24,9 +24,9 @@
#
# This is what it generates
#
# <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"
# <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"
# >
# <vcloud:Item>
# <rasd:Address>0</rasd:Address>
@ -37,7 +37,7 @@
# <rasd:ResourceType>6</rasd:ResourceType>
# </vcloud:Item><vcloud:Item>
# <rasd:AddressOnParent>0</rasd:AddressOnParent>
# <rasd:Description>Hard disk</rasd:Description>
# <rasd:Description>Hard disk</rasd:Description>
# <rasd:ElementName>Hard disk 1</rasd:ElementName>
# <rasd:HostResource vcloud:capacity="16384" vcloud:busSubType="VirtualSCSI" vcloud:busType="6"></rasd:HostResource>
# <rasd:InstanceID>2000</rasd:InstanceID>
@ -50,25 +50,25 @@
# <rasd:InstanceID>3</rasd:InstanceID>
# <rasd:ResourceType>5</rasd:ResourceType>
# </vcloud:Item></vcloud:RasdItemsList>
#
#
module Fog
module Generators
module Compute
module VcloudDirector
class Disks
def initialize(items=[])
@items = items[:disks]
end
def modify_hard_disk_size(disk_number, new_size)
found = false
@items.each do |item|
if item[:resource_type] == 17
if item[:name] == "Hard disk #{disk_number}"
found = true
raise "Hard disk size can't be reduced" if item[:capacity].to_i > new_size.to_i
raise "Hard disk size can't be reduced" if item[:capacity].to_i > new_size.to_i
item[:capacity] = new_size
end
end
@ -76,24 +76,24 @@ module Fog
raise "Hard disk #{disk_number} not found" unless found
true
end
def add_hard_disk(size)
new_hard_disk = last_hard_disk.dup
new_hard_disk[:capacity] = size
new_hard_disk[:name] = increase_hard_disk_name(new_hard_disk[:name])
new_hard_disk[:address_on_parent] += 1
new_hard_disk[:id] += 1
new_hard_disk[:address_on_parent] += 1
new_hard_disk[:id] += 1
@items << new_hard_disk
end
def delete_hard_disk(disk_number)
@items.delete_if {|item| item[:resource_type] == 17 && item[:name] =~ /#{disk_number}$/ }
end
def disks
{ :disks => @items }
end
def generate_xml
output = ""
output << header
@ -110,21 +110,21 @@ module Fog
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"
'<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">'
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:Description>#{opts[:description]}</rasd:Description>
<rasd:ElementName>#{opts[: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[:id]}</rasd:InstanceID>
@ -132,7 +132,7 @@ module Fog
<rasd:ResourceType>17</rasd:ResourceType>
</vcloud:Item>"
end
def ide_controller_item(opts={})
"<vcloud:Item>
<rasd:Address>#{opts[:address]}</rasd:Address>
@ -142,7 +142,7 @@ module Fog
<rasd:ResourceType>5</rasd:ResourceType>
</vcloud:Item>"
end
def scsi_controller(opts={})
"<vcloud:Item>
<rasd:Address>#{opts[:address]}</rasd:Address>
@ -153,9 +153,9 @@ module Fog
<rasd:ResourceType>6</rasd:ResourceType>
</vcloud:Item>"
end
# helpers
def last_hard_disk
hard_disks = @items.select{|item| item[:resource_type] == 17}
names = hard_disks.map{|item| item[:name] }
@ -163,13 +163,13 @@ module Fog
last_number = only_numbers.sort.last # get the last number
hard_disks.detect{|hard_disk| hard_disk[:name] =~ /#{last_number}$/ }
end
def increase_hard_disk_name(hard_disk_name)
hard_disk_name.gsub(/(\d+)$/) { $1.to_i + 1 }
end
end
end
end
end
end
end

View file

@ -5,7 +5,7 @@
# :href=>
# "https://example.com/api/vApp/vm-18545e82-d919-4071-ae7e-d1300d9d8112/metadata",
# :id=>"vm-18545e82-d919-4071-ae7e-d1300d9d8112"}
#
#
# <Metadata xmlns="http://www.vmware.com/vcloud/v1.5" type="application/vnd.vmware.vcloud.metadata+xml" 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">
# <MetadataEntry>
# <Key>buenas si</Key>
@ -23,13 +23,13 @@ module Fog
module VcloudDirector
class MetadataBase
attr_reader :attrs
def initialize(attrs={})
@attrs = attrs
end
def generate_xml
output = ""
output << header
@ -39,39 +39,39 @@ module Fog
output << tail
output
end
def add_item(k,v)
@attrs[:metadata].merge!(Hash[k,v])
end
# 1.5
def header
'<Metadata xmlns="http://www.vmware.com/vcloud/v1.5"
type="application/vnd.vmware.vcloud.metadata+xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
'<Metadata xmlns="http://www.vmware.com/vcloud/v1.5"
type="application/vnd.vmware.vcloud.metadata+xml"
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">
'
end
def metadata_entry
raise "This is an abstract class. Use the appropriate subclass"
end
# 5.1
#def header
# '<Metadata xmlns="http://www.vmware.com/vcloud/v1.5"
# xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
# type="application/vnd.vmware.vcloud.metadata+xml"
# '<Metadata xmlns="http://www.vmware.com/vcloud/v1.5"
# xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
# type="application/vnd.vmware.vcloud.metadata+xml"
# href="https://devlab.mdsol.com/api/vApp/vm-345c3619-edcd-4a8c-a8b9-c69ace3f89d1/metadata"
# xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://10.194.1.65/api/v1.5/schema/master.xsd">'
#end
def tail
'</Metadata>'
end
end
class MetadataV51 < MetadataBase
def metadata_entry(key,value)
body = <<EOF
@ -85,9 +85,9 @@ module Fog
</MetadataEntry>
EOF
end
end
class MetadataV15 < MetadataBase
def metadata_entry(key,value)
body = <<EOF
@ -98,7 +98,8 @@ EOF
EOF
end
end
#
end
end
end
end
end

View file

@ -12,7 +12,7 @@
# :is_connected=>true,
# :mac_address=>"00:50:56:01:00:8d",
# :ip_address_allocation_mode=>"POOL"}
#
#
#
# This is what it generates
#
@ -28,20 +28,20 @@
# </NetworkConnection>
# <Link rel="edit" type="application/vnd.vmware.vcloud.networkConnectionSection+xml" href="https://example.com/api/vApp/vm-8b74d95a-ee91-4f46-88d8-fc92be0dbaae/networkConnectionSection/"/>
# </NetworkConnectionSection>
#
#
module Fog
module Generators
module Compute
module VcloudDirector
class VmNetwork
attr_reader :attrs
def initialize(attrs={})
@attrs = attrs
end
def generate_xml
output = ""
output << header
@ -49,58 +49,57 @@ module Fog
output << tail
output
end
def network
@attrs[:network]
end
def network=(new_network_name)
@attrs[:network] = new_network_name
end
def ip_address
@attrs[:ip_address]
end
def ip_address=(new_ip_address)
@attrs[:ip_address] = new_ip_address
end
def is_connected
@attrs[:is_connected]
end
def is_connected=(new_is_connected)
@attrs[:is_connected] = new_is_connected
end
def ip_address_allocation_mode
@attrs[:ip_address_allocation_mode]
end
def ip_address_allocation_mode=(new_ip_address_allocation_mode)
@attrs[:ip_address_allocation_mode] = new_ip_address_allocation_mode
end
def header
'<NetworkConnectionSection xmlns="http://www.vmware.com/vcloud/v1.5"
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
type="application/vnd.vmware.vcloud.networkConnectionSection+xml"
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
'<NetworkConnectionSection xmlns="http://www.vmware.com/vcloud/v1.5"
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
type="application/vnd.vmware.vcloud.networkConnectionSection+xml"
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://10.194.1.65/api/v1.5/schema/master.xsd">'
end
def body(opts={})
body = <<EOF
<ovf:Info>#{opts[:info]}</ovf:Info>
<PrimaryNetworkConnectionIndex>#{opts[:primary_network_connection_index]}</PrimaryNetworkConnectionIndex>
<NetworkConnection
network="#{opts[:network]}"
<NetworkConnection
network="#{opts[:network]}"
needsCustomization="#{opts[:needs_customization]}">
<NetworkConnectionIndex>#{opts[:network_connection_index]}</NetworkConnectionIndex>
<IpAddress>#{opts[:ip_address]}</IpAddress>
@ -110,13 +109,14 @@ module Fog
</NetworkConnection>
EOF
end
def tail
'</NetworkConnectionSection>'
end
end
end
end
end
end
end

View file

@ -5,21 +5,21 @@ module Fog
class VcloudDirector
class Catalog < Model
identity :id
attribute :name
attribute :type
attribute :href
attribute :description, :aliases => :Description
attribute :is_published, :aliases => :IsPublished, :type => :boolean
def catalog_items
requires :id
service.catalog_items(:catalog => self)
end
end
end
end
end
end

View file

@ -5,21 +5,20 @@ module Fog
class VcloudDirector
class CatalogItem < Model
identity :id
attribute :name
attribute :type
attribute :href
attribute :description, :aliases => :Description
attribute :vapp_template_id
def instantiate(vapp_name, options={})
response = service.instantiate_vapp_template(vapp_name, vapp_template_id, options)
service.process_task(response.body[:Tasks][:Task])
end
end
end
end

View file

@ -7,18 +7,18 @@ module Fog
class CatalogItems < Collection
model Fog::Compute::VcloudDirector::CatalogItem
attribute :catalog
private
def item_list
data = service.get_catalog(catalog.id).body
items = data[:CatalogItems][:CatalogItem].select { |link| link[:type] == "application/vnd.vmware.vcloud.catalogItem+xml" }
items.each{|item| service.add_id_from_href!(item) }
items
end
def get_by_id(item_id)
item = service.get_catalog_item(item_id).body
item[:vapp_template_id] = item[:Entity][:href].split('/').last
@ -29,4 +29,4 @@ module Fog
end
end
end
end
end

View file

@ -5,32 +5,28 @@ module Fog
module Compute
class VcloudDirector
class Catalogs < Collection
model Fog::Compute::VcloudDirector::Catalog
attribute :organization
private
def get_by_id(item_id)
item = service.get_catalog(item_id).body
%w(:CatalogItems :Link).each {|key_to_delete| item.delete(key_to_delete) }
service.add_id_from_href!(item)
item
end
def item_list
data = service.get_organization(organization.id).body
items = data[:Link].select { |link| link[:type] == "application/vnd.vmware.vcloud.catalog+xml" }
items.each{|item| service.add_id_from_href!(item) }
items
end
end
end
end
end
end

View file

@ -5,9 +5,9 @@ module Fog
class VcloudDirector
class Disk < Model # there is no lazy_load in disks
identity :id
attribute :address
attribute :description
attribute :name
@ -18,7 +18,7 @@ module Fog
attribute :capacity
attribute :bus_sub_type
attribute :bus_type
# TODO Virtual machine disk sizes may only be increased, not decreased.
def capacity=(new_capacity)
has_changed = ( capacity != new_capacity.to_i )
@ -32,11 +32,11 @@ module Fog
service.process_task(response.body)
end
end
def all_disks
attributes[:all_disks] # this is passed at instantiation time
end
def destroy
num_disk = name.scan(/\d+/).first.to_i
data = Fog::Generators::Compute::VcloudDirector::Disks.new(all_disks)
@ -48,4 +48,4 @@ module Fog
end
end
end
end
end

View file

@ -7,9 +7,9 @@ module Fog
class Disks < Collection
model Fog::Compute::VcloudDirector::Disk
attribute :vm
def create(size)
item_list unless @disks
data = Fog::Generators::Compute::VcloudDirector::Disks.new(@disks)
@ -17,24 +17,24 @@ module Fog
response = service.put_vm_disks(vm.id, data.disks)
service.process_task(response.body)
end
def get_by_id(item_id)
item = item_list.detect{ |i| i[:id] == item_id}
item.merge!(:all_disks => @disks, :vm => vm) if item
item
end
def item_list
@disks = service.get_vm_disks(vm.id).body
items = @disks[:disks]
items.each do |disk|
disk[:all_disks] = @disks
items.each do |disk|
disk[:all_disks] = @disks
disk[:vm] = vm
end
items
end
end
end
end
end
end

View file

@ -5,9 +5,9 @@ module Fog
class VcloudDirector
class Network < Model
identity :id
attribute :name
attribute :type
attribute :href
@ -19,8 +19,8 @@ module Fog
attribute :dns2
attribute :dns_suffix
attribute :ip_ranges, :type => :array
end
end
end
end
end

View file

@ -7,25 +7,24 @@ module Fog
class Networks < Collection
model Fog::Compute::VcloudDirector::Network
attribute :organization
private
def get_by_id(item_id)
item = service.get_network(item_id).body
service.add_id_from_href!(item)
item
end
def item_list
data = service.get_organization(organization.id).body
items = data[:Link].select { |link| link[:type] == "application/vnd.vmware.vcloud.orgNetwork+xml" }
items.each{|item| service.add_id_from_href!(item) }
items
end
end
end
end

View file

@ -7,8 +7,7 @@ module Fog
class Organizations < Collection
model Fog::Compute::VcloudDirector::Organization
private
def get_by_id(org_id)
@ -17,14 +16,14 @@ module Fog
service.add_id_from_href!(org)
org
end
def item_list
data = service.get_organizations.body
orgs = data[:Org].is_a?(Hash) ? [data[:Org]] : data[:Org]
orgs.each {|org| service.add_id_from_href!(org)}
orgs
end
end
end
end

View file

@ -5,8 +5,8 @@ module Fog
class VcloudDirector
class Tag < Model
identity :id
attribute :value
@ -19,13 +19,13 @@ module Fog
service.process_task(response.body)
end
end
def destroy
response = service.delete_metadata(vm.id, id)
service.process_task(response.body)
end
def vm
attributes[:vm]
end

View file

@ -7,13 +7,13 @@ module Fog
class Tags < Collection
model Fog::Compute::VcloudDirector::Tag
attribute :vm
def get_by_name(tag_name)
get(tag_name)
end
def create(key,value)
item_list unless @tags
metadata_klass = case service.api_version
@ -26,26 +26,25 @@ module Fog
response = service.post_vm_metadata(vm.id, data.attrs)
service.process_task(response.body)
end
def hash_items
@tags = service.get_metadata(vm.id).body
@tags[:metadata]
end
# private
def item_list
@items =[]
hash_items.each_pair{ |k,v| @items << {:id => k, :value => v }.merge(:vm => vm) }
@items
end
def get_by_id(item_id)
item_list unless @items
@items.detect{ |i| i[:id] == item_id}
@items.detect{ |i| i[:id] == item_id}
end
end
end
end

View file

@ -6,7 +6,6 @@ module Fog
class Vapp < Model
identity :id
attribute :name

View file

@ -7,26 +7,26 @@ module Fog
class Vapps < Collection
model Fog::Compute::VcloudDirector::Vapp
attribute :vdc
private
def get_by_id(item_id)
item = service.get_vapp(item_id).body
%w(:Link).each {|key_to_delete| item.delete(key_to_delete) }
service.add_id_from_href!(item)
item
end
def item_list
data = service.get_vdc(vdc.id).body
items = data[:ResourceEntities][:ResourceEntity].select { |link| link[:type] == "application/vnd.vmware.vcloud.vApp+xml" }
items.each{|item| service.add_id_from_href!(item) }
items
end
end
end
end
end
end

View file

@ -5,9 +5,9 @@ module Fog
class VcloudDirector
class Vdc < Model
identity :id
attribute :name
attribute :type
attribute :href
@ -21,14 +21,13 @@ module Fog
attribute :network_quota ,:aliases => :NetworkQuota, :type => :integer
attribute :vm_quota ,:aliases => :VmQuota, :type => :integer
attribute :is_enabled ,:aliases => :IsEnabled, :type => :boolean
def vapps
requires :id
service.vapps(:vdc => self)
end
end
end
end
end
end

View file

@ -7,26 +7,26 @@ module Fog
class Vdcs < Collection
model Fog::Compute::VcloudDirector::Vdc
attribute :organization
private
def get_by_id(item_id)
item = service.get_vdc(item_id).body
%w(:VdcItems :Link :ResourceEntities).each {|key_to_delete| item.delete(key_to_delete) }
service.add_id_from_href!(item)
item
end
def item_list
data = service.get_organization(organization.id).body
items = data[:Link].select { |link| link[:type] == "application/vnd.vmware.vcloud.vdc+xml" }
items.each{|item| service.add_id_from_href!(item) }
items
end
end
end
end
end
end

View file

@ -1,7 +1,6 @@
require 'fog/core/model'
require 'fog/vcloud_director/models/compute/vm_customization'
module Fog
module Compute
class VcloudDirector
@ -14,21 +13,20 @@ module Fog
attribute :name
attribute :type
attribute :href
attribute :status
attribute :status
attribute :operating_system
attribute :ip_address
attribute :cpu, :type => :integer
attribute :memory
attribute :hard_disks, :aliases => :disks
def reload
# when collection.vapp is nil, it means it's fatherless,
# when collection.vapp is nil, it means it's fatherless,
# vms from different vapps are loaded in the same collection.
# This situation comes from a "query" result
collection.vapp.nil? ? reload_single_vm : super
end
def reload_single_vm
return unless data = begin
collection.get_single_vm(identity)
@ -43,33 +41,33 @@ module Fog
merge_attributes(new_attributes)
self
end
def power_on
response = service.post_vm_poweron(id)
service.process_task(response.body)
end
def tags
requires :id
service.tags(:vm => self)
end
def customization
data = service.get_vm_customization(id).body
service.vm_customizations.new(data)
end
def network
data = service.get_vm_network(id).body
service.vm_networks.new(data)
end
def disks
requires :id
service.disks(:vm => self)
end
def memory=(new_memory)
has_changed = ( memory != new_memory.to_i )
not_first_set = !memory.nil?
@ -79,7 +77,7 @@ module Fog
service.process_task(response.body)
end
end
def cpu=(new_cpu)
has_changed = ( cpu != new_cpu.to_i )
not_first_set = !cpu.nil?
@ -90,8 +88,7 @@ module Fog
end
end
end
end
end
end
end

View file

@ -5,10 +5,9 @@ module Fog
class VcloudDirector
class VmCustomization < Model
identity :id
attribute :type
attribute :href
attribute :enabled
@ -20,22 +19,22 @@ module Fog
attribute :virtual_machine_id
attribute :computer_name
attribute :has_customization_script
# bug: for some reason if the customization_script has /r, is showed here as /n. Looks likes is something in excon
def script
attributes[:customization_script]
end
def script=(new_script)
attributes[:customization_script] = new_script
end
def save
response = service.put_vm_customization(id, attributes)
service.process_task(response.body)
end
end
end
end
end
end

View file

@ -7,11 +7,10 @@ module Fog
class VmCustomizations < Collection
model Fog::Compute::VcloudDirector::VmCustomization
attribute :vm
end
end
end
end
end

View file

@ -5,10 +5,9 @@ module Fog
class VcloudDirector
class VmNetwork < Model
identity :id
attribute :type
attribute :href
attribute :info
@ -19,13 +18,13 @@ module Fog
attribute :is_connected
attribute :mac_address
attribute :ip_address_allocation_mode
def save
response = service.put_vm_network(id, attributes)
service.process_task(response.body)
end
end
end
end
end
end

View file

@ -7,15 +7,15 @@ module Fog
class VmNetworks < Collection
model Fog::Compute::VcloudDirector::VmNetwork
attribute :vm
def get(id)
data = service.get_vm_network(id).body
new(data)
end
end
end
end
end
end

View file

@ -7,9 +7,9 @@ module Fog
class Vms < Collection
model Fog::Compute::VcloudDirector::Vm
attribute :vapp
def get_by_metadata(key, value)
data = service.get_vms_by_metadata(key, value).body
items = data[:vm_records]
@ -23,19 +23,19 @@ module Fog
end
private
def get_by_id(item_id)
item = item_list.detect{ |vm| vm[:id] == item_id }
item
end
def item_list
data = service.get_vms(vapp.id).body # vapp.id
items = data[:vms]
items
end
end
end
end
end
end

View file

@ -3,8 +3,6 @@ module Fog
module Compute
module VcloudDirector
class Disks < VcloudDirectorParser
def reset
@ -17,7 +15,7 @@ module Fog
super
case name
when 'HostResource'
@host_resource = extract_attributes(attributes)
@host_resource = extract_attributes(attributes)
end
end
@ -48,9 +46,8 @@ module Fog
@response[:disks] << @disk
@host_resource = nil
@disk = {}
end
end
end
end

View file

@ -17,14 +17,14 @@
# <Value>adios</Value>
# </MetadataEntry>
# </Metadata>
#
#
#
# {:metadata=>{"buenas si"=>"no tanto ya", "hola"=>"adios"},
# :type=>"application/vnd.vmware.vcloud.metadata+xml",
# :href=>
# "https://example.com/api/vApp/vm-18545e82-d919-4071-ae7e-d1300d9d8112/metadata",
# :id=>"vm-18545e82-d919-4071-ae7e-d1300d9d8112"}
#
#
module Fog
module Parsers
module Compute
@ -57,7 +57,7 @@ module Fog
@response[:metadata].merge!(Hash[@key, @val])
end
end
end
end

View file

@ -74,11 +74,11 @@ module Fog
super
case name
when 'OrgNetwork', 'OrgVdcNetwork' # OrgVdcNetwork belongs to 5.1
network = extract_attributes(attributes)
@response.merge!(network.reject {|key,value| ![:href, :name, :type].include?(key)})
@response[:id] = @response[:href].split('/').last
when 'Description',
@response[:description] = value
network = extract_attributes(attributes)
@response.merge!(network.reject {|key,value| ![:href, :name, :type].include?(key)})
@response[:id] = @response[:href].split('/').last
when 'Description',
@response[:description] = value
end
end
@ -99,7 +99,7 @@ module Fog
@ip_range = {}
end
end
end
end

View file

@ -16,18 +16,18 @@ module Fog
def start_element(name, attributes)
super
case name
when 'OperatingSystemSection'
@in_operating_system = true
when 'Vm'
vm_attrs = extract_attributes(attributes)
@response[:vm].merge!(vm_attrs.reject {|key,value| ![:href, :name, :status, :type].include?(key)})
@response[:vm][:id] = @response[:vm][:href].split('/').last
@response[:vm][:status] = human_status(@response[:vm][:status])
when 'HostResource'
@current_host_resource = extract_attributes(attributes)
when 'Link'
@links << extract_attributes(attributes)
end
when 'OperatingSystemSection'
@in_operating_system = true
when 'Vm'
vm_attrs = extract_attributes(attributes)
@response[:vm].merge!(vm_attrs.reject {|key,value| ![:href, :name, :status, :type].include?(key)})
@response[:vm][:id] = @response[:vm][:href].split('/').last
@response[:vm][:status] = human_status(@response[:vm][:status])
when 'HostResource'
@current_host_resource = extract_attributes(attributes)
when 'Link'
@links << extract_attributes(attributes)
end
end
def end_element(name)
@ -58,19 +58,19 @@ module Fog
when 'Link'
@response[:vm][:links] = @links
end
end
def human_status(status)
case status
when '0', 0
'creating'
when '8', 8
'off'
when '4', 4
'on'
when '0', 0
'creating'
when '8', 8
'off'
when '4', 4
'on'
else
'unknown'
'unknown'
end
end

View file

@ -24,7 +24,7 @@ module Fog
def end_element(name)
case name
when 'Enabled',
when 'Enabled',
@response[:enabled] = (value == "true")
when 'ChangeSid'
@response[:change_sid] = (value == "true")
@ -44,11 +44,10 @@ module Fog
@response[:computer_name] = value
when 'CustomizationScript'
@response[:has_customization_script] = !value.empty?
@response[:customization_script] = CGI::unescapeHTML(value) if @response[:has_customization_script]
@response[:customization_script] = CGI::unescapeHTML(value) if @response[:has_customization_script]
end
end
end
end

View file

@ -102,7 +102,7 @@ module Fog
@response[:ip_address_allocation_mode] = value
end
end
end
end

View file

@ -17,26 +17,26 @@ module Fog
def start_element(name, attributes)
super
case name
when 'OperatingSystemSection'
@in_operating_system = true
when 'VApp'
vapp = extract_attributes(attributes)
@response.merge!(vapp.reject {|key,value| ![:href, :name, :size, :status, :type].include?(key)})
@response[:id] = @response[:href].split('/').last
when 'Vm'
vapp = extract_attributes(attributes)
@vm.merge!(vapp.reject {|key,value| ![:href, :name, :status, :type].include?(key)})
@vm[:id] = @vm[:href].split('/').last
@vm[:vapp_id] = @response[:id]
@vm[:vapp_name] = @response[:name]
@vm[:status] = human_status(@vm[:status])
when 'Children'
@in_children = true
when 'HostResource'
@current_host_resource = extract_attributes(attributes)
when 'Link'
@links << extract_attributes(attributes)
end
when 'OperatingSystemSection'
@in_operating_system = true
when 'VApp'
vapp = extract_attributes(attributes)
@response.merge!(vapp.reject {|key,value| ![:href, :name, :size, :status, :type].include?(key)})
@response[:id] = @response[:href].split('/').last
when 'Vm'
vapp = extract_attributes(attributes)
@vm.merge!(vapp.reject {|key,value| ![:href, :name, :status, :type].include?(key)})
@vm[:id] = @vm[:href].split('/').last
@vm[:vapp_id] = @response[:id]
@vm[:vapp_name] = @response[:name]
@vm[:status] = human_status(@vm[:status])
when 'Children'
@in_children = true
when 'HostResource'
@current_host_resource = extract_attributes(attributes)
when 'Link'
@links << extract_attributes(attributes)
end
end
def end_element(name)
@ -72,19 +72,19 @@ module Fog
@vm = {}
end
end
end
def human_status(status)
case status
when '0', 0
'creating'
when '8', 8
'off'
when '4', 4
'on'
when '0', 0
'creating'
when '8', 8
'off'
when '4', 4
'on'
else
'unknown'
'unknown'
end
end

View file

@ -33,7 +33,6 @@ module Fog
end
end
end
end

View file

@ -2,15 +2,15 @@ module Fog
module Compute
class VcloudDirector
class Real
def delete_metadata(vm_id, metadata_key)
require 'fog/vcloud_director/parsers/compute/metadata'
request(
:expects => 202,
:method => 'DELETE',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/metadata/#{URI.escape(metadata_key)}"
:expects => 202,
:method => 'DELETE',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/metadata/#{URI.escape(metadata_key)}"
)
end

View file

@ -2,13 +2,13 @@ module Fog
module Compute
class VcloudDirector
class Real
def get_catalog(catalog_uuid)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "catalog/#{catalog_uuid}"
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "catalog/#{catalog_uuid}"
)
end

View file

@ -5,13 +5,12 @@ module Fog
def get_catalog_item(catalog_item_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "catalogItem/#{catalog_item_id}"
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "catalogItem/#{catalog_item_id}"
)
end
end
end

View file

@ -2,14 +2,14 @@ module Fog
module Compute
class VcloudDirector
class Real
def get_href(href)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:override_path => true,
:path => URI.parse(href).path
:path => URI.parse(href).path
)
end

View file

@ -2,15 +2,15 @@ module Fog
module Compute
class VcloudDirector
class Real
def get_metadata(vm_id)
require 'fog/vcloud_director/parsers/compute/metadata'
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::Metadata.new,
:path => "vApp/#{vm_id}/metadata/"
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::Metadata.new,
:path => "vApp/#{vm_id}/metadata/"
)
end

View file

@ -2,19 +2,20 @@ module Fog
module Compute
class VcloudDirector
class Real
require 'fog/vcloud_director/parsers/compute/network'
def get_network(network_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::Network.new,
:path => "network/#{network_id}"
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::Network.new,
:path => "network/#{network_id}"
)
end
end
end
end
end

View file

@ -4,18 +4,15 @@ module Fog
class Real
def get_organization(organization_id)
request({
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "org/#{organization_id}"
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "org/#{organization_id}"
})
end
end
end
end
end

View file

@ -3,19 +3,16 @@ module Fog
class VcloudDirector
class Real
def get_organizations
request({
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "org"
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "org"
})
end
end
end
end
end

View file

@ -5,11 +5,12 @@ module Fog
def get_request(uri)
request(
:expects => 200,
:method => 'GET',
:path => uri
:expects => 200,
:method => 'GET',
:path => uri
)
end
end
end
end

View file

@ -5,16 +5,14 @@ module Fog
def get_task(task_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "task/#{task_id}"
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "task/#{task_id}"
)
end
end
end
end
end
end

View file

@ -5,16 +5,14 @@ module Fog
def get_tasks_list(tasks_list_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "tasksList/#{tasks_list_id}"
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "tasksList/#{tasks_list_id}"
)
end
end
end
end
end
end

View file

@ -5,10 +5,10 @@ module Fog
def get_vapp(vapp_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vapp_id}"
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vapp_id}"
)
end

View file

@ -5,13 +5,13 @@ module Fog
def get_vapp_template(vapp_template_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "vAppTemplate/#{vapp_template_id}"
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "vAppTemplate/#{vapp_template_id}"
)
end
end
end
end

View file

@ -5,16 +5,14 @@ module Fog
def get_vdc(vdc_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "vdc/#{vdc_id}"
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "vdc/#{vdc_id}"
)
end
end
end
end
end
end

View file

@ -2,14 +2,15 @@ module Fog
module Compute
class VcloudDirector
class Real
require 'fog/vcloud_director/parsers/compute/vm'
def get_vm(vm_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::Vm.new,
:path => "vApp/#{vm_id}"
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::Vm.new,
:path => "vApp/#{vm_id}"
)
end

View file

@ -2,13 +2,13 @@ module Fog
module Compute
class VcloudDirector
class Real
def get_vm_cpu(vm_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/cpu"
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/cpu"
)
end

View file

@ -2,14 +2,15 @@ module Fog
module Compute
class VcloudDirector
class Real
require 'fog/vcloud_director/parsers/compute/vm_customization'
def get_vm_customization(vm_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::VmCustomization.new,
:path => "vApp/#{vm_id}/guestCustomizationSection"
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::VmCustomization.new,
:path => "vApp/#{vm_id}/guestCustomizationSection"
)
end

View file

@ -2,15 +2,15 @@ module Fog
module Compute
class VcloudDirector
class Real
require 'fog/vcloud_director/parsers/compute/disks'
def get_vm_disks(vm_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::Disks.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/disks"
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::Disks.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/disks"
)
end

View file

@ -2,13 +2,13 @@ module Fog
module Compute
class VcloudDirector
class Real
def get_vm_memory(vm_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/memory"
:expects => 200,
:method => 'GET',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/memory"
)
end

View file

@ -2,15 +2,15 @@ module Fog
module Compute
class VcloudDirector
class Real
require 'fog/vcloud_director/parsers/compute/vm_network'
def get_vm_network(vm_id)
require 'fog/vcloud_director/parsers/compute/vm_network'
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::VmNetwork.new,
:path => "vApp/#{vm_id}/networkConnectionSection/"
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::VmNetwork.new,
:path => "vApp/#{vm_id}/networkConnectionSection/"
)
end

View file

@ -2,14 +2,15 @@ module Fog
module Compute
class VcloudDirector
class Real
require 'fog/vcloud_director/parsers/compute/vms'
def get_vms(vapp_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::Vms.new,
:path => "vApp/#{vapp_id}"
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::Vms.new,
:path => "vApp/#{vapp_id}"
)
end

View file

@ -2,18 +2,18 @@ module Fog
module Compute
class VcloudDirector
class Real
require 'fog/vcloud_director/parsers/compute/vms_by_metadata'
def get_vms_by_metadata(key,value)
require 'fog/vcloud_director/parsers/compute/vms_by_metadata'
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::VmsByMetadata.new,
:path => "vms/query?format=records&filter=metadata:#{key}==STRING:#{value}"
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Compute::VcloudDirector::VmsByMetadata.new,
:path => "vms/query?format=records&filter=metadata:#{key}==STRING:#{value}"
)
end
end
end
end

View file

@ -1,27 +1,27 @@
module Fog
module Compute
module Helper
def catalog_item_end_point(catalog_item_id = nil)
end_point + ( catalog_item_id ? "catalogItem/#{catalog_item_id}" : "catalogItem" )
end
def network_end_point(network_id = nil)
end_point + ( network_id ? "network/#{network_id}" : "network" )
end
def vapp_template_end_point(vapp_template_id = nil)
end_point + ( vapp_template_id ? "vAppTemplate/#{vapp_template_id}" : "vAppTemplate" )
end
def vdc_end_point(vdc_id = nil)
end_point + ( vdc_id ? "vdc/#{vdc_id}" : "vdc" )
end
def endpoint
end_point
end
# A single organization can have multiple Org vDCs.
def default_vdc_id
if default_organization_id
@ -39,7 +39,7 @@ module Fog
nil
end
end
# A single organization can have multiple Org vDCs.
def default_vdc_body
return nil unless default_vdc_id
@ -49,7 +49,7 @@ module Fog
response.data[:body]
end
end
def default_network_name
return nil unless default_vdc_body
return nil unless network = default_vdc_body[:AvailableNetworks][:Network]
@ -61,7 +61,7 @@ module Fog
return nil unless network = default_vdc_body[:AvailableNetworks][:Network]
network[:href].split('/').last
end
def default_network_name
if default_vdc_id
@default_network_name ||= begin
@ -70,7 +70,7 @@ module Fog
end
end
end
def default_organization_id
@default_organization_id ||= begin
org = get_organizations.body[:Org]
@ -82,13 +82,12 @@ module Fog
def default_organization_body
return nil unless default_organization_id
@default_organization_body ||= begin
response = get_organization(default_organization_id)
return nil unless response.respond_to? 'body'
response.body
response = get_organization(default_organization_id)
return nil unless response.respond_to? 'body'
response.body
end
end
end
end
end

View file

@ -2,32 +2,32 @@ module Fog
module Compute
class VcloudDirector
class Real
#TODO move all the logic to a generator
# TODO move all the logic to a generator
def instantiate_vapp_template(vapp_name, template_id, options = {})
params = populate_uris(options.merge(:vapp_name => vapp_name, :template_id => template_id))
validate_uris(params)
data = generate_instantiate_vapp_template_request(params)
request(
:body => data,
:body => data,
:expects => 201,
:headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml' },
:method => 'POST',
:parser => Fog::ToHashDocument.new,
:path => "vdc/#{params[:vdc_id]}/action/instantiateVAppTemplate"
:method => 'POST',
:parser => Fog::ToHashDocument.new,
:path => "vdc/#{params[:vdc_id]}/action/instantiateVAppTemplate"
)
end
def validate_uris(options ={})
[:vdc_uri, :network_uri].each do |opt_uri|
result = default_organization_body[:Link].detect {|org| org[:href] == options[opt_uri]}
raise("#{opt_uri}: #{options[opt_uri]} not found") unless result
end
end
def populate_uris(options = {})
options[:vdc_id] ||= default_vdc_id
options[:vdc_uri] = vdc_end_point(options[:vdc_id])
@ -47,7 +47,7 @@ module Fog
#end
options
end
def generate_instantiate_vapp_template_request(options ={})
xml = Builder::XmlMarkup.new
xml.InstantiateVAppTemplateParams(xmlns.merge!(:name => options[:vapp_name], :"xml:lang" => "en")) {
@ -57,10 +57,10 @@ module Fog
if options[:network_uri]
xml.NetworkConfigSection {
xml.tag!("ovf:Info"){ "Configuration parameters for logical networks" }
xml.NetworkConfig("networkName" => options[:network_name]) {
xml.Configuration {
xml.ParentNetwork(:href => options[:network_uri])
xml.FenceMode("bridged")
xml.NetworkConfig("networkName" => options[:network_name]) {
xml.Configuration {
xml.ParentNetwork(:href => options[:network_uri])
xml.FenceMode("bridged")
}
}
}
@ -71,16 +71,16 @@ module Fog
xml.AllEULAsAccepted("true")
}
end
def xmlns
{ 'xmlns' => "http://www.vmware.com/vcloud/v1.5",
"xmlns:ovf" => "http://schemas.dmtf.org/ovf/envelope/1",
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
"xmlns:xsd" => "http://www.w3.org/2001/XMLSchema"
}
{
'xmlns' => "http://www.vmware.com/vcloud/v1.5",
"xmlns:ovf" => "http://schemas.dmtf.org/ovf/envelope/1",
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
"xmlns:xsd" => "http://www.w3.org/2001/XMLSchema"
}
end
# def validate_instantiate_vapp_template_options options
# # :network_uri removed, if not specified will use template network config.
# valid_opts = [:catalog_item_uri, :name, :vdc_uri]

View file

@ -2,26 +2,27 @@ module Fog
module Compute
class VcloudDirector
class Real
require 'fog/vcloud_director/generators/compute/metadata'
def post_vm_metadata(vm_id, metadata={})
def post_vm_metadata(vm_id, metadata={})
metadata_klass = case api_version
when '5.1' ; Fog::Generators::Compute::VcloudDirector::MetadataV51
when '1.5' ; Fog::Generators::Compute::VcloudDirector::MetadataV15
else raise "API version: #{api_version} not supported"
end
data = metadata_klass.new(metadata)
request(
:body => data.generate_xml,
:expects => 202,
:body => data.generate_xml,
:expects => 202,
:headers => { 'Content-Type' => "application/vnd.vmware.vcloud.metadata+xml" },
:method => 'POST',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/metadata/"
:method => 'POST',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/metadata/"
)
end
end
end
end

View file

@ -2,16 +2,16 @@ module Fog
module Compute
class VcloudDirector
class Real
def post_vm_poweron(vm_id)
def post_vm_poweron(vm_id)
request(
:expects => 202,
:method => 'POST',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/power/action/powerOn"
:expects => 202,
:method => 'POST',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/power/action/powerOn"
)
end
end
end
end

View file

@ -2,23 +2,23 @@ module Fog
module Compute
class VcloudDirector
class Real
def put_metadata_value(vm_id, metadata_key, metadata_value)
def put_metadata_value(vm_id, metadata_key, metadata_value)
body="
<MetadataValue xmlns=\"http://www.vmware.com/vcloud/v1.5\">
<Value>#{metadata_value}</Value>
</MetadataValue>"
request(
:body => body,
:expects => 202,
:body => body,
:expects => 202,
:headers => { 'Content-Type' => "application/vnd.vmware.vcloud.metadata.value+xml" },
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/metadata/#{URI.escape(metadata_key)}"
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/metadata/#{URI.escape(metadata_key)}"
)
end
end
end
end

View file

@ -2,7 +2,7 @@ module Fog
module Compute
class VcloudDirector
class Real
def put_vm_cpu(vm_id, num_cpus)
data = <<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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns12="http://www.vmware.com/vcloud/v1.5" ns12:href="#{endpoint}vApp/#{vm_id}/virtualHardwareSection/cpu" ns12:type="application/vnd.vmware.vcloud.rasdItem+xml" 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">
@ -17,15 +17,17 @@ module Fog
<Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml" href="#{endpoint}vApp/#{vm_id}/virtualHardwareSection/cpu"/>
</Item>
EOF
request(
:body => data,
:expects => 202,
:body => data,
:expects => 202,
:headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.rasdItem+xml' },
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/cpu"
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/cpu"
)
end
end
end
end

View file

@ -2,20 +2,22 @@ module Fog
module Compute
class VcloudDirector
class Real
require 'fog/vcloud_director/generators/compute/customization'
def put_vm_customization(vm_id, customization={})
data = Fog::Generators::Compute::VcloudDirector::Customization.new(customization)
request(
:body => data.generate_xml,
:expects => 202,
:body => data.generate_xml,
:expects => 202,
:headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.guestCustomizationSection+xml' },
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/guestCustomizationSection"
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/guestCustomizationSection"
)
end
end
end
end

View file

@ -2,21 +2,23 @@ module Fog
module Compute
class VcloudDirector
class Real
require 'fog/vcloud_director/generators/compute/disks'
# disks is the body of get_vm_disks
def put_vm_disks(vm_id, disks=[])
data = Fog::Generators::Compute::VcloudDirector::Disks.new(disks)
request(
:body => data.generate_xml,
:expects => 202,
:body => data.generate_xml,
:expects => 202,
:headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.rasdItemsList+xml' },
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/disks"
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/disks"
)
end
end
end
end

View file

@ -2,7 +2,7 @@ module Fog
module Compute
class VcloudDirector
class Real
def put_vm_memory(vm_id, memory)
data = <<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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns12="http://www.vmware.com/vcloud/v1.5" ns12:href="#{endpoint}vApp/#{vm_id}/virtualHardwareSection/memory" ns12:type="application/vnd.vmware.vcloud.rasdItem+xml" 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">
@ -17,15 +17,17 @@ module Fog
<Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml" href="#{endpoint}vApp/#{vm_id}/virtualHardwareSection/memory"/>
</Item>
EOF
request(
:body => data,
:expects => 202,
:body => data,
:expects => 202,
:headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.rasdItem+xml' },
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/memory"
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/virtualHardwareSection/memory"
)
end
end
end
end

View file

@ -2,21 +2,22 @@ module Fog
module Compute
class VcloudDirector
class Real
require 'fog/vcloud_director/generators/compute/vm_network'
def put_vm_network(vm_id, network={})
require 'fog/vcloud_director/generators/compute/vm_network'
data = Fog::Generators::Compute::VcloudDirector::VmNetwork.new(network)
request(
:body => data.generate_xml,
:expects => 202,
:body => data.generate_xml,
:expects => 202,
:headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.networkConnectionSection+xml' },
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/networkConnectionSection/"
:method => 'PUT',
:parser => Fog::ToHashDocument.new,
:path => "vApp/#{vm_id}/networkConnectionSection/"
)
end
end
end
end

View file

@ -2,21 +2,24 @@ module Fog
module Compute
class VcloudDirector
class Real
def undeploy(vapp_id)
body = <<EOF
<UndeployVAppParams xmlns="http://www.vmware.com/vcloud/v1.5">
<UndeployPowerAction>shutdown</UndeployPowerAction>
</UndeployVAppParams>
EOF
request(
:body => body,
:expects => 202,
:method => 'POST',
:parser => Fog::ToHashDocument.new,
:parser => Fog::ToHashDocument.new,
:headers => {'Content-Type' => 'application/vnd.vmware.vcloud.undeployVAppParams+xml' },
:path => "vApp/#{vapp_id}/action/undeploy"
)
end
end
end
end