Class: VagrantPlugins::VCloudAir::Driver::Meta
- Extended by:
- Forwardable
- Defined in:
- lib/vagrant-vcloudair/driver/meta.rb
Instance Attribute Summary collapse
-
#driver ⇒ Object
readonly
Returns the value of attribute driver.
Instance Method Summary collapse
-
#initialize(cloud_id, username, password, vdc_name) ⇒ Meta
constructor
A new instance of Meta.
Methods inherited from Base
#compose_vapp_from_vm, #create_vapp_from_template, #delete_vapp, #get_catalog, #get_catalog_by_name, #get_catalog_id_by_name, #get_catalog_item, #get_catalog_item_by_name, #get_organization, #get_organization_by_name, #get_organization_id_by_name, #get_organizations, #get_task, #get_vapp, #get_vapp_edge_public_ip, #get_vapp_port_forwarding_rules, #get_vapp_template, #get_vdc, #get_vdc_by_name, #get_vdc_id_by_name, #get_vm, #login, #logout, #poweron_vapp, #reboot_vapp, #reset_vapp, #set_vapp_network_config, #set_vapp_port_forwarding_rules, #set_vm_guest_customization, #set_vm_hardware, #set_vm_network_config, #suspend_vapp, #upload_ovf, #wait_task_completion
Constructor Details
#initialize(cloud_id, username, password, vdc_name) ⇒ Meta
Returns a new instance of Meta.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/vagrant-vcloudair/driver/meta.rb', line 33 def initialize(cloud_id, username, password, vdc_name) # Setup the base super() @username = username @password = password @logger = Log4r::Logger.new('vagrant::provider::vcloudair::meta') # Logging into vCloud Air params = { 'method' => :post, 'command' => '/vchs/sessions' } _response, headers = send_vcloudair_request(params) unless headers.key?('x-vchs-authorization') fail Errors::InvalidRequestError, :message => 'Failed to authenticate: ' \ 'missing x-vchs-authorization header' end @vcloudair_auth_key = headers['x-vchs-authorization'] # Get Services available params = { 'method' => :get, 'command' => '/vchs/services' } response, _headers = send_vcloudair_request(params) services = response.css('Services Service') service_id = cloud_id || vdc_name services.each do |service| if service['serviceId'] == service_id @compute_id = URI(service['href']).path.gsub('/api', '') end end fail Errors::ServiceNotFound if @compute_id.nil? # Get Service Link to vCloud Director params = { 'method' => :get, 'command' => @compute_id } response, _headers = send_vcloudair_request(params) vdcs = response.css('Compute VdcRef') vdcs.each do |vdc| if vdc['name'] == vdc_name @vdc_id = URI(vdc['href']).path.gsub('/api', '') end end fail Errors::VdcNotFound, :message => vdc_name if @vdc_id.nil? # Authenticate to vCloud Director params = { 'method' => :post, 'command' => "#{@vdc_id}/vcloudsession" } response, _headers = send_vcloudair_request(params) vdclinks = response.css('VCloudSession VdcLink') vdclinks.each do |vdclink| if vdclink['name'] == service_id uri = URI(vdclink['href']) @api_url = "#{uri.scheme}://#{uri.host}:#{uri.port}/api" @host_url = "#{uri.scheme}://#{uri.host}:#{uri.port}" @auth_key = vdclink['authorizationToken'] end end fail Errors::ObjectNotFound, :message => 'Cannot find link to backend \ vCloud Director Instance' if @api_url.nil? @org_name = vdc_name # Read and assign the version of vCloud Air we know which # specific driver to instantiate. @logger.debug("Asking API Version with host_url: #{@host_url}") @version = get_api_version(@host_url) || '' # Instantiate the proper version driver for vCloud Air @logger.debug("Finding driver for vCloud Air version: #{@version}") driver_map = { '5.1' => Version_5_1, '5.5' => Version_5_1, '5.6' => Version_5_1, '5.7' => Version_5_1, '11.0' => Version_5_1 } if @version.start_with?('0.9') || @version.start_with?('1.0') || @version.start_with?('1.5') # We only support vCloud Air 5.1 or higher. fail Errors::VCloudAirOldVersion, :version => @version end driver_klass = nil driver_map.each do |key, klass| if @version.start_with?(key) driver_klass = klass break end end unless driver_klass supported_versions = driver_map.keys.sort.join(', ') fail Errors::VCloudAirInvalidVersion, :supported_versions => supported_versions end @logger.info("Using vCloud Air driver: #{driver_klass}") @driver = driver_klass.new(@api_url, @host_url, @auth_key, @org_name) end |
Instance Attribute Details
#driver ⇒ Object (readonly)
Returns the value of attribute driver.
31 32 33 |
# File 'lib/vagrant-vcloudair/driver/meta.rb', line 31 def driver @driver end |