vcloud-core 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 0.14.0 (2014-11-10)
2
+
3
+ API changes:
4
+
5
+ - Automatic pagination of `Vcloud::QueryRunner` results can now be
6
+ overridden with `page` and `pageSize` options.
7
+
8
+ Documentation:
9
+
10
+ - Documented all the public methods in vcloud-core to comply with semver.org recommendations.
11
+
1
12
  ## 0.13.0 (2014-10-13)
2
13
 
3
14
  Features:
@@ -5,30 +5,59 @@ module Vcloud
5
5
  # if functionality does not exist in Core
6
6
  class ApiInterface
7
7
 
8
+ # Private interface to Fog service layer to allow direct access to Fog
9
+ # for functionality not exposed elsewhere in Vcloud::Core.
10
+ #
11
+ # @api private
8
12
  def fog_service_interface
9
13
  @fog_service_interface ||= Vcloud::Core::Fog::ServiceInterface.new
10
14
  end
11
15
 
16
+ # Private interface to Fog model layer to allow direct access to Fog for
17
+ # functionality not exposed elsewhere in Vcloud::Core.
18
+ #
19
+ # @api private
12
20
  def fog_model_interface
13
21
  @fog_model_interface ||= Vcloud::Core::Fog::ModelInterface.new
14
22
  end
15
23
 
24
+ # Get a vApp by name and vdc_name
25
+ #
26
+ # @param name [String] Name of the vApp
27
+ # @param vdc_name [String] Name of the vDC
28
+ # @return [String] Response body describing the vApp
16
29
  def get_vapp_by_name_and_vdc_name(name, vdc_name)
17
30
  fog_service_interface.get_vapp_by_name_and_vdc_name(name, vdc_name)
18
31
  end
19
32
 
33
+ # Get a vApp by id
34
+ #
35
+ # @param id [String] ID of the vApp to get
36
+ # @return [String] Response body describing the vApp
20
37
  def get_vapp(id)
21
38
  fog_service_interface.get_vapp(id)
22
39
  end
23
40
 
41
+ # Delete a vApp by id
42
+ #
43
+ # @param id [String] ID of the vApp to delete
44
+ # @return [Boolean] return true or throw error
24
45
  def delete_vapp(id)
25
46
  fog_service_interface.delete_vapp(id)
26
47
  end
27
48
 
49
+ # Delete a network by id
50
+ #
51
+ # @param id [String] ID of the network to delete
52
+ # @return [Boolean] return true or throw error
28
53
  def delete_network(id)
29
54
  fog_service_interface.delete_network(id)
30
55
  end
31
56
 
57
+ # Returns a Fog::Compute::VcloudDirector::Organization instance representing
58
+ # the current organization
59
+ #
60
+ # @return [Fog::Compute::VcloudDirector::Organization]
32
61
  def current_organization
33
62
  fog_model_interface.current_organization
34
63
  end
@@ -2,6 +2,10 @@ module Vcloud
2
2
  module Core
3
3
  module ComputeMetadata
4
4
 
5
+ # Returns the metadata for a compute resource
6
+ #
7
+ # @param id [String] The ID of the vApp or VM to retrieve metadata for
8
+ # @return [Hash] Metadata keys/values
5
9
  def get_metadata id
6
10
  vcloud_compute_metadata = Vcloud::Core::Fog::ServiceInterface.new.get_vapp_metadata(id)
7
11
  MetadataHelper.extract_metadata(vcloud_compute_metadata[:MetadataEntry])
@@ -4,6 +4,17 @@ module Vcloud
4
4
  module Core
5
5
  class ConfigLoader
6
6
 
7
+ # Loads the configuration from +config_file+, optionally rendering
8
+ # +config_file+ as a Mustache template using vars in +vars_file+ and
9
+ # optionally validating config against +schema+ supplied.
10
+ #
11
+ # @param config_file [String] Location of the YAML config file
12
+ # @param schema [String, nil] Location of the validation schema
13
+ # if nil, no validation takes place.
14
+ # @param vars_file [String, nil] Location of the vars_file (YAML),
15
+ # if nil, config_file is not rendered
16
+ # by Mustache
17
+ # @return [Hash]
7
18
  def load_config(config_file, schema = nil, vars_file = nil)
8
19
  if vars_file
9
20
  rendered_config = Mustache.render(
@@ -4,6 +4,12 @@ module Vcloud
4
4
 
5
5
  attr_reader :id
6
6
 
7
+ # Initialize a new EdgeGateway and check that the provided ID
8
+ # is in the correct format (lowercase string containing
9
+ # hexadecimal characters or hyphens)
10
+ #
11
+ # @param id [String] The ID of gateway
12
+ # @return [Vcloud::Core::EdgeGateway] an instance of an EdgeGateway
7
13
  def initialize(id)
8
14
  unless id =~ /^[-0-9a-f]+$/
9
15
  raise "EdgeGateway id : #{id} is not in correct format"
@@ -11,6 +17,10 @@ module Vcloud
11
17
  @id = id
12
18
  end
13
19
 
20
+ # Find a list of EdgeGateway IDs that match a name
21
+ #
22
+ # @param name [String] The name of the EdgeGateway
23
+ # @return [Array] An array of IDs found.
14
24
  def self.get_ids_by_name(name)
15
25
  q = Vcloud::Core::QueryRunner.new
16
26
  query_results = q.run('edgeGateway', :filter => "name==#{name}")
@@ -20,11 +30,20 @@ module Vcloud
20
30
  end
21
31
  end
22
32
 
33
+
34
+ # Update configuration for EdgeGateway
35
+ #
36
+ # @param config [Hash] A configuration for EdgeGateway
23
37
  def update_configuration(config)
24
38
  fsi = Vcloud::Core::Fog::ServiceInterface.new
25
39
  fsi.post_configure_edge_gateway_services(id, config)
26
40
  end
27
41
 
42
+
43
+ # Return the Vcloud::Core::EdgeGatewayInterface of EdgeGateway which matches an ID
44
+ #
45
+ # @param id [String] The id of the EdgeGatewayInterface
46
+ # @return [Vcloud::Core::EdgeGatewayInterface] the EdgeGatewayInterface instance
28
47
  def vcloud_gateway_interface_by_id gateway_interface_id
29
48
  gateway_interfaces = vcloud_attributes[:Configuration][:GatewayInterfaces][:GatewayInterface]
30
49
  unless gateway_interfaces.empty?
@@ -34,6 +53,11 @@ module Vcloud
34
53
  end
35
54
  end
36
55
 
56
+ # Return the EdgeGateway instance that is the first match for the
57
+ # supplied name.
58
+ #
59
+ # @param name [String] The name of the EdgeGateway
60
+ # @return [Vcloud::Core::EdgeGateway] the EdgeGateway instance
37
61
  def self.get_by_name(name)
38
62
  ids = self.get_ids_by_name(name)
39
63
  raise "edgeGateway #{name} not found" if ids.size == 0
@@ -41,19 +65,33 @@ module Vcloud
41
65
  return self.new(ids.first)
42
66
  end
43
67
 
68
+ # Get the vCloud attributes for EdgeGateway
69
+ #
70
+ # @return [String] Excon::Response#body from vCloud for EdgeGateway
44
71
  def vcloud_attributes
45
72
  fsi = Vcloud::Core::Fog::ServiceInterface.new
46
73
  fsi.get_edge_gateway(id)
47
74
  end
48
75
 
76
+ # Return the +href+ of EdgeGateway
77
+ #
78
+ # @return [String] href of EdgeGateway
49
79
  def href
50
80
  vcloud_attributes[:href]
51
81
  end
52
82
 
83
+ # Return the +name+ of EdgeGateway
84
+ #
85
+ # @return [String] name of EdgeGateway
53
86
  def name
54
87
  vcloud_attributes[:name]
55
88
  end
56
89
 
90
+ # For each GatewayInterfaces item in the configuration, create an
91
+ # EdgeGatewayInterface object to allow decisions based on the connected
92
+ # networks to be taken without inspecting the API details.
93
+ #
94
+ # @return [Array] An array of Vcloud::Core::EdgeGatewayInterface objects
57
95
  def interfaces
58
96
  gateway_config = vcloud_attributes[:Configuration]
59
97
  return [] unless gateway_config[:GatewayInterfaces]
@@ -4,6 +4,10 @@ module Vcloud
4
4
 
5
5
  attr_accessor :name, :network_href, :network_name
6
6
 
7
+ # Return a new instance of an EdgeGatewayInterface
8
+ #
9
+ # @param gateway_interface_hash [Hash] The configuration of EdgeGatewayInterface
10
+ # @return [Vcloud::Core::EdgeGatewayInterface]
7
11
  def initialize(gateway_interface_hash)
8
12
  if gateway_interface_hash.nil?
9
13
  raise "EdgeGatewayInterface: gateway_interface_hash cannot be nil"
@@ -17,6 +21,9 @@ module Vcloud
17
21
  @network_name = gateway_interface_hash[:Network][:name]
18
22
  end
19
23
 
24
+ # Get the ID of EdgeGatewayInterface from the @network_href
25
+ #
26
+ # @return [String] The ID of EdgeGatewayInterface
20
27
  def network_id
21
28
  network_href.split('/').last
22
29
  end
@@ -10,10 +10,18 @@ module Vcloud
10
10
  TOKEN_ENV_VAR_NAME = 'FOG_VCLOUD_TOKEN'
11
11
  FOG_CREDS_PASS_NAME = :vcloud_director_password
12
12
 
13
+ # Run any checks needed against the Fog credentials
14
+ # currently only used to disallow plaintext passwords
15
+ # in .fog files.
16
+ #
13
17
  def self.check_credentials
14
18
  check_plaintext_pass
15
19
  end
16
20
 
21
+ # Attempt to load the password from the fog credentials file
22
+ #
23
+ # @return [String, nil] The password if it could be loaded,
24
+ # else nil.
17
25
  def self.fog_credentials_pass
18
26
  begin
19
27
  pass = ::Fog.credentials[FOG_CREDS_PASS_NAME]
@@ -28,6 +36,10 @@ module Vcloud
28
36
 
29
37
  private
30
38
 
39
+ # Check whether a plaintext password is in the Fog config
40
+ # file
41
+ #
42
+ # @return [void]
31
43
  def self.check_plaintext_pass
32
44
  pass = fog_credentials_pass
33
45
  unless pass.nil? or pass.empty?
@@ -9,6 +9,10 @@ module Vcloud
9
9
 
10
10
  attr_reader :id
11
11
 
12
+ # Return an object referring to a particular IndependentDisk
13
+ #
14
+ # @param id [String] The ID of the independent disk
15
+ # @return [Vcloud::Core::IndependentDisk]
12
16
  def initialize(id)
13
17
  unless id =~ /^[-0-9a-f]+$/
14
18
  raise "IndependentDisk id : #{id} is not in correct format"
@@ -16,6 +20,11 @@ module Vcloud
16
20
  @id = id
17
21
  end
18
22
 
23
+ # Return the ID of an IndependentDisk referred to by name and vDC
24
+ #
25
+ # @param name [String] The name of the disk
26
+ # @param vdc [String] The name of the vDC
27
+ # @return [Vcloud::Core::IndependentDisk] An object representing the IndependentDisk
19
28
  def self.get_by_name_and_vdc_name(name, vdc_name)
20
29
  q = Vcloud::Core::QueryRunner.new
21
30
  query_results = q.run('disk', :filter => "name==#{name};vdcName==#{vdc_name}")
@@ -33,6 +42,15 @@ module Vcloud
33
42
  return self.new(query_results.first[:href].split('/').last)
34
43
  end
35
44
 
45
+ # Create a named, sized IndependentDisk in a particular named vDC
46
+ #
47
+ # @param vdc [String] The name of the vDC
48
+ # @param name [String] The name of the IndependentDisk
49
+ # @param size [String, Integer] The size as an integer of bytes, or an
50
+ # integer with units
51
+ # (see convert_size_to_bytes)
52
+ # @return [Vcloud::Core::IndependentDisk] An object representing
53
+ # the new disk
36
54
  def self.create(vdc, name, size)
37
55
  vdc_name = vdc.name
38
56
  begin
@@ -52,18 +70,31 @@ module Vcloud
52
70
  return self.new(body[:href].split('/').last)
53
71
  end
54
72
 
73
+ # Return all the vcloud attributes of IndependentDisk
74
+ #
75
+ # @return [Hash] a hash describing all the attributes of disk
55
76
  def vcloud_attributes
56
77
  Vcloud::Core::Fog::ServiceInterface.new.get_disk(id)
57
78
  end
58
79
 
80
+ # Return the name of IndependentDisk
81
+ #
82
+ # @return [String] the name of instance
59
83
  def name
60
84
  vcloud_attributes[:name]
61
85
  end
62
86
 
87
+ # Return the href of IndependentDisk
88
+ #
89
+ # @return [String] the href of instance
63
90
  def href
64
91
  vcloud_attributes[:href]
65
92
  end
66
93
 
94
+ # Return an array of Vcloud::Core::Vm objects which are attached to
95
+ # independent disk
96
+ #
97
+ # @return [Array] an array of Vcloud::Core::Vm
67
98
  def attached_vms
68
99
  body = Vcloud::Core::Fog::ServiceInterface.new.get_vms_disk_attached_to(id)
69
100
  vms = body.fetch(:VmReference)
@@ -74,6 +105,11 @@ module Vcloud
74
105
  end
75
106
  end
76
107
 
108
+ # Convert an integer and units suffix (e.g. 10mb) into an integer of bytes
109
+ # Allowed suffixes are: mb, gb, mib, gib
110
+ #
111
+ # @param size [String] the intended size of the disk (optionally with units)
112
+ # @return [Integer] the disk size in bytes
77
113
  def self.convert_size_to_bytes(size)
78
114
  if size.to_s =~ /^(\d+)mb$/i
79
115
  Integer($1) * (10**6)
@@ -4,12 +4,20 @@ require 'highline'
4
4
  module Vcloud
5
5
  module Core
6
6
  class LoginCli
7
+
8
+ # Create a new instance of the CLI, parsing the arguments supplied
9
+ #
10
+ # @param argv_array [Array] The Array of ARGV arguments
11
+ # @return [Vcloud::Core::LoginCLI]
7
12
  def initialize(argv_array)
8
13
  @usage_text = nil
9
14
 
10
15
  parse(argv_array)
11
16
  end
12
17
 
18
+ # Login to vCloud and print shell commands suitable for setting the vcloud_token
19
+ #
20
+ # @return [void]
13
21
  def run
14
22
  begin
15
23
  pass = read_pass
@@ -2,6 +2,13 @@ module Vcloud
2
2
  module Core
3
3
  module MetadataHelper
4
4
 
5
+ # Convert the fog metadata into a hash of standard Ruby types
6
+ # Fog and vCloud currently expose the types used in the API, which are
7
+ # unnecessary for most needs. This class maps those custom Fog types back
8
+ # to Ruby types if possible.
9
+ #
10
+ # @param vcloud_metadata_entries [Hash] vCloud data as returned from Fog
11
+ # @return [Hash] a hash of only the metadata using Ruby types
5
12
  def extract_metadata vcloud_metadata_entries
6
13
  metadata = {}
7
14
  vcloud_metadata_entries.each do |entry|
@@ -4,6 +4,10 @@ module Vcloud
4
4
 
5
5
  attr_reader :id
6
6
 
7
+ # Return an object referring to a particular OrgVdcNetwork
8
+ #
9
+ # @param id [String] The ID of the network
10
+ # @return [Vcloud::Core::OrgVdcNetwork]
7
11
  def initialize(id)
8
12
  unless id =~ /^[-0-9a-f]+$/
9
13
  raise "orgVdcNetwork id : #{id} is not in correct format"
@@ -11,6 +15,10 @@ module Vcloud
11
15
  @id = id
12
16
  end
13
17
 
18
+ # Configure OrgVdcNetwork
19
+ #
20
+ # @param config [Hash] the configuration to apply to network
21
+ # @return [Vcloud::Core::OrgVdcNetwork] an object referring to network
14
22
  def self.provision(config)
15
23
  raise "Must specify a name" unless config[:name]
16
24
  raise "Must specify a vdc_name" unless config[:vdc_name]
@@ -45,18 +53,30 @@ module Vcloud
45
53
 
46
54
  end
47
55
 
56
+ # Return all the vcloud attributes of OrgVdcNetwork
57
+ #
58
+ # @return [Hash] a hash describing all the attributes of OrgVdcNetwork
48
59
  def vcloud_attributes
49
60
  Vcloud::Core::Fog::ServiceInterface.new.get_network_complete(id)
50
61
  end
51
62
 
63
+ # Return the name of OrgVdcNetwork
64
+ #
65
+ # @return [String] the name of instance
52
66
  def name
53
67
  vcloud_attributes[:name]
54
68
  end
55
69
 
70
+ # Return the href of OrgVdcNetwork
71
+ #
72
+ # @return [String] the href of instance
56
73
  def href
57
74
  vcloud_attributes[:href]
58
75
  end
59
76
 
77
+ # Delete OrgVdcNetwork
78
+ #
79
+ # @return [void]
60
80
  def delete
61
81
  Vcloud::Core::Fog::ServiceInterface.new.delete_network(id)
62
82
  end
@@ -4,6 +4,12 @@ module Vcloud
4
4
  module Core
5
5
  class Query
6
6
 
7
+ # Initialize a new Vcloud::Core::Query object
8
+ #
9
+ # @param type [String] Restrict query results to this type (see QueryRunner#available_query_types)
10
+ # @param options [Hash] key :output_type defines the output type and defaults to tsv; csv and yaml are valid options
11
+ # @param query_runner [Method] default=Vcloud::Core::QueryRunner.new
12
+ # @return [Vcloud::Core::Query]
7
13
  def initialize(type=nil, options={}, query_runner = Vcloud::Core::QueryRunner.new)
8
14
  @type = type
9
15
  @options = options
@@ -11,6 +17,9 @@ module Vcloud
11
17
  @query_runner = query_runner
12
18
  end
13
19
 
20
+ # Run the query and print to standard out
21
+ #
22
+ # @return [void]
14
23
  def run()
15
24
  if @type.nil?
16
25
  output_available_query_types
@@ -3,6 +3,11 @@ require 'optparse'
3
3
  module Vcloud
4
4
  module Core
5
5
  class QueryCli
6
+
7
+ # Create a new instance of the CLI, parsing the arguments supplied
8
+ #
9
+ # @param argv_array [Array] The Array of ARGV arguments
10
+ # @return [Vcloud::Core::QueryCLI]
6
11
  def initialize(argv_array)
7
12
  @usage_text = nil
8
13
  @type = nil
@@ -11,6 +16,9 @@ module Vcloud
11
16
  parse(argv_array)
12
17
  end
13
18
 
19
+ # Run a query and print results to standard out
20
+ #
21
+ # @return [void]
14
22
  def run
15
23
  begin
16
24
  Vcloud::Core::Query.new(@type, @options).run
@@ -2,15 +2,38 @@ module Vcloud
2
2
  module Core
3
3
  class QueryRunner
4
4
 
5
+ # Create a new instance of the ServiceInterface as the @fsi global
5
6
  def initialize
6
7
  @fsi = Vcloud::Core::Fog::ServiceInterface.new
7
8
  end
8
9
 
10
+ # Run a query (optionally for a particular entity type)
11
+ #
12
+ # @param type [String] Name of type to query for - default: nil
13
+ # See integration test of this module for examples
14
+ # @param options [Hash] options for the query API
15
+ # see Fog::Compute::VcloudDirector::Real for more
16
+ # documentation of valid options.
17
+ # Default: {}
18
+ # @option options [String] :filter Filter the query e.g. "name==foo"
19
+ # @option options [String] :format Unsupported - do not use
20
+ # @option options [String] :page Override automatic pagination
21
+ # @option options [String] :pageSize Override automatic pagination
22
+ # @return [Array] List of results
9
23
  def run(type=nil, options={})
10
24
  raise ArgumentError, "Query API :format option is not supported" if options[:format]
11
- get_all_results(type, options)
25
+
26
+ if options.has_key?(:page) || options.has_key?(:pageSize)
27
+ get_results_page(options.fetch(:page, 1), type, options) || []
28
+ else
29
+ get_all_results(type, options)
30
+ end
12
31
  end
13
32
 
33
+ # List the available entity types which can be queried
34
+ # See integration test of this module for examples
35
+ #
36
+ # @return [Array] list of valid types
14
37
  def available_query_types
15
38
  query_body = @fsi.get_execute_query()
16
39
  get_entity_types_in_record_format(query_body)
@@ -5,6 +5,10 @@ module Vcloud
5
5
 
6
6
  attr_reader :id
7
7
 
8
+ # Initialize a Vcloud::Core::Vapp
9
+ #
10
+ # @param id [String] the vApp ID
11
+ # @return [Vcloud::Core::Vapp]
8
12
  def initialize(id)
9
13
  unless id =~ /^#{self.class.id_prefix}-[-0-9a-f]+$/
10
14
  raise "#{self.class.id_prefix} id : #{id} is not in correct format"
@@ -12,6 +16,10 @@ module Vcloud
12
16
  @id = id
13
17
  end
14
18
 
19
+ # Return the ID of a named vApp
20
+ #
21
+ # @param name [String] the name of the vApp to find
22
+ # @return [String] the vApp ID
15
23
  def self.get_by_name(name)
16
24
  q = Vcloud::Core::QueryRunner.new
17
25
  query_results = q.run('vApp', :filter => "name==#{name}")
@@ -26,6 +34,10 @@ module Vcloud
26
34
  end
27
35
  end
28
36
 
37
+ # Return the ID of the vApp which contains a particular VM
38
+ #
39
+ # @param vm_id [String] the ID of the VM to find the parent for
40
+ # @return [String] the vApp ID
29
41
  def self.get_by_child_vm_id(vm_id)
30
42
  raise ArgumentError, "Must supply a valid Vm id" unless vm_id =~ /^vm-[-0-9a-f]+$/
31
43
  vm_body = Vcloud::Core::Fog::ServiceInterface.new.get_vapp(vm_id)
@@ -38,6 +50,9 @@ module Vcloud
38
50
  return self.new(parent_vapp_link.fetch(:href).split('/').last)
39
51
  end
40
52
 
53
+ # Return the vCloud data associated with vApp
54
+ #
55
+ # @return [Hash] the complete vCloud data for vApp
41
56
  def vcloud_attributes
42
57
  Vcloud::Core::Fog::ServiceInterface.new.get_vapp(id)
43
58
  end
@@ -47,33 +62,60 @@ module Vcloud
47
62
  POWERED_OFF = 8
48
63
  end
49
64
 
65
+ # Return the name of vApp
66
+ #
67
+ # @return [String] the name of instance
50
68
  def name
51
69
  vcloud_attributes[:name]
52
70
  end
53
71
 
72
+ # Return the href of vApp
73
+ #
74
+ # @return [String] the href of instance
54
75
  def href
55
76
  vcloud_attributes[:href]
56
77
  end
57
78
 
79
+ # Return the ID of the vDC containing vApp
80
+ #
81
+ # @return [String] the ID of the vDC containing vApp
58
82
  def vdc_id
59
83
  link = vcloud_attributes[:Link].detect { |l| l[:rel] == Fog::RELATION::PARENT && l[:type] == Fog::ContentTypes::VDC }
60
84
  link ? link[:href].split('/').last : raise('a vapp without parent vdc found')
61
85
  end
62
86
 
87
+ # Return the VMs within vApp
88
+ #
89
+ # @return [Hash] the VMs contained in the vApp
63
90
  def vms
64
91
  vcloud_attributes[:Children][:Vm]
65
92
  end
66
93
 
94
+ # Return the networks connected to vApp
95
+ #
96
+ # @return [Hash] a hash describing the networks
67
97
  def networks
68
98
  vcloud_attributes[:'ovf:NetworkSection'][:'ovf:Network']
69
99
  end
70
100
 
101
+ # Find a vApp by name and vDC
102
+ #
103
+ # @param name [String] name of the vApp to find
104
+ # @param vdc_name [String] name of the vDC
105
+ # @return [String] the ID of the instance
71
106
  def self.get_by_name_and_vdc_name(name, vdc_name)
72
107
  fog_interface = Vcloud::Core::Fog::ServiceInterface.new
73
108
  attrs = fog_interface.get_vapp_by_name_and_vdc_name(name, vdc_name)
74
109
  self.new(attrs[:href].split('/').last) if attrs && attrs.key?(:href)
75
110
  end
76
111
 
112
+ # Instantiate a vApp
113
+ #
114
+ # @param name [String] Name to use when creating the vApp
115
+ # @param network_names [Array] Array of Strings with names of Networks to connect to the vApp
116
+ # @param template_id [String] The ID of the template to use when creating the vApp
117
+ # @param vdc_name [String] The name of the vDC to create vApp in
118
+ # @return [String] the id of the created vApp
77
119
  def self.instantiate(name, network_names, template_id, vdc_name)
78
120
  Vcloud::Core.logger.info("Instantiating new vApp #{name} in vDC '#{vdc_name}'")
79
121
  fog_interface = Vcloud::Core::Fog::ServiceInterface.new
@@ -88,6 +130,10 @@ module Vcloud
88
130
  self.new(attrs[:href].split('/').last) if attrs and attrs.key?(:href)
89
131
  end
90
132
 
133
+ # Update custom_fields for vApp
134
+ #
135
+ # @param custom_fields [Array] Array of Hashes describing the custom fields
136
+ # @return [Boolean] return true or throws error
91
137
  def update_custom_fields(custom_fields)
92
138
  return if custom_fields.nil?
93
139
  fields = custom_fields.collect do |field|
@@ -108,6 +154,9 @@ module Vcloud
108
154
  Vcloud::Core::Fog::ServiceInterface.new.put_product_sections(@id, fields)
109
155
  end
110
156
 
157
+ # Power on vApp
158
+ #
159
+ # @return [Boolean] Returns true if the VM is running, false otherwise
111
160
  def power_on
112
161
  raise "Cannot power on a missing vApp." unless id
113
162
  return true if running?
@@ -4,6 +4,9 @@ module Vcloud
4
4
 
5
5
  attr_reader :id
6
6
 
7
+ # Return the vCloud data associated with vApp
8
+ #
9
+ # @return [Hash] the complete vCloud data for vApp
7
10
  def initialize(id)
8
11
  unless id =~ /^#{self.class.id_prefix}-[-0-9a-f]+$/
9
12
  raise "#{self.class.id_prefix} id : #{id} is not in correct format"
@@ -11,18 +14,32 @@ module Vcloud
11
14
  @id = id
12
15
  end
13
16
 
17
+ # Return the vCloud data associated with vAppTemplate
18
+ #
19
+ # @return [Hash] the complete vCloud data for vAppTemplate
14
20
  def vcloud_attributes
15
21
  Vcloud::Core::Fog::ServiceInterface.new.get_vapp_template(id)
16
22
  end
17
23
 
24
+ # Return the name of vAppTemplate
25
+ #
26
+ # @return [String] the name of instance
18
27
  def href
19
28
  vcloud_attributes[:href]
20
29
  end
21
30
 
31
+ # Return the name of vAppTemplate
32
+ #
33
+ # @return [String] the name of instance
22
34
  def name
23
35
  vcloud_attributes[:name]
24
36
  end
25
37
 
38
+ # Get a list of templates with a particular name in a catalog
39
+ #
40
+ # @param name [String] The name of the vAppTemplate to find
41
+ # @param catalog_name [String] The name of the catalog to search
42
+ # @return [Array] an array of IDs of matching templates
26
43
  def self.get_ids_by_name_and_catalog name, catalog_name
27
44
  raise "provide Catalog and vAppTemplate name" unless name && catalog_name
28
45
  q = Vcloud::Core::QueryRunner.new
@@ -33,6 +50,11 @@ module Vcloud
33
50
  end
34
51
  end
35
52
 
53
+ # Get a template by name and catalog
54
+ #
55
+ # @param vapp_template_name [String] The name of the vAppTemplate
56
+ # @param catalog_name [String] The name of the catalog containing vAppTemplate
57
+ # @return [String] the ID of the template
36
58
  def self.get vapp_template_name, catalog_name
37
59
  ids = self.get_ids_by_name_and_catalog(vapp_template_name, catalog_name)
38
60
  raise 'Could not find template vApp' if ids.size == 0
@@ -42,6 +64,9 @@ module Vcloud
42
64
  return self.new(ids.first)
43
65
  end
44
66
 
67
+ # Return the id_prefix to be used for vAppTemplates
68
+ #
69
+ # @return [String] returns 'vappTemplate' as an id_prefix
45
70
  def self.id_prefix
46
71
  'vappTemplate'
47
72
  end
@@ -4,6 +4,10 @@ module Vcloud
4
4
 
5
5
  attr_reader :id
6
6
 
7
+ # Initialize a Vcloud::Core::Vdc
8
+ #
9
+ # @param id [String] the vDC ID
10
+ # @return [Vcloud::Core::Vdc]
7
11
  def initialize(id)
8
12
  unless id =~ /^[-0-9a-f]+$/
9
13
  raise "vdc id : #{id} is not in correct format"
@@ -11,6 +15,10 @@ module Vcloud
11
15
  @id = id
12
16
  end
13
17
 
18
+ # Get the ID of a named vDC
19
+ #
20
+ # @param name [String] The name of the vDC
21
+ # @return [String] The ID of the vDC
14
22
  def self.get_by_name(name)
15
23
  q = Vcloud::Core::QueryRunner.new
16
24
  query_results = q.run('orgVdc', :filter => "name==#{name}")
@@ -19,14 +27,23 @@ module Vcloud
19
27
  return self.new(query_results.first[:href].split('/').last)
20
28
  end
21
29
 
30
+ # Return the vCloud data associated with vDC
31
+ #
32
+ # @return [Hash] the complete vCloud data for vDC
22
33
  def vcloud_attributes
23
34
  Vcloud::Core::Fog::ServiceInterface.new.get_vdc(id)
24
35
  end
25
36
 
37
+ # Return the name of vDC
38
+ #
39
+ # @return [String] the name of instance
26
40
  def name
27
41
  vcloud_attributes[:name]
28
42
  end
29
43
 
44
+ # Return the href of vDC
45
+ #
46
+ # @return [String] the href of instance
30
47
  def href
31
48
  vcloud_attributes[:href]
32
49
  end
@@ -1,5 +1,5 @@
1
1
  module Vcloud
2
2
  module Core
3
- VERSION = '0.13.0'
3
+ VERSION = '0.14.0'
4
4
  end
5
5
  end
@@ -5,6 +5,11 @@ module Vcloud
5
5
 
6
6
  attr_reader :id
7
7
 
8
+ # Initialize a Vcloud::Core::Vm within a vApp
9
+ #
10
+ # @param id [String] the VM ID
11
+ # @param vapp [Vcloud::Core::Vapp] The vApp object to create VM in
12
+ # @return [Vcloud::Core::Vm]
8
13
  def initialize(id, vapp)
9
14
  unless id =~ /^#{self.class.id_prefix}-[-0-9a-f]+$/
10
15
  raise "#{self.class.id_prefix} id : #{id} is not in correct format"
@@ -13,10 +18,17 @@ module Vcloud
13
18
  @vapp = vapp
14
19
  end
15
20
 
21
+ # Return the vCloud data associated with VM
22
+ #
23
+ # @return [Hash] the complete vCloud data for VM
16
24
  def vcloud_attributes
17
25
  Vcloud::Core::Fog::ServiceInterface.new.get_vapp(id)
18
26
  end
19
27
 
28
+ # Set the amount of memory in VM which can't be nil or less than 64 (mb)
29
+ #
30
+ # @param new_memory [Integer] amount of memory for instance
31
+ # @return [Boolean] return true or throws an error
20
32
  def update_memory_size_in_mb(new_memory)
21
33
  return if new_memory.nil?
22
34
  return if new_memory.to_i < 64
@@ -25,33 +37,56 @@ module Vcloud
25
37
  end
26
38
  end
27
39
 
40
+ # Return the amount of memory allocated to VM
41
+ #
42
+ # @return [Integer] amount of memory in megabytes
28
43
  def memory
29
44
  memory_item = virtual_hardware_section.detect { |i| i[:'rasd:ResourceType'] == '4' }
30
45
  memory_item[:'rasd:VirtualQuantity']
31
46
  end
32
47
 
48
+ # Return the number of CPUs allocated to the VM
49
+ #
50
+ # @return [Integer] number of virtual CPUs
33
51
  def cpu
34
52
  cpu_item = virtual_hardware_section.detect { |i| i[:'rasd:ResourceType'] == '3' }
35
53
  cpu_item[:'rasd:VirtualQuantity']
36
54
  end
37
55
 
56
+ # Return the name of VM
57
+ #
58
+ # @return [String] the name of instance
38
59
  def name
39
60
  vcloud_attributes[:name]
40
61
  end
41
62
 
63
+ # Return the href of VM
64
+ #
65
+ # @return [String] the href of instance
42
66
  def href
43
67
  vcloud_attributes[:href]
44
68
  end
45
69
 
70
+ # Update the name of VM
71
+ #
72
+ # @param new_name [String] The new name for the VM
73
+ # @return [Boolean] return true or throw an error
46
74
  def update_name(new_name)
47
75
  fsi = Vcloud::Core::Fog::ServiceInterface.new
48
76
  fsi.put_vm(id, new_name) unless name == new_name
49
77
  end
50
78
 
79
+ # Return the name of the vApp containing VM
80
+ #
81
+ # @return [String] the name of the vApp
51
82
  def vapp_name
52
83
  @vapp.name
53
84
  end
54
85
 
86
+ # Update the number of CPUs in VM
87
+ #
88
+ # @param new_cpu_count [Integer] The number of virtual CPUs to allocate
89
+ # @return [Boolean] return true or throw an error
55
90
  def update_cpu_count(new_cpu_count)
56
91
  return if new_cpu_count.nil?
57
92
  return if new_cpu_count.to_i == 0
@@ -60,6 +95,10 @@ module Vcloud
60
95
  end
61
96
  end
62
97
 
98
+ # Update the metadata for VM
99
+ #
100
+ # @param metadata [Hash] hash of keys, values to set
101
+ # @return [Boolean] return true or throw an error
63
102
  def update_metadata(metadata)
64
103
  return if metadata.nil?
65
104
  fsi = Vcloud::Core::Fog::ServiceInterface.new
@@ -69,6 +108,10 @@ module Vcloud
69
108
  end
70
109
  end
71
110
 
111
+ # Attach independent disk(s) to VM
112
+ #
113
+ # @param disk_list [Array] an array of Vcloud::Core::IndependentDisk objects
114
+ # @return [Boolean] return true or throw an error
72
115
  def attach_independent_disks(disk_list)
73
116
  disk_list = Array(disk_list) # ensure we have an array
74
117
  disk_list.each do |disk|
@@ -76,6 +119,10 @@ module Vcloud
76
119
  end
77
120
  end
78
121
 
122
+ # Detach independent disk(s) from VM
123
+ #
124
+ # @param disk_list [Array] an array of Vcloud::Core::IndependentDisk objects
125
+ # @return [Boolean] return true or throw an error
79
126
  def detach_independent_disks(disk_list)
80
127
  disk_list = Array(disk_list) # ensure we have an array
81
128
  disk_list.each do |disk|
@@ -83,6 +130,10 @@ module Vcloud
83
130
  end
84
131
  end
85
132
 
133
+ # Add extra disks to VM
134
+ #
135
+ # @param extra_disks [Array] An array of hashes like [{ size: '20480' }]
136
+ # @return [Boolean] return true or throw an error
86
137
  def add_extra_disks(extra_disks)
87
138
  vm = Vcloud::Core::Fog::ModelInterface.new.get_vm_by_href(href)
88
139
  if extra_disks
@@ -93,6 +144,10 @@ module Vcloud
93
144
  end
94
145
  end
95
146
 
147
+ # Configure VM network interfaces
148
+ #
149
+ # @param networks_config [Array] An array of hashes like [{ :name => 'NetworkName' }]
150
+ # @return [Boolean] return true or throw an error
96
151
  def configure_network_interfaces(networks_config)
97
152
  return unless networks_config
98
153
  section = {PrimaryNetworkConnectionIndex: 0}
@@ -116,10 +171,18 @@ module Vcloud
116
171
  Vcloud::Core::Fog::ServiceInterface.new.put_network_connection_system_section_vapp(id, section)
117
172
  end
118
173
 
174
+ # Configure guest customisation script
175
+ #
176
+ # @param preamble [String] A script to run when the VM is created
177
+ # @return [Boolean] return true or throw an error
119
178
  def configure_guest_customization_section(preamble)
120
179
  Vcloud::Core::Fog::ServiceInterface.new.put_guest_customization_section(id, vapp_name, preamble)
121
180
  end
122
181
 
182
+ # Update the storage profile of a VM
183
+ #
184
+ # @param storage_profile [String] The name of the storage profile
185
+ # @return [Boolean] return true or throw an error
123
186
  def update_storage_profile storage_profile
124
187
  storage_profile_href = get_storage_profile_href_by_name(storage_profile, @vapp.name)
125
188
  Vcloud::Core::Fog::ServiceInterface.new.put_vm(id, name, {
@@ -185,6 +185,24 @@ module Vcloud
185
185
 
186
186
  end
187
187
 
188
+ context "automatic pagination can be suppressed with page/pageSize options" do
189
+ before(:all) do
190
+ @first_vapp_name = ''
191
+ end
192
+
193
+ it "returns the first singular result" do
194
+ results = Vcloud::Core::QueryRunner.new.run('vApp', sortAsc: 'name', pageSize: 1)
195
+ expect(results).to have(1).items
196
+ @first_vapp_name = results.first.fetch(:name)
197
+ end
198
+
199
+ it "returns the next singular result which is different from the first" do
200
+ results = Vcloud::Core::QueryRunner.new.run('vApp', sortAsc: 'name', pageSize: 1, page: 2)
201
+ expect(results).to have(1).items
202
+ expect(results.first.fetch(:name)).not_to eq(@first_vapp_name)
203
+ end
204
+ end
205
+
188
206
  after(:all) do
189
207
  IntegrationHelper.delete_vapps(@test_case_vapps)
190
208
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcloud-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-13 00:00:00.000000000 Z
12
+ date: 2014-11-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
16
- requirement: &4397480 !ruby/object:Gem::Requirement
16
+ requirement: &11276440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.24.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *4397480
24
+ version_requirements: *11276440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mustache
27
- requirement: &4395720 !ruby/object:Gem::Requirement
27
+ requirement: &11275840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *4395720
35
+ version_requirements: *11275840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: highline
38
- requirement: &4520880 !ruby/object:Gem::Requirement
38
+ requirement: &11275060 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *4520880
46
+ version_requirements: *11275060
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: gem_publisher
49
- requirement: &4516360 !ruby/object:Gem::Requirement
49
+ requirement: &11274300 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - =
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.2.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *4516360
57
+ version_requirements: *11274300
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: pry
60
- requirement: &4478040 !ruby/object:Gem::Requirement
60
+ requirement: &11273220 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *4478040
68
+ version_requirements: *11273220
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
- requirement: &4476980 !ruby/object:Gem::Requirement
71
+ requirement: &11272420 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *4476980
79
+ version_requirements: *11272420
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &4475000 !ruby/object:Gem::Requirement
82
+ requirement: &11270040 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 2.14.1
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *4475000
90
+ version_requirements: *11270040
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rubocop
93
- requirement: &4472300 !ruby/object:Gem::Requirement
93
+ requirement: &11286180 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 0.23.0
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *4472300
101
+ version_requirements: *11286180
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: simplecov
104
- requirement: &4470940 !ruby/object:Gem::Requirement
104
+ requirement: &11345780 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 0.7.1
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *4470940
112
+ version_requirements: *11345780
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: vcloud-tools-tester
115
- requirement: &4863720 !ruby/object:Gem::Requirement
115
+ requirement: &11344000 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,7 +120,7 @@ dependencies:
120
120
  version: 0.2.0
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *4863720
123
+ version_requirements: *11344000
124
124
  description: Core tools for interacting with VMware vCloud Director. Includes VCloud
125
125
  Query, a light wrapper round the vCloud Query API.
126
126
  email:
@@ -229,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
229
  version: '0'
230
230
  segments:
231
231
  - 0
232
- hash: -1721799035721332313
232
+ hash: -2644317041570452992
233
233
  requirements: []
234
234
  rubyforge_project:
235
235
  rubygems_version: 1.8.11