fog 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/fog.gemspec +13 -7
  2. data/lib/fog.rb +1 -1
  3. data/lib/fog/aws.rb +0 -4
  4. data/lib/fog/aws/parsers/ec2/get_console_output.rb +4 -2
  5. data/lib/fog/aws/requests/ec2/associate_address.rb +1 -1
  6. data/lib/fog/aws/requests/ec2/attach_volume.rb +2 -2
  7. data/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb +1 -1
  8. data/lib/fog/aws/requests/ec2/delete_security_group.rb +1 -1
  9. data/lib/fog/aws/requests/ec2/delete_snapshot.rb +1 -1
  10. data/lib/fog/aws/requests/ec2/delete_volume.rb +1 -1
  11. data/lib/fog/aws/requests/ec2/describe_addresses.rb +1 -1
  12. data/lib/fog/aws/requests/ec2/describe_instances.rb +2 -2
  13. data/lib/fog/aws/requests/ec2/describe_key_pairs.rb +1 -1
  14. data/lib/fog/aws/requests/ec2/describe_security_groups.rb +1 -1
  15. data/lib/fog/aws/requests/ec2/describe_snapshots.rb +1 -1
  16. data/lib/fog/aws/requests/ec2/describe_volumes.rb +1 -1
  17. data/lib/fog/aws/requests/ec2/detach_volume.rb +1 -1
  18. data/lib/fog/aws/requests/ec2/get_console_output.rb +2 -2
  19. data/lib/fog/aws/requests/ec2/reboot_instances.rb +1 -1
  20. data/lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb +1 -1
  21. data/lib/fog/aws/requests/ec2/run_instances.rb +2 -1
  22. data/lib/fog/aws/requests/ec2/terminate_instances.rb +1 -1
  23. data/lib/fog/collection.rb +7 -3
  24. data/lib/fog/terremark/shared.rb +4 -2
  25. data/lib/fog/vcloud.rb +25 -3
  26. data/lib/fog/vcloud/collection.rb +66 -0
  27. data/lib/fog/vcloud/model.rb +49 -0
  28. data/lib/fog/vcloud/models/vdc.rb +36 -0
  29. data/lib/fog/vcloud/models/vdcs.rb +36 -0
  30. data/lib/fog/vcloud/parser.rb +4 -1
  31. data/lib/fog/vcloud/parsers/get_vdc.rb +26 -1
  32. data/lib/fog/vcloud/parsers/login.rb +2 -6
  33. data/lib/fog/vcloud/requests/get_organization.rb +1 -1
  34. data/lib/fog/vcloud/requests/get_vdc.rb +32 -1
  35. data/lib/fog/vcloud/terremark/ecloud.rb +2 -1
  36. data/lib/fog/vcloud/terremark/ecloud/models/vdc.rb +20 -0
  37. data/lib/fog/vcloud/terremark/ecloud/models/vdcs.rb +29 -0
  38. data/lib/fog/vcloud/terremark/ecloud/parsers/get_vdc.rb +3 -3
  39. data/lib/fog/vcloud/terremark/ecloud/requests/get_vdc.rb +1 -1
  40. data/lib/fog/vcloud/terremark/vcloud/requests/get_vdc.rb +1 -1
  41. data/spec/aws/models/ec2/snapshots_spec.rb +1 -1
  42. data/spec/shared_examples/servers_examples.rb +1 -1
  43. data/spec/vcloud/models/vdc_spec.rb +46 -0
  44. data/spec/vcloud/models/vdcs_spec.rb +1 -0
  45. data/spec/vcloud/requests/get_organization_spec.rb +2 -2
  46. data/spec/vcloud/requests/get_vdc_spec.rb +6 -3
  47. data/spec/vcloud/spec_helper.rb +44 -8
  48. data/spec/vcloud/terremark/ecloud/models/vdc_spec.rb +43 -0
  49. data/spec/vcloud/terremark/ecloud/models/vdcs_spec.rb +25 -0
  50. data/spec/vcloud/terremark/ecloud/requests/get_vdc_spec.rb +8 -8
  51. data/spec/vcloud/terremark/vcloud/requests/get_vdc_spec.rb +4 -4
  52. data/tests/aws/helper.rb +0 -8
  53. data/tests/aws/requests/ec2/address_tests.rb +3 -3
  54. data/tests/aws/requests/ec2/availability_zone_tests.rb +2 -2
  55. data/tests/aws/requests/ec2/instance_tests.rb +122 -0
  56. data/tests/aws/requests/ec2/key_pair_tests.rb +1 -1
  57. data/tests/aws/requests/ec2/region_tests.rb +2 -2
  58. data/tests/aws/requests/ec2/security_group_tests.rb +6 -6
  59. data/tests/aws/requests/ec2/snapshot_tests.rb +2 -2
  60. data/tests/aws/requests/ec2/volume_tests.rb +5 -5
  61. data/tests/helper.rb +19 -6
  62. data/tests/rackspace/requests/servers/list_images_detail_tests.rb +1 -1
  63. metadata +14 -8
  64. data/spec/aws/requests/ec2/describe_instances_spec.rb +0 -104
  65. data/spec/aws/requests/ec2/get_console_output_spec.rb +0 -35
  66. data/spec/aws/requests/ec2/reboot_instances_spec.rb +0 -30
  67. data/spec/aws/requests/ec2/run_instances_spec.rb +0 -48
  68. data/spec/aws/requests/ec2/terminate_instances_spec.rb +0 -35
@@ -0,0 +1,49 @@
1
+ module Fog
2
+ module Vcloud
3
+ class Model < Fog::Model
4
+
5
+ #def self.attribute(name, other_names = [])
6
+ # super
7
+ # class_eval <<-EOS, __FILE__, __LINE__
8
+ # def #{name}=(new_#{name})
9
+ # @#{name} = new_#{name}
10
+ # end
11
+ # EOS
12
+ #end
13
+
14
+ def self.inherited(klass)
15
+ attributes.each { |attribute| klass.attribute attribute }
16
+ klass.instance_variable_set(:@identity, @identity)
17
+ klass.instance_variable_set(:@aliases, @aliases)
18
+ end
19
+
20
+ def self.delete_attribute(name)
21
+ if @attributes.reject! { |item| item == name }
22
+ class_eval <<-EOS,__FILE__,__LINE__
23
+ undef_method :#{name}
24
+ undef_method :#{name}=
25
+ EOS
26
+ aliases.reject! { |key, value| value == name || key == name }
27
+ end
28
+ end
29
+
30
+ def reload
31
+ if data = collection.get_raw(identity)
32
+ merge_get_raw_result(data)
33
+ self
34
+ end
35
+ end
36
+
37
+ def merge_get_raw_result(data)
38
+ data.body.each_pair do |key,value|
39
+ if aliased_key = self.class.aliases[key]
40
+ send("#{aliased_key}=", value)
41
+ else
42
+ send("#{key}=", value)
43
+ end
44
+ end
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,36 @@
1
+ require 'fog/model'
2
+
3
+ module Fog
4
+ module Vcloud
5
+ class Vdc < Fog::Vcloud::Model
6
+
7
+ identity :href
8
+
9
+ attribute :name
10
+ attribute :other_links, :links
11
+ attribute :resource_entity_links, :resource_entities
12
+ attribute :network_links, :networks
13
+ attribute :cpu_capacity
14
+ attribute :storage_capacity
15
+ attribute :memory_capacity
16
+ attribute :vm_quota
17
+ attribute :enabled
18
+ attribute :nic_quota
19
+ attribute :network_quota
20
+ attribute :vcloud_type, :type
21
+ attribute :xmlns
22
+ attribute :description
23
+ attribute :allocation_model
24
+
25
+ #def networks
26
+ # connection.networks(:vdc_uri => @uri)
27
+ #end
28
+
29
+ #def addresses
30
+ # connection.addresses(:vdc_uri => @uri)
31
+ #end
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ module Fog
2
+ module Vcloud
3
+ class Mock
4
+ def vdcs(options = {})
5
+ @vdcs ||= Fog::Vcloud::Vdcs.new(options.merge(:connection => self))
6
+ end
7
+ end
8
+
9
+ class Real
10
+ def vdcs(options = {})
11
+ @vdcs ||= Fog::Vcloud::Vdcs.new(options.merge(:connection => self))
12
+ end
13
+ end
14
+
15
+ class Vdcs < Fog::Vcloud::Collection
16
+
17
+ model Fog::Vcloud::Vdc
18
+
19
+ get_request :get_vdc
20
+ vcloud_type "application/vnd.vmware.vcloud.vdc+xml"
21
+ all_request lambda { |vdcs| vdcs.connection.get_organization(vdcs.organization_uri) }
22
+
23
+ def organization_uri
24
+ @organizatio_uri ||= connection.default_organization_uri
25
+ end
26
+
27
+ private
28
+
29
+ def organization_uri=(new_organization_uri)
30
+ @organization_uri = new_organization_uri
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -10,6 +10,9 @@ module Fog
10
10
  until attributes.empty?
11
11
  link[attributes.shift.downcase] = attributes.shift
12
12
  end
13
+ if link.href
14
+ link.href = URI.parse(link.href)
15
+ end
13
16
  link
14
17
  end
15
18
 
@@ -23,7 +26,7 @@ module Fog
23
26
  root[attributes.shift.downcase] = attributes.shift
24
27
  end
25
28
  end
26
- @response.href = root['href']
29
+ @response.href = URI.parse(root['href'])
27
30
  @response.name = root['name']
28
31
  @response.type = root['type']
29
32
  @response.xmlns = root['xmlns']
@@ -8,14 +8,31 @@ module Fog
8
8
  #vCloud API Guide v0.9 - Page 27
9
9
 
10
10
  def reset
11
- @response = Struct::VcloudVdc.new([])
11
+ @target = nil
12
+ @response = Struct::VcloudVdc.new([],[],[],Struct::VcloudXCapacity.new,Struct::VcloudXCapacity.new,Struct::VcloudXCapacity.new)
12
13
  end
13
14
 
14
15
  def start_element(name, attributes)
15
16
  @value = ''
16
17
  case name
18
+ when 'Cpu'
19
+ @target = :cpu_capacity
20
+ when 'Memory'
21
+ @target = :memory_capacity
22
+ when 'StorageCapacity'
23
+ @target = :storage_capacity
24
+ when 'NetworkQuota'
25
+ @target = :network_quota
26
+ when 'VmQuota'
27
+ @target = :vm_quota
28
+ when 'NicQuota'
29
+ @target = :nic_quota
17
30
  when 'Link'
18
31
  @response.links << generate_link(attributes)
32
+ when 'ResourceEntity'
33
+ @response.resource_entities << generate_link(attributes)
34
+ when 'Network'
35
+ @response.networks << generate_link(attributes)
19
36
  when 'Vdc'
20
37
  handle_root(attributes)
21
38
  end
@@ -23,10 +40,18 @@ module Fog
23
40
 
24
41
  def end_element(name)
25
42
  case name
43
+ when 'Allocated', 'Limit', 'Used'
44
+ @response[@target][name.downcase] = @value.to_i
45
+ when 'Units'
46
+ @response[@target][name.downcase] = @value
26
47
  when "AllocationModel"
27
48
  @response.allocation_model = @value
28
49
  when "Description"
29
50
  @response.description = @value
51
+ when "NicQuota", "VmQuota", "NetworkQuota"
52
+ @response[@target] = @value.to_i
53
+ when 'IsEnabled'
54
+ @response.enabled = (@value == 'true' ? true : false)
30
55
  end
31
56
  end
32
57
 
@@ -2,7 +2,7 @@ module Fog
2
2
  module Parsers
3
3
  module Vcloud
4
4
 
5
- class Login < Fog::Parsers::Base
5
+ class Login < Fog::Parsers::Vcloud::Base
6
6
  #
7
7
  # Based off of:
8
8
  # http://support.theenterprisecloud.com/kb/default.asp?id=536&Lang=1&SID=
@@ -26,11 +26,7 @@ module Fog
26
26
  end
27
27
  end
28
28
  when 'Org'
29
- organization = Struct::VcloudOrgLink.new
30
- until attributes.empty?
31
- organization[attributes.shift.downcase.to_sym] = attributes.shift
32
- end
33
- @response.organizations << organization
29
+ @response.organizations << generate_link(attributes)
34
30
  end
35
31
  end
36
32
 
@@ -23,7 +23,7 @@ module Fog
23
23
  #
24
24
  # vCloud API Guide v0.9 - Page 26
25
25
  #
26
- if org = DATA[:organizations].detect { |org| org[:info][:href] == organization_uri.to_s }
26
+ if org = mock_data[:organizations].detect { |org| URI.parse(org[:info][:href]) == organization_uri }
27
27
  xml = Builder::XmlMarkup.new
28
28
 
29
29
  mock_it Fog::Parsers::Vcloud::GetOrganization.new, 200,
@@ -20,7 +20,7 @@ module Fog
20
20
  #vCloud API Guide v0.9 - Page 27
21
21
 
22
22
  def get_vdc(vdc_uri)
23
- if vdc = DATA[:organizations].map { |org| org[:vdcs] }.flatten.detect { |vdc| vdc[:href] == vdc_uri }
23
+ if vdc = DATA[:organizations].map { |org| org[:vdcs] }.flatten.detect { |vdc| URI.parse(vdc[:href]) == vdc_uri }
24
24
  xml = Builder::XmlMarkup.new
25
25
  mock_it Fog::Parsers::Vcloud::GetVdc.new, 200,
26
26
  xml.Vdc(xmlns.merge(:href => vdc[:href], :name => vdc[:name])) {
@@ -47,6 +47,37 @@ module Fog
47
47
  :href => vdc[:href] + "/action/composeVApp")
48
48
  xml.AllocationModel("AllocationPool")
49
49
  xml.Description(vdc[:name] + " VDC")
50
+ xml.ResourceEntities {
51
+ DATA[:vdc_resources].each do |resource|
52
+ xml.ResourceEntity(resource)
53
+ end
54
+ }
55
+ xml.AvailableNetworks {
56
+ vdc[:networks].each do |network|
57
+ xml.Network( :name => network[:name], :href => network[:href], :type => "application/vnd.vmware.vcloud.network+xml" )
58
+ end
59
+ }
60
+ xml.ComputeCapacity{
61
+ xml.Cpu {
62
+ xml.Units("Mhz")
63
+ xml.Allocated(vdc[:cpu][:allocated])
64
+ xml.Limit(vdc[:cpu][:allocated])
65
+ }
66
+ xml.Memory {
67
+ xml.Units("MB")
68
+ xml.Allocated(vdc[:memory][:allocated])
69
+ xml.Limit(vdc[:memory][:allocated])
70
+ }
71
+ }
72
+ xml.StorageCapacity{
73
+ xml.Units("MB")
74
+ xml.Allocated(vdc[:storage][:allocated])
75
+ xml.Limit(vdc[:storage][:allocated])
76
+ }
77
+ xml.VmQuota(0)
78
+ xml.NicQuota(0)
79
+ xml.IsEnabled('true')
80
+ xml.NetworkQuota(0)
50
81
  #FIXME: Incomplete
51
82
  }, { 'Content-Type' => 'application/vnd.vmware.vcloud.vdc+xml' }
52
83
  else
@@ -11,13 +11,14 @@ module Fog
11
11
  #Do anything we need to do here that's specific to ecloud
12
12
  unless @required
13
13
  require 'fog/vcloud/terremark/all'
14
+ require 'fog/vcloud/terremark/ecloud/models/vdc'
15
+ require 'fog/vcloud/terremark/ecloud/models/vdcs'
14
16
  require 'fog/vcloud/terremark/ecloud/parsers/get_vdc'
15
17
  require 'fog/vcloud/terremark/ecloud/requests/login'
16
18
  require 'fog/vcloud/terremark/ecloud/requests/get_vdc'
17
19
  Struct.new("TmrkEcloudVdc", :links, :resource_entities, :networks,
18
20
  :cpu_capacity, :storage_capacity, :memory_capacity, :deployed_vm_quota, :instantiated_vm_quota,
19
21
  :href, :type, :name, :xmlns, :description)
20
- Struct.new("TmrkEcloudXCapacity", :units, :allocated, :used, :limit)
21
22
  @required = true
22
23
  end
23
24
  if Fog.mocking?
@@ -0,0 +1,20 @@
1
+ module Fog
2
+ module Vcloud
3
+ module Terremark
4
+ module Ecloud
5
+ class Vdc < Fog::Vcloud::Vdc
6
+
7
+ delete_attribute :enabled
8
+ delete_attribute :vm_quota
9
+ delete_attribute :nic_quota
10
+ delete_attribute :network_quota
11
+ delete_attribute :allocation_model
12
+
13
+ attribute :deployed_vm_quota
14
+ attribute :instantiated_vm_quota
15
+
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ module Fog
2
+ module Vcloud
3
+ module Terremark
4
+ module Ecloud
5
+ module Mock
6
+ def vdcs(options = {})
7
+ @vdcs ||= Fog::Vcloud::Terremark::Ecloud::Vdcs.new(options.merge(:connection => self))
8
+ end
9
+ end
10
+
11
+ module Real
12
+ def vdcs(options = {})
13
+ @vdcs ||= Fog::Vcloud::Terremark::Ecloud::Vdcs.new(options.merge(:connection => self))
14
+ end
15
+ end
16
+
17
+ class Vdcs < Fog::Vcloud::Vdcs
18
+
19
+ model Fog::Vcloud::Terremark::Ecloud::Vdc
20
+
21
+ #get_request :get_vdc
22
+ #vcloud_type "application/vnd.vmware.vcloud.vdc+xml"
23
+ #all_request lambda { |vdcs| vdcs.connection.get_organization(vdcs.organization_uri) }
24
+
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -8,9 +8,9 @@ module Fog
8
8
 
9
9
  def reset
10
10
  @target = nil
11
- @response = Struct::TmrkEcloudVdc.new([],[],[],Struct::TmrkEcloudXCapacity.new,Struct::TmrkEcloudXCapacity.new,
12
- Struct::TmrkEcloudXCapacity.new,Struct::TmrkEcloudXCapacity.new,
13
- Struct::TmrkEcloudXCapacity.new)
11
+ @response = Struct::TmrkEcloudVdc.new([],[],[],Struct::VcloudXCapacity.new,Struct::VcloudXCapacity.new,
12
+ Struct::VcloudXCapacity.new,Struct::VcloudXCapacity.new,
13
+ Struct::VcloudXCapacity.new)
14
14
  end
15
15
 
16
16
  def start_element(name, attributes)
@@ -22,7 +22,7 @@ module Fog
22
22
  #http://support.theenterprisecloud.com/kb/default.asp?id=545&Lang=1&SID=
23
23
 
24
24
  def get_vdc(vdc_uri)
25
- if vdc = mock_data[:organizations].map { |org| org[:vdcs] }.flatten.detect { |vdc| vdc[:href] == vdc_uri }
25
+ if vdc = mock_data[:organizations].map { |org| org[:vdcs] }.flatten.detect { |vdc| URI.parse(vdc[:href]) == vdc_uri }
26
26
  xml = Builder::XmlMarkup.new
27
27
  mock_it Fog::Parsers::Vcloud::Terremark::Ecloud::GetVdc.new, 200,
28
28
  xml.Vdc(xmlns.merge(:href => vdc[:href], :name => vdc[:name])) {
@@ -22,7 +22,7 @@ module Fog
22
22
  #https://community.vcloudexpress.terremark.com/en-us/product_docs/w/wiki/09-get-vdc.aspx
23
23
 
24
24
  def get_vdc(vdc_uri)
25
- if vdc = mock_data[:organizations].map { |org| org[:vdcs] }.flatten.detect { |vdc| vdc[:href] == vdc_uri }
25
+ if vdc = mock_data[:organizations].map { |org| org[:vdcs] }.flatten.detect { |vdc| URI.parse(vdc[:href]) == vdc_uri }
26
26
  xml = Builder::XmlMarkup.new
27
27
  mock_it Fog::Parsers::Vcloud::Terremark::Vcloud::GetVdc.new, 200,
28
28
  xml.Vdc(xmlns.merge(:href => vdc[:href], :name => vdc[:name])) {
@@ -61,7 +61,7 @@ describe 'Fog::AWS::EC2::Snapshots' do
61
61
  end
62
62
 
63
63
  it "should return nil if no matching address exists" do
64
- AWS[:ec2].snapshots.get('vol-00000000').should be_nil
64
+ AWS[:ec2].snapshots.get('snap-00000000').should be_nil
65
65
  end
66
66
 
67
67
  end
@@ -18,7 +18,7 @@ shared_examples_for "Servers" do
18
18
  end
19
19
 
20
20
  it "should return nil if no matching server exists" do
21
- @servers.get('0').should be_nil
21
+ @servers.get('i-00000000').should be_nil
22
22
  end
23
23
 
24
24
  end
@@ -0,0 +1,46 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Fog::Vcloud::Vdc", :type => :vcloud_model do
4
+
5
+ describe :class do
6
+ subject { Fog::Vcloud::Vdc }
7
+
8
+ it { should have_identity :href }
9
+
10
+ it { should have_only_these_attributes [:allocation_model, :cpu_capacity, :description, :enabled, :href, :memory_capacity, :name, :network_links, :network_quota,
11
+ :nic_quota, :other_links, :resource_entity_links, :storage_capacity, :vcloud_type, :vm_quota, :xmlns] }
12
+ end
13
+
14
+ context "with no uri" do
15
+
16
+ subject { Fog::Vcloud::Vdc.new() }
17
+
18
+ its(:href) { should be_nil }
19
+ its(:identity) { should be_nil }
20
+ end
21
+
22
+ context "as a collection member" do
23
+ subject { @vcloud.vdcs[0] }
24
+
25
+ its(:href) { should == URI.parse(@mock_vdc[:href]) }
26
+ its(:identity) { should == URI.parse(@mock_vdc[:href]) }
27
+ its(:name) { should == @mock_vdc[:name] }
28
+ its(:other_links) { should have(7).items }
29
+ its(:resource_entity_links) { should have(3).items }
30
+ its(:network_links) { should have(2).items }
31
+
32
+ its(:cpu_capacity) { should == Struct::VcloudXCapacity.new('Mhz',@mock_vdc[:cpu][:allocated], nil, @mock_vdc[:cpu][:allocated]) }
33
+ its(:memory_capacity) { should == Struct::VcloudXCapacity.new('MB',@mock_vdc[:memory][:allocated], nil, @mock_vdc[:memory][:allocated]) }
34
+ its(:storage_capacity) { should == Struct::VcloudXCapacity.new('MB',@mock_vdc[:storage][:allocated], nil, @mock_vdc[:storage][:allocated]) }
35
+
36
+ its(:vm_quota) { should == 0 }
37
+ its(:nic_quota) { should == 0 }
38
+ its(:network_quota) { should == 0 }
39
+
40
+ its(:enabled) { should == true }
41
+
42
+ end
43
+
44
+
45
+
46
+ end
@@ -0,0 +1 @@
1
+ require 'spec_helper'