2014-02-01 21:13:17 -05:00
|
|
|
require 'fog/vcloud_director/core'
|
2013-06-11 09:06:30 -04:00
|
|
|
|
2013-08-27 05:19:54 -04:00
|
|
|
class VcloudDirectorParser < Fog::Parsers::Base
|
2013-06-18 10:57:32 -04:00
|
|
|
def extract_attributes(attributes_xml)
|
|
|
|
attributes = {}
|
|
|
|
until attributes_xml.empty?
|
|
|
|
if attributes_xml.first.is_a?(Array)
|
|
|
|
until attributes_xml.first.empty?
|
|
|
|
attribute = attributes_xml.first.shift
|
2013-07-09 09:00:15 -04:00
|
|
|
attributes[attribute.localname.to_sym] = attribute.value
|
2013-06-18 10:57:32 -04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
attribute = attributes_xml.shift
|
2013-07-09 09:00:15 -04:00
|
|
|
attributes[attribute.localname.to_sym] = attribute.value
|
2013-06-18 10:57:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
attributes
|
|
|
|
end
|
|
|
|
end
|
2013-06-11 09:06:30 -04:00
|
|
|
|
2013-07-08 14:31:37 -04:00
|
|
|
class NonLoaded
|
|
|
|
end
|
2013-06-11 09:06:30 -04:00
|
|
|
|
2013-06-18 10:57:32 -04:00
|
|
|
module Fog
|
|
|
|
module Compute
|
2013-08-27 05:19:54 -04:00
|
|
|
class VcloudDirector < Fog::Service
|
2013-09-16 13:13:09 -04:00
|
|
|
module Defaults
|
|
|
|
PATH = '/api'
|
|
|
|
PORT = 443
|
|
|
|
SCHEME = 'https'
|
|
|
|
API_VERSION = '5.1'
|
|
|
|
end
|
|
|
|
|
2013-10-13 15:46:41 -04:00
|
|
|
class ServiceError < Fog::VcloudDirector::Errors::ServiceError; end
|
|
|
|
|
|
|
|
class BadRequest < Fog::VcloudDirector::Errors::BadRequest; end
|
|
|
|
class Unauthorized < Fog::VcloudDirector::Errors::Unauthorized; end
|
|
|
|
class Forbidden < Fog::VcloudDirector::Errors::Forbidden; end
|
|
|
|
class Conflict < Fog::VcloudDirector::Errors::Conflict; end
|
2014-03-10 15:43:00 -04:00
|
|
|
class MalformedResponse < Fog::VcloudDirector::Errors::MalformedResponse; end
|
2013-10-13 15:46:41 -04:00
|
|
|
|
|
|
|
class DuplicateName < Fog::VcloudDirector::Errors::DuplicateName; end
|
|
|
|
class TaskError < Fog::VcloudDirector::Errors::TaskError; end
|
2013-09-16 13:13:09 -04:00
|
|
|
|
|
|
|
requires :vcloud_director_username, :vcloud_director_password, :vcloud_director_host
|
2013-10-16 03:15:32 -04:00
|
|
|
recognizes :vcloud_director_api_version, :vcloud_director_show_progress
|
2013-09-16 13:13:09 -04:00
|
|
|
|
|
|
|
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
|
2014-05-20 10:57:22 -04:00
|
|
|
model :custom_field
|
2014-05-20 10:51:47 -04:00
|
|
|
collection :custom_fields
|
2013-09-16 13:13:09 -04:00
|
|
|
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
|
2013-09-30 21:36:20 -04:00
|
|
|
model :media
|
|
|
|
collection :medias # sic
|
2013-09-16 13:13:09 -04:00
|
|
|
|
|
|
|
request_path 'fog/vcloud_director/requests/compute'
|
2013-10-10 02:27:34 -04:00
|
|
|
request :delete_catalog_item
|
|
|
|
request :delete_catalog_item_metadata_item_metadata
|
|
|
|
request :delete_disk
|
|
|
|
request :delete_disk_metadata_item_metadata
|
2013-10-08 13:46:06 -04:00
|
|
|
request :delete_logout
|
2013-10-01 03:43:28 -04:00
|
|
|
request :delete_media
|
2013-10-10 02:27:34 -04:00
|
|
|
request :delete_media_metadata_item_metadata
|
2013-12-13 07:17:33 -05:00
|
|
|
request :delete_network
|
2013-10-08 13:46:06 -04:00
|
|
|
request :delete_shadow_vm
|
2013-10-01 03:43:28 -04:00
|
|
|
request :delete_vapp
|
|
|
|
request :delete_vapp_metadata_item_metadata
|
2013-10-10 02:27:34 -04:00
|
|
|
request :delete_vapp_template
|
|
|
|
request :delete_vapp_template_metadata_item_metadata
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_allocated_ip_addresses
|
2013-09-16 13:13:09 -04:00
|
|
|
request :get_catalog
|
|
|
|
request :get_catalog_item
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_catalog_item_metadata
|
2013-10-08 15:18:06 -04:00
|
|
|
request :get_catalog_item_metadata_item_metadata
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_catalog_metadata
|
2013-10-08 15:18:06 -04:00
|
|
|
request :get_catalog_metadata_item_metadata
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_catalogs_from_query
|
2013-10-10 02:27:34 -04:00
|
|
|
request :get_control_access_params_catalog
|
|
|
|
request :get_control_access_params_vapp
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_cpu_rasd_item
|
|
|
|
request :get_current_session
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_disk
|
|
|
|
request :get_disk_metadata
|
2013-10-08 15:18:06 -04:00
|
|
|
request :get_disk_metadata_item_metadata
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_disk_owner
|
|
|
|
request :get_disks_from_query
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_disks_rasd_items_list
|
2013-10-13 04:37:11 -04:00
|
|
|
request :get_edge_gateway
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_entity
|
2013-10-14 18:34:34 -04:00
|
|
|
request :get_execute_query
|
2013-10-13 19:50:11 -04:00
|
|
|
request :get_groups_from_query
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_guest_customization_system_section_vapp
|
2013-10-10 02:27:34 -04:00
|
|
|
request :get_guest_customization_system_section_vapp_template
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_href # this is used for manual testing
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_lease_settings_section_vapp
|
2013-10-10 02:27:34 -04:00
|
|
|
request :get_lease_settings_section_vapp_template
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_media
|
2013-10-10 02:27:34 -04:00
|
|
|
request :get_media_drives_rasd_items_list
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_media_metadata
|
2013-10-08 15:18:06 -04:00
|
|
|
request :get_media_metadata_item_metadata
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_media_owner
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_medias_from_query
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_memory_rasd_item
|
|
|
|
request :get_metadata
|
|
|
|
request :get_network
|
2013-10-10 02:27:34 -04:00
|
|
|
request :get_network_cards_items_list
|
2014-02-18 06:08:35 -05:00
|
|
|
request :get_network_complete
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_network_config_section_vapp
|
2013-10-10 02:27:34 -04:00
|
|
|
request :get_network_config_section_vapp_template
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_network_connection_system_section_vapp
|
2013-10-10 02:27:34 -04:00
|
|
|
request :get_network_connection_system_section_vapp_template
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_network_metadata
|
2013-10-08 15:18:06 -04:00
|
|
|
request :get_network_metadata_item_metadata
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_network_section_vapp
|
2013-10-10 02:27:34 -04:00
|
|
|
request :get_network_section_vapp_template
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_operating_system_section
|
2013-10-15 17:41:08 -04:00
|
|
|
request :get_org_settings
|
2013-10-13 04:47:37 -04:00
|
|
|
request :get_org_vdc_gateways
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_organization
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_organization_metadata
|
2013-10-08 15:18:06 -04:00
|
|
|
request :get_organization_metadata_item_metadata
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_organizations
|
2013-10-13 19:50:11 -04:00
|
|
|
request :get_organizations_from_query
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_product_sections_vapp
|
2013-10-10 02:27:34 -04:00
|
|
|
request :get_product_sections_vapp_template
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_request # this is used for manual testing
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_runtime_info_section_type
|
2013-10-10 02:27:34 -04:00
|
|
|
request :get_serial_ports_items_list
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_shadow_vm
|
|
|
|
request :get_snapshot_section
|
|
|
|
request :get_startup_section
|
2013-10-01 04:45:01 -04:00
|
|
|
request :get_supported_systems_info
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_supported_versions
|
2013-09-16 13:13:09 -04:00
|
|
|
request :get_task
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_task_list
|
2013-10-13 09:34:55 -04:00
|
|
|
request :get_thumbnail
|
2013-10-13 19:50:11 -04:00
|
|
|
request :get_users_from_query
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_vapp
|
|
|
|
request :get_vapp_metadata
|
2013-10-08 15:18:06 -04:00
|
|
|
request :get_vapp_metadata_item_metadata
|
2013-10-01 21:14:52 -04:00
|
|
|
request :get_vapp_ovf_descriptor
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_vapp_owner
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_vapp_template
|
2013-10-10 02:27:34 -04:00
|
|
|
request :get_vapp_template_customization_system_section
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_vapp_template_metadata
|
2013-10-08 15:18:06 -04:00
|
|
|
request :get_vapp_template_metadata_item_metadata
|
2013-10-01 21:14:52 -04:00
|
|
|
request :get_vapp_template_ovf_descriptor
|
2013-10-10 02:27:34 -04:00
|
|
|
request :get_vapp_template_owner
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_vapp_templates_from_query
|
|
|
|
request :get_vapps_in_lease_from_query
|
2013-10-15 17:41:08 -04:00
|
|
|
request :get_vcloud
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_vdc
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_vdc_metadata
|
2013-10-08 15:18:06 -04:00
|
|
|
request :get_vdc_metadata_item_metadata
|
|
|
|
request :get_vdc_storage_class
|
|
|
|
request :get_vdc_storage_class_metadata
|
|
|
|
request :get_vdc_storage_class_metadata_item_metadata
|
2013-10-13 19:50:11 -04:00
|
|
|
request :get_vdcs_from_query
|
2013-10-10 02:27:34 -04:00
|
|
|
request :get_virtual_hardware_section
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_vm
|
2013-10-10 02:27:34 -04:00
|
|
|
request :get_vm_capabilities
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_vm_compliance_results
|
2013-09-16 13:13:09 -04:00
|
|
|
request :get_vm_customization
|
|
|
|
request :get_vm_disks
|
|
|
|
request :get_vm_network
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_vm_pending_question
|
2013-10-01 03:43:28 -04:00
|
|
|
request :get_vms
|
2013-09-16 13:13:09 -04:00
|
|
|
request :get_vms_by_metadata
|
2013-10-20 14:52:14 -04:00
|
|
|
request :get_vms_disk_attached_to
|
2013-10-08 13:46:06 -04:00
|
|
|
request :get_vms_in_lease_from_query
|
2013-10-13 17:10:30 -04:00
|
|
|
request :instantiate_vapp_template # to be deprecated
|
2013-10-10 02:27:34 -04:00
|
|
|
request :post_acquire_ticket
|
2013-10-15 18:19:50 -04:00
|
|
|
request :post_answer_vm_pending_question
|
2013-10-10 02:27:34 -04:00
|
|
|
request :post_attach_disk
|
2013-10-01 03:43:28 -04:00
|
|
|
request :post_cancel_task
|
2013-10-01 21:58:20 -04:00
|
|
|
request :post_capture_vapp
|
2013-10-08 13:46:06 -04:00
|
|
|
request :post_check_vm_compliance
|
|
|
|
request :post_clone_media
|
|
|
|
request :post_clone_vapp
|
|
|
|
request :post_clone_vapp_template
|
2013-10-15 07:42:22 -04:00
|
|
|
request :post_configure_edge_gateway_services
|
2013-10-10 02:27:34 -04:00
|
|
|
request :post_consolidate_vm_vapp
|
|
|
|
request :post_consolidate_vm_vapp_template
|
2013-12-31 07:21:12 -05:00
|
|
|
request :post_create_catalog_item
|
2013-12-13 11:34:31 -05:00
|
|
|
request :post_create_org_vdc_network
|
2013-10-08 13:46:06 -04:00
|
|
|
request :post_deploy_vapp
|
2013-10-10 02:27:34 -04:00
|
|
|
request :post_detach_disk
|
2013-10-08 13:46:06 -04:00
|
|
|
request :post_disable_nested_hv
|
2013-10-10 02:27:34 -04:00
|
|
|
request :post_disable_vapp_template_download
|
|
|
|
request :post_discard_vapp_state
|
|
|
|
request :post_eject_cd_rom
|
2013-10-08 13:46:06 -04:00
|
|
|
request :post_enable_nested_hv
|
2013-10-10 02:27:34 -04:00
|
|
|
request :post_enable_vapp_template_download
|
2013-10-08 13:46:06 -04:00
|
|
|
request :post_enter_maintenance_mode
|
|
|
|
request :post_exit_maintenance_mode
|
2013-10-10 02:27:34 -04:00
|
|
|
request :post_insert_cd_rom
|
2013-10-08 13:46:06 -04:00
|
|
|
request :post_install_vmware_tools
|
2013-10-13 17:10:30 -04:00
|
|
|
request :post_instantiate_vapp_template
|
2013-10-08 13:46:06 -04:00
|
|
|
request :post_login_session
|
2013-10-01 03:43:28 -04:00
|
|
|
request :post_power_off_vapp
|
|
|
|
request :post_power_on_vapp
|
2013-10-01 05:23:57 -04:00
|
|
|
request :post_reboot_vapp
|
2013-10-10 02:27:34 -04:00
|
|
|
request :post_remove_all_snapshots
|
2013-10-01 05:23:57 -04:00
|
|
|
request :post_reset_vapp
|
2013-10-10 02:27:34 -04:00
|
|
|
request :post_revert_snapshot
|
2013-10-01 05:23:57 -04:00
|
|
|
request :post_shutdown_vapp
|
|
|
|
request :post_suspend_vapp
|
2013-10-01 03:43:28 -04:00
|
|
|
request :post_undeploy_vapp
|
2013-10-13 04:37:11 -04:00
|
|
|
request :post_update_catalog_item_metadata
|
|
|
|
request :post_update_disk_metadata
|
|
|
|
request :post_update_media_metadata
|
|
|
|
request :post_update_vapp_metadata
|
|
|
|
request :post_update_vapp_template_metadata
|
2013-10-08 13:46:06 -04:00
|
|
|
request :post_upgrade_hw_version
|
2013-10-20 14:52:14 -04:00
|
|
|
request :post_upload_disk
|
2013-09-30 20:47:57 -04:00
|
|
|
request :post_upload_media
|
2013-10-08 13:46:06 -04:00
|
|
|
request :post_upload_vapp_template
|
2013-10-13 04:37:11 -04:00
|
|
|
request :put_catalog_item_metadata_item_metadata
|
2013-10-01 03:43:28 -04:00
|
|
|
request :put_cpu
|
2013-10-13 04:37:11 -04:00
|
|
|
request :put_disk_metadata_item_metadata
|
2013-10-01 03:43:28 -04:00
|
|
|
request :put_disks
|
|
|
|
request :put_guest_customization_section_vapp
|
2013-10-13 04:37:11 -04:00
|
|
|
request :put_media_metadata_item_metadata
|
2013-10-01 03:43:28 -04:00
|
|
|
request :put_memory
|
2013-10-13 04:37:11 -04:00
|
|
|
request :put_metadata_value # deprecated
|
2014-06-02 17:12:08 -04:00
|
|
|
request :put_network
|
2013-10-01 03:43:28 -04:00
|
|
|
request :put_network_connection_system_section_vapp
|
2014-06-18 10:28:29 -04:00
|
|
|
request :put_product_sections
|
2013-10-01 03:43:28 -04:00
|
|
|
request :put_vapp_metadata_item_metadata
|
2013-12-15 13:49:29 -05:00
|
|
|
request :put_vapp_name_and_description
|
2013-10-13 04:37:11 -04:00
|
|
|
request :put_vapp_template_metadata_item_metadata
|
2013-12-04 06:45:03 -05:00
|
|
|
request :put_vm
|
2013-10-15 18:27:43 -04:00
|
|
|
request :put_vm_capabilities
|
2013-09-16 13:13:09 -04:00
|
|
|
|
|
|
|
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)
|
2014-05-22 21:40:43 -04:00
|
|
|
item_found = item_list.find {|item| item[:name] == item_name}
|
2013-09-16 13:13:09 -04:00
|
|
|
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
|
2013-06-11 09:06:30 -04:00
|
|
|
|
2013-09-16 13:13:09 -04:00
|
|
|
class Real
|
2013-10-08 14:43:06 -04:00
|
|
|
extend Fog::Deprecation
|
|
|
|
deprecate :auth_token, :vcloud_token
|
|
|
|
|
2013-10-16 03:15:32 -04:00
|
|
|
attr_reader :end_point, :api_version, :show_progress
|
|
|
|
alias_method :show_progress?, :show_progress
|
2013-09-16 13:13:09 -04:00
|
|
|
|
|
|
|
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
|
2014-02-26 19:50:35 -05:00
|
|
|
@connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
|
2013-09-16 13:13:09 -04:00
|
|
|
@end_point = "#{@scheme}://#{@host}#{@path}/"
|
|
|
|
@api_version = options[:vcloud_director_api_version] || Fog::Compute::VcloudDirector::Defaults::API_VERSION
|
2013-10-16 03:15:32 -04:00
|
|
|
@show_progress = options[:vcloud_director_show_progress]
|
|
|
|
@show_progress = $stdin.tty? if @show_progress.nil?
|
2013-09-16 13:13:09 -04:00
|
|
|
end
|
|
|
|
|
2013-10-08 14:43:06 -04:00
|
|
|
def vcloud_token
|
|
|
|
login if @vcloud_token.nil?
|
|
|
|
@vcloud_token
|
2013-09-16 13:13:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def org_name
|
|
|
|
login if @org_name.nil?
|
|
|
|
@org_name
|
|
|
|
end
|
|
|
|
|
2013-10-13 01:30:38 -04:00
|
|
|
def user_name
|
|
|
|
login if @user_name.nil?
|
|
|
|
@user_name
|
|
|
|
end
|
|
|
|
|
2013-09-16 13:13:09 -04:00
|
|
|
def reload
|
|
|
|
@connection.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
def request(params)
|
|
|
|
begin
|
|
|
|
do_request(params)
|
2014-03-17 17:47:37 -04:00
|
|
|
rescue Excon::Errors::SocketError::EOFError
|
2014-03-10 15:43:00 -04:00
|
|
|
# This error can occur if Vcloud receives a request from a network
|
|
|
|
# it deems to be unauthorized; no HTTP response is sent, but the
|
|
|
|
# connection is sent a signal to terminate early.
|
|
|
|
raise(
|
|
|
|
MalformedResponse, "Connection unexpectedly terminated by vcloud"
|
|
|
|
)
|
2013-09-16 13:13:09 -04:00
|
|
|
# this is to know if Excon::Errors::Unauthorized really happens
|
|
|
|
#rescue Excon::Errors::Unauthorized
|
2013-10-08 14:43:06 -04:00
|
|
|
# login
|
2013-09-16 13:13:09 -04:00
|
|
|
# do_request(params)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-27 11:32:49 -04:00
|
|
|
# @api private
|
2013-09-16 13:13:09 -04:00
|
|
|
def do_request(params)
|
2013-10-08 14:43:06 -04:00
|
|
|
headers = {
|
|
|
|
'Accept' => "application/*+xml;version=#{@api_version}",
|
|
|
|
'x-vcloud-authorization' => vcloud_token
|
|
|
|
}
|
2013-09-16 13:13:09 -04:00
|
|
|
if params[:path]
|
|
|
|
if params[:override_path] == true
|
|
|
|
path = params[:path]
|
|
|
|
else
|
|
|
|
path = "#{@path}/#{params[:path]}"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
path = "#{@path}"
|
|
|
|
end
|
|
|
|
@connection.request({
|
2013-10-13 05:11:50 -04:00
|
|
|
:body => params[:body],
|
|
|
|
:expects => params[:expects],
|
|
|
|
:headers => headers.merge!(params[:headers] || {}),
|
|
|
|
:idempotent => params[:idempotent],
|
|
|
|
:method => params[:method],
|
|
|
|
:parser => params[:parser],
|
2013-10-13 19:50:11 -04:00
|
|
|
:path => path,
|
|
|
|
:query => params[:query]
|
2013-09-16 13:13:09 -04:00
|
|
|
})
|
2013-10-13 15:46:41 -04:00
|
|
|
rescue Excon::Errors::HTTPStatusError => error
|
|
|
|
raise case error
|
|
|
|
when Excon::Errors::BadRequest then BadRequest.slurp(error);
|
|
|
|
when Excon::Errors::Unauthorized then Unauthorized.slurp(error);
|
|
|
|
when Excon::Errors::Forbidden then Forbidden.slurp(error);
|
|
|
|
when Excon::Errors::Conflict then Conflict.slurp(error);
|
|
|
|
else ServiceError.slurp(error)
|
2013-09-16 13:13:09 -04:00
|
|
|
end
|
|
|
|
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? }
|
2013-10-13 15:46:41 -04:00
|
|
|
raise TaskError.new "status: #{task.status}, error: #{task.error}" unless task.success?
|
2013-09-16 13:13:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_id_from_href!(data={})
|
|
|
|
data[:id] = data[:href].split('/').last
|
|
|
|
end
|
|
|
|
|
2013-10-15 11:35:06 -04:00
|
|
|
# Compensate for Fog::ToHashDocument shortcomings.
|
|
|
|
# @api private
|
|
|
|
# @param [Hash] hash
|
|
|
|
# @param [String,Symbol] key1
|
|
|
|
# @param [String,Symbol] key2
|
|
|
|
# @return [Hash]
|
|
|
|
def ensure_list!(hash, key1, key2=nil)
|
|
|
|
if key2.nil?
|
|
|
|
hash[key1] ||= []
|
|
|
|
hash[key1] = [hash[key1]] if hash[key1].is_a?(Hash)
|
|
|
|
else
|
|
|
|
hash[key1] ||= {key2 => []}
|
|
|
|
hash[key1] = {key2 => []} if hash[key1].empty?
|
|
|
|
hash[key1][key2] = [hash[key1][key2]] if hash[key1][key2].is_a?(Hash)
|
|
|
|
end
|
|
|
|
hash
|
|
|
|
end
|
|
|
|
|
2013-09-16 13:13:09 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def login
|
2014-02-06 14:01:03 -05:00
|
|
|
if @vcloud_token = ENV['FOG_VCLOUD_TOKEN']
|
|
|
|
response = get_current_session
|
|
|
|
else
|
|
|
|
response = post_login_session
|
2014-05-22 21:40:43 -04:00
|
|
|
x_vcloud_authorization = response.headers.keys.find do |key|
|
2014-02-06 14:01:03 -05:00
|
|
|
key.downcase == 'x-vcloud-authorization'
|
|
|
|
end
|
|
|
|
@vcloud_token = response.headers[x_vcloud_authorization]
|
2013-10-08 14:43:06 -04:00
|
|
|
end
|
2013-09-16 13:13:09 -04:00
|
|
|
@org_name = response.body[:org]
|
2013-10-13 01:30:38 -04:00
|
|
|
@user_name = response.body[:user]
|
2013-09-16 13:13:09 -04:00
|
|
|
end
|
2013-10-08 14:43:06 -04:00
|
|
|
|
|
|
|
# @note This isn't needed.
|
|
|
|
def logout
|
|
|
|
delete_logout
|
|
|
|
@vcloud_token = nil
|
|
|
|
@org_name = nil
|
|
|
|
end
|
2013-09-16 13:13:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Mock
|
2013-09-26 06:29:51 -04:00
|
|
|
attr_reader :end_point, :api_version
|
|
|
|
|
|
|
|
def data
|
|
|
|
@@data ||= Hash.new do |hash, key|
|
2013-10-08 05:14:50 -04:00
|
|
|
|
2013-12-12 10:42:57 -05:00
|
|
|
vdc1_uuid = uuid
|
|
|
|
vdc2_uuid = uuid
|
2013-10-08 05:14:50 -04:00
|
|
|
default_network_uuid = uuid
|
2013-12-12 10:42:57 -05:00
|
|
|
uplink_network_uuid = uuid
|
|
|
|
isolated_vdc1_network_uuid = uuid
|
|
|
|
isolated_vdc2_network_uuid = uuid
|
2014-03-17 16:51:05 -04:00
|
|
|
vapp1_id = "vapp-#{uuid}"
|
|
|
|
vapp2_id = "vapp-#{uuid}"
|
|
|
|
vapp1vm1_id = "vm-#{uuid}"
|
|
|
|
vapp2vm1_id = "vm-#{uuid}"
|
|
|
|
vapp2vm2_id = "vm-#{uuid}"
|
2014-06-16 08:37:37 -04:00
|
|
|
catalog_uuid = uuid
|
2013-10-08 05:14:50 -04:00
|
|
|
|
2013-09-26 06:29:51 -04:00
|
|
|
hash[key] = {
|
2013-09-29 16:27:58 -04:00
|
|
|
:catalogs => {
|
2014-06-16 08:37:37 -04:00
|
|
|
catalog_uuid => {
|
2013-09-29 16:27:58 -04:00
|
|
|
:name => 'Default Catalog'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
:catalog_items => {
|
|
|
|
uuid => {
|
2014-06-16 08:37:37 -04:00
|
|
|
:type => 'vAppTemplate',
|
|
|
|
:name => 'vAppTemplate 1',
|
|
|
|
:catalog => catalog_uuid,
|
2013-09-29 16:27:58 -04:00
|
|
|
}
|
|
|
|
},
|
2013-10-20 14:52:14 -04:00
|
|
|
:disks => {},
|
2013-10-13 11:18:59 -04:00
|
|
|
:edge_gateways => {
|
|
|
|
uuid => {
|
|
|
|
:name => 'MockEdgeGateway',
|
|
|
|
:networks => [uplink_network_uuid, default_network_uuid],
|
2013-12-12 10:42:57 -05:00
|
|
|
:vdc => vdc1_uuid,
|
2013-10-18 10:44:53 -04:00
|
|
|
:Configuration => {
|
|
|
|
:GatewayBackingConfig => "compact",
|
|
|
|
:GatewayInterfaces => {
|
|
|
|
:GatewayInterface => []},
|
|
|
|
:EdgeGatewayServiceConfiguration => {
|
|
|
|
:FirewallService => {
|
|
|
|
:IsEnabled => "true",
|
|
|
|
:DefaultAction => "drop",
|
|
|
|
:LogDefaultAction => "false",
|
|
|
|
:FirewallRule => []
|
|
|
|
},
|
|
|
|
:NatService => {:IsEnabled => "true"}},
|
|
|
|
:HaEnabled => "false",
|
|
|
|
:UseDefaultRouteForDnsRelay => "false"
|
|
|
|
}
|
2013-10-13 11:18:59 -04:00
|
|
|
}
|
|
|
|
},
|
2013-12-12 10:42:57 -05:00
|
|
|
|
2013-09-29 16:27:58 -04:00
|
|
|
:medias => {},
|
2013-12-12 10:42:57 -05:00
|
|
|
|
2013-09-29 16:27:58 -04:00
|
|
|
:networks => {
|
2013-12-12 10:42:57 -05:00
|
|
|
|
2013-10-08 05:14:50 -04:00
|
|
|
default_network_uuid => {
|
2013-12-12 10:42:57 -05:00
|
|
|
:IsShared => true,
|
|
|
|
:vdc => vdc1_uuid,
|
|
|
|
:FenceMode => 'natRouted',
|
2013-10-08 05:14:50 -04:00
|
|
|
:ApplyRateLimit => "false",
|
|
|
|
:Description => 'Org Network for mocking',
|
2013-09-29 16:27:58 -04:00
|
|
|
:Dns1 => '8.8.8.8',
|
|
|
|
:Dns2 => '8.8.4.4',
|
|
|
|
:DnsSuffix => 'example.com',
|
|
|
|
:Gateway => '192.168.1.1',
|
2013-10-08 05:14:50 -04:00
|
|
|
:InterfaceType => "internal",
|
2013-09-29 16:27:58 -04:00
|
|
|
:IpRanges => [{
|
|
|
|
:StartAddress=>'192.168.1.2',
|
|
|
|
:EndAddress=>'192.168.1.254'
|
|
|
|
}],
|
|
|
|
:IsInherited => false,
|
|
|
|
:Netmask => '255.255.255.0',
|
2014-07-11 07:01:43 -04:00
|
|
|
:name => 'vDC1 Default Network',
|
2013-10-08 05:14:50 -04:00
|
|
|
:SubnetParticipation => {
|
|
|
|
:Gateway => "192.168.1.0",
|
|
|
|
:Netmask => "255.255.0.0",
|
|
|
|
:IpAddress => "192.168.1.0"
|
|
|
|
},
|
|
|
|
:UseForDefaultRoute => "false"
|
|
|
|
},
|
2013-12-12 10:42:57 -05:00
|
|
|
|
|
|
|
isolated_vdc1_network_uuid => {
|
|
|
|
:IsShared => false,
|
|
|
|
:vdc => vdc1_uuid,
|
|
|
|
:ApplyRateLimit => "false",
|
|
|
|
:FenceMode => 'isolated',
|
|
|
|
:Description => 'Org Network for mocking',
|
|
|
|
:Dns1 => '8.8.8.8',
|
|
|
|
:Dns2 => '8.8.4.4',
|
|
|
|
:DnsSuffix => 'example.com',
|
|
|
|
:InterfaceType => "internal",
|
|
|
|
:IpRanges => [{
|
|
|
|
:StartAddress=>'10.1.0.100',
|
|
|
|
:EndAddress=>'10.1.0.200'
|
|
|
|
}],
|
|
|
|
:IsInherited => false,
|
|
|
|
:Netmask => '255.255.255.0',
|
|
|
|
:name => 'vDC1 backend network',
|
|
|
|
:SubnetParticipation => {
|
|
|
|
:Gateway => "192.168.1.0",
|
|
|
|
:Netmask => "255.255.0.0",
|
|
|
|
:IpAddress => "192.168.1.0"
|
|
|
|
},
|
|
|
|
:UseForDefaultRoute => "false"
|
|
|
|
},
|
|
|
|
|
|
|
|
isolated_vdc2_network_uuid => {
|
|
|
|
:IsShared => false,
|
|
|
|
:vdc => vdc2_uuid,
|
|
|
|
:ApplyRateLimit => "false",
|
|
|
|
:Description => 'Org Network for mocking',
|
|
|
|
:Dns1 => '8.8.8.8',
|
|
|
|
:Dns2 => '8.8.4.4',
|
|
|
|
:DnsSuffix => 'example.com',
|
|
|
|
:InterfaceType => "internal",
|
|
|
|
:IpRanges => [{
|
|
|
|
:StartAddress=>'10.2.0.100',
|
|
|
|
:EndAddress=>'10.2.0.200'
|
|
|
|
}],
|
|
|
|
:IsInherited => false,
|
|
|
|
:Netmask => '255.255.255.0',
|
|
|
|
:name => 'vDC2 backend network',
|
|
|
|
:SubnetParticipation => {
|
|
|
|
:Gateway => "192.168.1.0",
|
|
|
|
:Netmask => "255.255.0.0",
|
|
|
|
:IpAddress => "192.168.1.0"
|
|
|
|
},
|
|
|
|
:UseForDefaultRoute => "false"
|
|
|
|
},
|
|
|
|
|
2013-10-08 05:14:50 -04:00
|
|
|
uplink_network_uuid => {
|
2013-12-12 10:42:57 -05:00
|
|
|
:IsShared => false,
|
|
|
|
:vdc => vdc1_uuid,
|
2013-10-08 05:14:50 -04:00
|
|
|
:ApplyRateLimit => "false",
|
2013-12-12 10:42:57 -05:00
|
|
|
:FenceMode => 'bridged',
|
2013-10-08 05:14:50 -04:00
|
|
|
:Description => 'Uplink Network for mocking',
|
|
|
|
:Dns1 => '8.8.8.8',
|
|
|
|
:Dns2 => '8.8.4.4',
|
|
|
|
:DnsSuffix => 'example.com',
|
|
|
|
:Gateway => '198.51.100.1',
|
|
|
|
:InterfaceType => "uplink",
|
|
|
|
:IpRanges => [{
|
|
|
|
:StartAddress=>'198.51.100.2',
|
|
|
|
:EndAddress=>'198.51.100.254'
|
|
|
|
}],
|
|
|
|
:IsInherited => false,
|
|
|
|
:Netmask => '255.255.255.0',
|
|
|
|
:name => 'uplink Network',
|
|
|
|
:SubnetParticipation => {
|
|
|
|
:Gateway => "198.51.100.81",
|
|
|
|
:Netmask => "255.255.255.248",
|
|
|
|
:IpAddress => "198.51.100.83",
|
|
|
|
:IpRanges => {
|
|
|
|
:IpRange => {
|
|
|
|
:StartAddress => "198.51.100.84",
|
|
|
|
:EndAddress => "198.51.100.86"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
:UseForDefaultRoute => "true"
|
2013-09-29 16:27:58 -04:00
|
|
|
}
|
2013-12-12 10:42:57 -05:00
|
|
|
|
2013-09-26 06:29:51 -04:00
|
|
|
},
|
|
|
|
:org => {
|
|
|
|
:description => 'Organization for mocking',
|
|
|
|
:full_name => 'Mock Organization',
|
|
|
|
:name => org_name,
|
|
|
|
:uuid => uuid
|
|
|
|
},
|
2013-09-29 16:27:58 -04:00
|
|
|
:tasks => {},
|
2014-03-17 16:51:05 -04:00
|
|
|
|
|
|
|
:vapps => {
|
|
|
|
vapp1_id => {
|
|
|
|
:name => 'mock-vapp-1',
|
2014-06-08 02:34:35 -04:00
|
|
|
:vdc_id => vdc1_uuid,
|
2014-03-17 16:51:05 -04:00
|
|
|
:description => "Mock vApp 1",
|
|
|
|
:networks => [
|
|
|
|
{ :parent_id => default_network_uuid, },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
vapp2_id => {
|
|
|
|
:name => 'mock-vapp-2',
|
2014-06-08 02:34:35 -04:00
|
|
|
:vdc_id => vdc2_uuid,
|
2014-03-17 16:51:05 -04:00
|
|
|
:description => "Mock vApp 2",
|
|
|
|
:networks => [
|
|
|
|
{ :parent_id => default_network_uuid },
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2013-10-13 11:18:59 -04:00
|
|
|
:vdc_storage_classes => {
|
|
|
|
uuid => {
|
|
|
|
:default => true,
|
|
|
|
:enabled => true,
|
|
|
|
:limit => 2 * 1024 * 1024,
|
|
|
|
:name => 'DefaultMockStorageClass',
|
|
|
|
:units => 'MB',
|
2013-12-12 10:42:57 -05:00
|
|
|
:vdc => vdc1_uuid,
|
2013-10-13 11:18:59 -04:00
|
|
|
}
|
|
|
|
},
|
2014-03-17 16:51:05 -04:00
|
|
|
|
2013-09-29 16:27:58 -04:00
|
|
|
:vdcs => {
|
2013-12-12 10:42:57 -05:00
|
|
|
vdc1_uuid => {
|
|
|
|
:description => 'vDC1 for mocking',
|
|
|
|
:name => 'MockVDC 1'
|
|
|
|
},
|
|
|
|
vdc2_uuid => {
|
|
|
|
:description => 'vDC2 for mocking',
|
|
|
|
:name => 'MockVDC 2'
|
|
|
|
},
|
2014-03-17 16:51:05 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
:vms => {
|
|
|
|
vapp1vm1_id => {
|
|
|
|
:name => 'mock-vm-1-1',
|
|
|
|
:parent_vapp => vapp1_id,
|
|
|
|
:nics => [
|
|
|
|
{
|
|
|
|
:network_name => 'Default Network',
|
|
|
|
:mac_address => "00:50:56:aa:bb:01",
|
|
|
|
:ip_address => "192.168.1.33",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
vapp2vm1_id => {
|
|
|
|
:name => 'mock-vm-2-1',
|
|
|
|
:parent_vapp => vapp2_id,
|
|
|
|
:nics => [
|
|
|
|
{
|
|
|
|
:network_name => 'Default Network',
|
|
|
|
:mac_address => "00:50:56:aa:bb:02",
|
|
|
|
:ip_address => "192.168.1.34",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
vapp2vm2_id => {
|
|
|
|
:name => 'mock-vm-2-2',
|
|
|
|
:parent_vapp => vapp2_id,
|
|
|
|
:nics => [
|
|
|
|
{
|
|
|
|
:network_name => 'Default Network',
|
|
|
|
:mac_address => "00:50:56:aa:bb:03",
|
|
|
|
:ip_address => "192.168.1.35",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2013-09-26 06:29:51 -04:00
|
|
|
}
|
|
|
|
end[@vcloud_director_username]
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2014-02-26 19:50:35 -05:00
|
|
|
#@connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
|
2013-09-26 06:29:51 -04:00
|
|
|
@end_point = "#{@scheme}://#{@host}#{@path}/"
|
|
|
|
@api_version = options[:vcloud_director_api_version] || Fog::Compute::VcloudDirector::Defaults::API_VERSION
|
|
|
|
end
|
|
|
|
|
2013-10-08 14:43:06 -04:00
|
|
|
def vcloud_token
|
|
|
|
@vcloud_token || Fog::Mock.random_base64(32)
|
2013-09-26 06:29:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def org_name
|
|
|
|
@org_name ||=
|
|
|
|
begin
|
|
|
|
username = @vcloud_director_username.split('@')
|
2013-10-09 10:29:12 -04:00
|
|
|
if username.size >= 2 # may be 'email_address@org_name'
|
|
|
|
username.last
|
|
|
|
else
|
2013-09-26 06:29:51 -04:00
|
|
|
Fog::Logger.warning('vcloud_director_username should be in the form user@org_name')
|
2013-10-09 10:29:12 -04:00
|
|
|
'vcd_org_name'
|
2013-09-26 06:29:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-09-16 13:13:09 -04:00
|
|
|
|
2013-09-26 06:29:51 -04:00
|
|
|
def user_name
|
|
|
|
@user_name ||= @vcloud_director_username.split('@').first
|
|
|
|
end
|
|
|
|
|
2013-09-30 20:47:57 -04:00
|
|
|
def user_uuid
|
|
|
|
@user_uuid ||= uuid
|
|
|
|
end
|
|
|
|
|
2013-09-26 06:29:51 -04:00
|
|
|
def uuid
|
|
|
|
[8,4,4,4,12].map {|i| Fog::Mock.random_hex(i)}.join('-')
|
|
|
|
end
|
|
|
|
|
2013-10-20 14:52:14 -04:00
|
|
|
# Create a task.
|
|
|
|
#
|
|
|
|
# @param [String] operation A message describing the operation that is
|
|
|
|
# tracked by this task.
|
|
|
|
# @param [String] operation_name The short name of the operation that
|
|
|
|
# is tracked by this task.
|
|
|
|
# @param [Hash] owner Reference to the owner of the task. This is
|
|
|
|
# typically the object that the task is creating or updating.
|
|
|
|
# * :href<~String> - Contains the URI to the entity.
|
|
|
|
# * :type<~String> - Contains the MIME type of the entity.
|
|
|
|
# @return [String] Object identifier of the task.
|
|
|
|
def enqueue_task(operation, operation_name, owner, options={})
|
|
|
|
task_id = uuid
|
|
|
|
now = DateTime.now
|
|
|
|
|
|
|
|
data[:tasks][task_id] = {
|
|
|
|
:cancel_requested => false,
|
|
|
|
:details => '',
|
|
|
|
:expiry_time => now + 86400, # in 24 hours
|
|
|
|
:name => 'task',
|
|
|
|
:progress => 1,
|
|
|
|
:service_namespace => 'com.vmware.vcloud',
|
|
|
|
:start_time => now,
|
|
|
|
:status => 'running',
|
|
|
|
}.merge(options).merge(
|
|
|
|
:operation => operation,
|
|
|
|
:operation_name => operation_name,
|
|
|
|
:owner => owner
|
|
|
|
)
|
|
|
|
|
|
|
|
task_id
|
|
|
|
end
|
|
|
|
|
|
|
|
# @note As far as this method is concerned, the only possible task
|
|
|
|
# states are 'running' and 'success'.
|
|
|
|
#
|
|
|
|
# @param [Hash] response_body
|
|
|
|
# @return [Boolean]
|
|
|
|
def process_task(response_body)
|
|
|
|
task_id = response_body[:href].split('/').last
|
|
|
|
task = data[:tasks][task_id]
|
|
|
|
|
|
|
|
if task[:status] == 'running'
|
|
|
|
task[:end_time] = DateTime.now
|
|
|
|
task[:progress] = 100
|
|
|
|
task[:status] = 'success'
|
|
|
|
|
|
|
|
if task[:on_success]
|
|
|
|
task[:on_success].call
|
|
|
|
task.delete(:on_success)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return true if task[:status] == 'success'
|
|
|
|
raise TaskError.new "status: #{task[:status]}, error: #{task[:Error]}"
|
|
|
|
end
|
|
|
|
|
2013-09-26 06:29:51 -04:00
|
|
|
def add_id_from_href!(data={})
|
|
|
|
data[:id] = data[:href].split('/').last
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def make_href(path)
|
|
|
|
"#{@end_point}#{path}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def xmlns
|
|
|
|
'http://www.vmware.com/vcloud/v1.5'
|
|
|
|
end
|
|
|
|
|
|
|
|
def xmlns_xsi
|
|
|
|
'http://www.w3.org/2001/XMLSchema-instance'
|
|
|
|
end
|
|
|
|
|
|
|
|
def xsi_schema_location
|
|
|
|
"http://www.vmware.com/vcloud/v1.5 http://#{@host}#{@path}/v1.5/schema/master.xsd"
|
|
|
|
end
|
|
|
|
end
|
2013-09-16 13:13:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|