fog 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. data/Gemfile +8 -8
  2. data/Gemfile.lock +3 -3
  3. data/bin/fog +2 -10
  4. data/fog.gemspec +45 -20
  5. data/lib/fog.rb +2 -1
  6. data/lib/fog/attributes.rb +48 -8
  7. data/lib/fog/aws/ec2.rb +5 -2
  8. data/lib/fog/aws/elb.rb +5 -2
  9. data/lib/fog/aws/models/ec2/server.rb +1 -1
  10. data/lib/fog/aws/requests/simpledb/put_attributes.rb +43 -12
  11. data/lib/fog/aws/s3.rb +2 -2
  12. data/lib/fog/aws/simpledb.rb +15 -3
  13. data/lib/fog/bin.rb +11 -2
  14. data/lib/fog/bluebox.rb +5 -1
  15. data/lib/fog/connection.rb +9 -1
  16. data/lib/fog/credentials.rb +3 -0
  17. data/lib/fog/new_servers.rb +89 -0
  18. data/lib/fog/new_servers/bin.rb +30 -0
  19. data/lib/fog/new_servers/requests/add_server.rb +39 -0
  20. data/lib/fog/new_servers/requests/cancel_server.rb +36 -0
  21. data/lib/fog/new_servers/requests/get_server.rb +42 -0
  22. data/lib/fog/new_servers/requests/list_images.rb +33 -0
  23. data/lib/fog/new_servers/requests/list_plans.rb +36 -0
  24. data/lib/fog/new_servers/requests/list_servers.rb +43 -0
  25. data/lib/fog/new_servers/requests/reboot_server.rb +30 -0
  26. data/lib/fog/parser.rb +6 -0
  27. data/lib/fog/rackspace/files.rb +8 -2
  28. data/lib/fog/rackspace/models/servers/server.rb +5 -0
  29. data/lib/fog/rackspace/servers.rb +5 -1
  30. data/lib/fog/service.rb +6 -1
  31. data/lib/fog/slicehost.rb +5 -1
  32. data/lib/fog/terremark/ecloud.rb +1 -0
  33. data/lib/fog/terremark/shared.rb +4 -1
  34. data/lib/fog/terremark/vcloud.rb +1 -0
  35. data/lib/fog/vcloud.rb +150 -141
  36. data/lib/fog/vcloud/bin.rb +2 -2
  37. data/lib/fog/vcloud/collection.rb +3 -84
  38. data/lib/fog/vcloud/extension.rb +44 -0
  39. data/lib/fog/vcloud/generators.rb +33 -0
  40. data/lib/fog/vcloud/model.rb +5 -38
  41. data/lib/fog/vcloud/models/vdc.rb +14 -24
  42. data/lib/fog/vcloud/models/vdcs.rb +13 -8
  43. data/lib/fog/vcloud/requests/get_network.rb +4 -11
  44. data/lib/fog/vcloud/requests/get_organization.rb +4 -11
  45. data/lib/fog/vcloud/requests/get_vdc.rb +4 -12
  46. data/lib/fog/vcloud/requests/get_versions.rb +4 -13
  47. data/lib/fog/vcloud/requests/login.rb +4 -4
  48. data/lib/fog/vcloud/terremark/ecloud.rb +125 -54
  49. data/lib/fog/vcloud/terremark/ecloud/models/catalog.rb +30 -0
  50. data/lib/fog/vcloud/terremark/ecloud/models/catalog_item.rb +31 -0
  51. data/lib/fog/vcloud/terremark/ecloud/models/internet_service.rb +21 -22
  52. data/lib/fog/vcloud/terremark/ecloud/models/internet_services.rb +11 -25
  53. data/lib/fog/vcloud/terremark/ecloud/models/ip.rb +38 -5
  54. data/lib/fog/vcloud/terremark/ecloud/models/ips.rb +11 -15
  55. data/lib/fog/vcloud/terremark/ecloud/models/network.rb +52 -11
  56. data/lib/fog/vcloud/terremark/ecloud/models/networks.rb +14 -13
  57. data/lib/fog/vcloud/terremark/ecloud/models/node.rb +47 -0
  58. data/lib/fog/vcloud/terremark/ecloud/models/nodes.rb +30 -0
  59. data/lib/fog/vcloud/terremark/ecloud/models/public_ip.rb +6 -9
  60. data/lib/fog/vcloud/terremark/ecloud/models/public_ips.rb +19 -3
  61. data/lib/fog/vcloud/terremark/ecloud/models/server.rb +203 -0
  62. data/lib/fog/vcloud/terremark/ecloud/models/servers.rb +43 -0
  63. data/lib/fog/vcloud/terremark/ecloud/models/task.rb +22 -0
  64. data/lib/fog/vcloud/terremark/ecloud/models/tasks.rb +30 -0
  65. data/lib/fog/vcloud/terremark/ecloud/models/vdc.rb +32 -10
  66. data/lib/fog/vcloud/terremark/ecloud/models/vdcs.rb +5 -6
  67. data/lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb +23 -10
  68. data/lib/fog/vcloud/terremark/ecloud/requests/add_node.rb +54 -0
  69. data/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb +14 -12
  70. data/lib/fog/vcloud/terremark/ecloud/requests/configure_network.rb +53 -0
  71. data/lib/fog/vcloud/terremark/ecloud/requests/configure_network_ip.rb +52 -0
  72. data/lib/fog/vcloud/terremark/ecloud/requests/configure_node.rb +42 -0
  73. data/lib/fog/vcloud/terremark/ecloud/requests/configure_vapp.rb +115 -0
  74. data/lib/fog/vcloud/terremark/ecloud/requests/delete_internet_service.rb +4 -23
  75. data/lib/fog/vcloud/terremark/ecloud/requests/delete_node.rb +0 -0
  76. data/lib/fog/vcloud/terremark/ecloud/requests/delete_vapp.rb +19 -0
  77. data/lib/fog/vcloud/terremark/ecloud/requests/get_catalog.rb +18 -0
  78. data/lib/fog/vcloud/terremark/ecloud/requests/get_catalog_item.rb +18 -0
  79. data/lib/fog/vcloud/terremark/ecloud/requests/get_customization_options.rb +18 -0
  80. data/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb +9 -16
  81. data/lib/fog/vcloud/terremark/ecloud/requests/get_network.rb +8 -14
  82. data/lib/fog/vcloud/terremark/ecloud/requests/get_network_extensions.rb +36 -0
  83. data/lib/fog/vcloud/terremark/ecloud/requests/get_network_ip.rb +44 -0
  84. data/lib/fog/vcloud/terremark/ecloud/requests/get_network_ips.rb +11 -12
  85. data/lib/fog/vcloud/terremark/ecloud/requests/get_node.rb +18 -0
  86. data/lib/fog/vcloud/terremark/ecloud/requests/get_nodes.rb +18 -0
  87. data/lib/fog/vcloud/terremark/ecloud/requests/get_public_ip.rb +5 -19
  88. data/lib/fog/vcloud/terremark/ecloud/requests/get_public_ips.rb +5 -12
  89. data/lib/fog/vcloud/terremark/ecloud/requests/get_task.rb +18 -0
  90. data/lib/fog/vcloud/terremark/ecloud/requests/get_task_list.rb +19 -0
  91. data/lib/fog/vcloud/terremark/ecloud/requests/get_vapp.rb +18 -0
  92. data/lib/fog/vcloud/terremark/ecloud/requests/get_vdc.rb +7 -15
  93. data/lib/fog/vcloud/terremark/ecloud/requests/power_off.rb +18 -0
  94. data/lib/fog/vcloud/terremark/ecloud/requests/power_on.rb +18 -0
  95. data/lib/fog/vcloud/terremark/ecloud/requests/power_reset.rb +18 -0
  96. data/lib/fog/vcloud/terremark/ecloud/requests/power_shutdown.rb +18 -0
  97. data/lib/fog/vcloud/terremark/vcloud.rb +4 -18
  98. data/lib/fog/vcloud/terremark/vcloud/requests/get_vdc.rb +4 -12
  99. data/spec/aws/requests/simpledb/put_attributes_spec.rb +18 -0
  100. data/spec/vcloud/bin_spec.rb +2 -2
  101. data/spec/vcloud/models/vdc_spec.rb +35 -29
  102. data/spec/vcloud/requests/get_network_spec.rb +32 -43
  103. data/spec/vcloud/requests/get_organization_spec.rb +45 -38
  104. data/spec/vcloud/requests/get_vdc_spec.rb +42 -32
  105. data/spec/vcloud/requests/get_versions_spec.rb +17 -17
  106. data/spec/vcloud/requests/login_spec.rb +7 -4
  107. data/spec/vcloud/spec_helper.rb +137 -46
  108. data/spec/vcloud/terremark/ecloud/models/internet_service_spec.rb +53 -58
  109. data/spec/vcloud/terremark/ecloud/models/internet_services_spec.rb +20 -20
  110. data/spec/vcloud/terremark/ecloud/models/ip_spec.rb +22 -21
  111. data/spec/vcloud/terremark/ecloud/models/ips_spec.rb +18 -18
  112. data/spec/vcloud/terremark/ecloud/models/network_spec.rb +55 -51
  113. data/spec/vcloud/terremark/ecloud/models/networks_spec.rb +16 -15
  114. data/spec/vcloud/terremark/ecloud/models/public_ip_spec.rb +26 -27
  115. data/spec/vcloud/terremark/ecloud/models/public_ips_spec.rb +16 -15
  116. data/spec/vcloud/terremark/ecloud/models/vdc_spec.rb +52 -36
  117. data/spec/vcloud/terremark/ecloud/models/vdcs_spec.rb +18 -15
  118. data/spec/vcloud/terremark/ecloud/requests/add_internet_service_spec.rb +46 -43
  119. data/spec/vcloud/terremark/ecloud/requests/configure_internet_service_spec.rb +37 -32
  120. data/spec/vcloud/terremark/ecloud/requests/delete_internet_service_spec.rb +26 -23
  121. data/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb +57 -49
  122. data/spec/vcloud/terremark/ecloud/requests/get_network_ip_spec.rb +41 -0
  123. data/spec/vcloud/terremark/ecloud/requests/get_network_ips_spec.rb +39 -34
  124. data/spec/vcloud/terremark/ecloud/requests/get_network_spec.rb +26 -48
  125. data/spec/vcloud/terremark/ecloud/requests/get_public_ip_spec.rb +25 -26
  126. data/spec/vcloud/terremark/ecloud/requests/get_public_ips_spec.rb +35 -27
  127. data/spec/vcloud/terremark/ecloud/requests/get_vdc_spec.rb +85 -110
  128. data/spec/vcloud/terremark/ecloud/requests/login_spec.rb +7 -4
  129. data/spec/vcloud/vcloud_spec.rb +9 -8
  130. metadata +62 -26
  131. data/lib/fog/vcloud/parser.rb +0 -42
  132. data/lib/fog/vcloud/parsers/get_organization.rb +0 -37
  133. data/lib/fog/vcloud/parsers/get_vdc.rb +0 -62
  134. data/lib/fog/vcloud/parsers/get_versions.rb +0 -46
  135. data/lib/fog/vcloud/parsers/login.rb +0 -36
  136. data/lib/fog/vcloud/parsers/network.rb +0 -53
  137. data/lib/fog/vcloud/terremark/all.rb +0 -9
  138. data/lib/fog/vcloud/terremark/ecloud/parsers/get_internet_services.rb +0 -59
  139. data/lib/fog/vcloud/terremark/ecloud/parsers/get_public_ip.rb +0 -30
  140. data/lib/fog/vcloud/terremark/ecloud/parsers/get_public_ips.rb +0 -40
  141. data/lib/fog/vcloud/terremark/ecloud/parsers/get_vdc.rb +0 -59
  142. data/lib/fog/vcloud/terremark/ecloud/parsers/internet_service.rb +0 -58
  143. data/lib/fog/vcloud/terremark/ecloud/parsers/network.rb +0 -28
  144. data/lib/fog/vcloud/terremark/ecloud/parsers/network_ips.rb +0 -31
  145. data/lib/fog/vcloud/terremark/ecloud/requests/login.rb +0 -27
  146. data/lib/fog/vcloud/terremark/vcloud/parsers/get_vdc.rb +0 -34
  147. data/spec/vcloud/terremark/vcloud/requests/get_vdc_spec.rb +0 -74
@@ -9,24 +9,20 @@ module Fog
9
9
 
10
10
  undef_method :create
11
11
 
12
- def all
13
- load(connection.get_network_ips(href).body.addresses.
14
- map { |address| { :name => address.name, :status => address.status, :server => address.server } })
15
- end
16
-
17
- def get_raw(name)
18
- raw_results.detect { |address| address.name == name }
19
- end
12
+ attribute :href
20
13
 
21
- def reload
22
- super
23
- @raw_results = nil
14
+ def all
15
+ if data = connection.get_network_ips(href).body[:IpAddress]
16
+ load(data)
17
+ end
24
18
  end
25
19
 
26
- private
27
-
28
- def raw_results
29
- @raw_results ||= connection.get_network_ips(href).body.addresses
20
+ def get(uri)
21
+ if data = connection.get_network_ip(uri).body
22
+ new(data)
23
+ end
24
+ rescue Fog::Errors::NotFound
25
+ nil
30
26
  end
31
27
 
32
28
  end
@@ -1,5 +1,3 @@
1
- require 'fog/model'
2
-
3
1
  module Fog
4
2
  module Vcloud
5
3
  module Terremark
@@ -8,20 +6,63 @@ module Fog
8
6
 
9
7
  identity :href
10
8
 
11
- attribute :name
12
- attribute :features
13
- attribute :configuration
14
- attribute :ips_link
9
+ ignore_attributes :xmlns, :xmlns_xsi, :xmlns_xsd, :xmlns_i, :Configuration
10
+
11
+ attribute :name, :aliases => :Name
12
+ attribute :id, :aliases => :Id
13
+ attribute :features, :aliases => :Features, :type => :array
14
+ attribute :links, :aliases => :Link, :type => :array
15
15
  attribute :type
16
- attribute :xmlns
16
+ attribute :gateway, :aliases => :GatewayAddress
17
+ attribute :broadcast, :aliases => :BroadcastAddress
18
+ attribute :address, :aliases => :Address
19
+ attribute :rnat, :aliases => :RnatAddress
20
+ attribute :extension_href, :aliases => :Href
17
21
 
18
22
  def ips
19
- unless @loaded
20
- reload
21
- end
23
+ load_unless_loaded!
22
24
  @ips ||= Fog::Vcloud::Terremark::Ecloud::Ips.
23
25
  new( :connection => connection,
24
- :href => ips_link.href )
26
+ :href => links.detect { |link| link[:name] == "IP Addresses" }[:href] )
27
+ end
28
+
29
+ def rnat=(new_rnat)
30
+ @rnat = new_rnat
31
+ @changed = true
32
+ end
33
+
34
+ def save
35
+ if @changed
36
+ connection.configure_network( extension_href, _compose_network_data )
37
+ end
38
+ true
39
+ end
40
+
41
+ def reload
42
+ super
43
+ merge_attributes(extension_data.body)
44
+ end
45
+
46
+ private
47
+
48
+ def extension_data
49
+ connection.get_network_extensions( extensions_link[:href] )
50
+ end
51
+
52
+ def extensions_link
53
+ links.detect { |link| link[:name] == name }
54
+ end
55
+
56
+ def _compose_network_data
57
+ {
58
+ :id => id,
59
+ :href => extension_href,
60
+ :name => name,
61
+ :rnat => rnat,
62
+ :address => address,
63
+ :broadcast => broadcast,
64
+ :gateway => gateway
65
+ }
25
66
  end
26
67
  end
27
68
  end
@@ -3,12 +3,6 @@ module Fog
3
3
  module Terremark
4
4
  module Ecloud
5
5
 
6
- module Mock
7
- def networks(options = {})
8
- @networks ||= Fog::Vcloud::Terremark::Ecloud::Networks.new(options.merge(:connection => self))
9
- end
10
- end
11
-
12
6
  module Real
13
7
  def networks(options = {})
14
8
  @networks ||= Fog::Vcloud::Terremark::Ecloud::Networks.new(options.merge(:connection => self))
@@ -21,14 +15,21 @@ module Fog
21
15
 
22
16
  model Fog::Vcloud::Terremark::Ecloud::Network
23
17
 
24
- get_request :get_network
25
- vcloud_type "application/vnd.vmware.vcloud.network+xml"
26
- all_request lambda { |networks| networks.connection.get_vdc(networks.href).body.networks }
18
+ attribute :href
19
+
20
+ def all
21
+ if data = connection.get_vdc(href).body[:AvailableNetworks][:Network]
22
+ load(data)
23
+ end
24
+ end
27
25
 
28
- #def all
29
- # pp connection.get_vdc(href).body.networks
30
- # load(connection.get_vdc(href).body.networks.map { |network| { } } )
31
- #end
26
+ def get(uri)
27
+ if data = connection.get_network(uri)
28
+ new(data.body)
29
+ end
30
+ rescue Fog::Errors::NotFound
31
+ nil
32
+ end
32
33
 
33
34
  end
34
35
  end
@@ -0,0 +1,47 @@
1
+ module Fog
2
+ module Vcloud
3
+ module Terremark
4
+ module Ecloud
5
+ class Node < Fog::Vcloud::Model
6
+
7
+ identity :href, :Href
8
+
9
+ ignore_attributes :xmlns, :xmlns_i
10
+
11
+ attribute :ip_address, :aliases => :IpAddress
12
+ attribute :description, :aliases => :Description
13
+ attribute :name, :aliases => :Name
14
+ attribute :port, :aliases => :Port
15
+ attribute :enabled, :aliases => :Enabled
16
+ attribute :id, :aliases => :Id
17
+
18
+ def delete
19
+ requires :href
20
+
21
+ connection.delete_node( href )
22
+ end
23
+
24
+ def save
25
+ if new_record?
26
+ result = connection.add_node( collection.href, _compose_node_data )
27
+ merge_attributes(result.body)
28
+ else
29
+ connection.configure_node( href, _compose_node_data )
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def _compose_node_data
36
+ node_data = {}
37
+ self.class.attributes.select{ |attribute| !send(attribute).nil? }.each { |attribute| node_data[attribute] = send(attribute).to_s }
38
+ node_data
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+
@@ -0,0 +1,30 @@
1
+ module Fog
2
+ module Vcloud
3
+ module Terremark
4
+ module Ecloud
5
+
6
+ class Nodes < Fog::Vcloud::Collection
7
+
8
+ model Fog::Vcloud::Terremark::Ecloud::Node
9
+
10
+ attribute :href, :aliases => :Href
11
+
12
+ def all
13
+ if data = connection.get_nodes(href).body[:NodeService]
14
+ load(data)
15
+ end
16
+ end
17
+
18
+ def get(uri)
19
+ if data = connection.get_node(uri)
20
+ new(data.body)
21
+ end
22
+ rescue Fog::Errors::NotFound
23
+ nil
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,21 +1,18 @@
1
- require 'fog/model'
2
-
3
1
  module Fog
4
2
  module Vcloud
5
3
  module Terremark
6
4
  module Ecloud
7
5
  class PublicIp < Fog::Vcloud::Model
8
6
 
9
- identity :href
7
+ identity :href, :Href
8
+
9
+ ignore_attributes :xmlns, :xmlns_i
10
10
 
11
- attribute :name
12
- attribute :type
13
- attribute :id
11
+ attribute :name, :aliases => :Name
12
+ attribute :id, :aliases => :Id
14
13
 
15
14
  def internet_services
16
- unless @loaded
17
- reload
18
- end
15
+ load_unless_loaded!
19
16
  @internet_services ||= Fog::Vcloud::Terremark::Ecloud::InternetServices.
20
17
  new( :connection => connection,
21
18
  :href => href.to_s + "/internetServices" )
@@ -19,11 +19,27 @@ module Fog
19
19
 
20
20
  undef_method :create
21
21
 
22
+ attribute :href, :aliases => :Href
23
+
22
24
  model Fog::Vcloud::Terremark::Ecloud::PublicIp
23
25
 
24
- get_request :get_public_ip
25
- vcloud_type "application/vnd.tmrk.ecloud.publicIp+xml"
26
- all_request lambda { |public_ips| public_ips.connection.get_public_ips(public_ips.href) }
26
+ #get_request :get_public_ip
27
+ #vcloud_type "application/vnd.tmrk.ecloud.publicIp+xml"
28
+ #all_request lambda { |public_ips| public_ips.connection.get_public_ips(public_ips.href) }
29
+
30
+ def all
31
+ if data = connection.get_public_ips(href).body[:PublicIPAddress]
32
+ load(data)
33
+ end
34
+ end
35
+
36
+ def get(uri)
37
+ if data = connection.get_public_ip(uri)
38
+ new(data.body)
39
+ end
40
+ rescue Fog::Errors::NotFound
41
+ nil
42
+ end
27
43
 
28
44
  end
29
45
  end
@@ -0,0 +1,203 @@
1
+ module Fog
2
+ module Vcloud
3
+ module Terremark
4
+ module Ecloud
5
+ class Server < Fog::Vcloud::Model
6
+
7
+ identity :href, :Href
8
+
9
+ ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd
10
+
11
+ attribute :type
12
+ attribute :name
13
+ attribute :status
14
+ attribute :network_connections, :aliases => :NetworkConnectionSection, :squash => :NetworkConnection
15
+ attribute :os, :aliases => :OperatingSystemSection
16
+ attribute :virtual_hardware, :aliases => :VirtualHardwareSection
17
+ attribute :storage_size, :size
18
+ attribute :links, :aliases => :Link, :type => :array
19
+
20
+ def friendly_status
21
+ load_unless_loaded!
22
+ case status
23
+ when '0'
24
+ 'creating'
25
+ when '2'
26
+ 'off'
27
+ when '4'
28
+ 'on'
29
+ else
30
+ 'unkown'
31
+ end
32
+ end
33
+
34
+ def ready?
35
+ load_unless_loaded!
36
+ @status == '2'
37
+ end
38
+
39
+ def on?
40
+ load_unless_loaded!
41
+ @status == '4'
42
+ end
43
+
44
+ def off?
45
+ load_unless_loaded!
46
+ @status == '2'
47
+ end
48
+
49
+ def power_on
50
+ power_operation( :power_on => :powerOn )
51
+ end
52
+
53
+ def power_off
54
+ power_operation( :power_off => :powerOff )
55
+ end
56
+
57
+ def shutdown
58
+ power_operation( :power_shutdown => :shutdown )
59
+ end
60
+
61
+ def power_reset
62
+ power_operation( :power_reset => :reset )
63
+ end
64
+
65
+ def graceful_restart
66
+ requires :href
67
+ shutdown
68
+ wait_for { off? }
69
+ power_on
70
+ end
71
+
72
+ def delete
73
+ requires :href
74
+ connection.delete_vapp( href)
75
+ end
76
+
77
+ def name=(new_name)
78
+ @name = new_name
79
+ @changed = true
80
+ end
81
+
82
+ def cpus
83
+ { :count => cpu_mess[:VirtualQuantity].to_i,
84
+ :units => cpu_mess[:AllocationUnits] }
85
+ end
86
+
87
+ def cpus=(qty)
88
+ @changed = true
89
+ cpu_mess[:VirtualQuantity] = qty.to_s
90
+ end
91
+
92
+ def memory
93
+ { :amount => memory_mess[:VirtualQuantity].to_i,
94
+ :units => memory_mess[:VirtualQuantityUnits] }
95
+ end
96
+
97
+ def memory=(amount)
98
+ @changed = true
99
+ memory_mess[:VirtualQuantity] = amount.to_s
100
+ end
101
+
102
+ def disks
103
+ disk_mess.map do |dm|
104
+ { :number => dm[:AddressOnParent], :size => dm[:VirtualQuantity].to_i, :resource => dm[:HostResource] }
105
+ end
106
+ end
107
+
108
+ def add_disk(size)
109
+ if @disk_change == :deleted
110
+ raise RuntimeError, "Can't add a disk w/o saving changes or reloading"
111
+ else
112
+ @disk_change = :added
113
+ load_unless_loaded!
114
+ virtual_hardware[:Item] << { :ResourceType => '17',
115
+ :AddressOnParent => (disk_mess.map { |dm| dm[:AddressOnParent] }.sort.last.to_i + 1).to_s,
116
+ :VirtualQuantity => size.to_s }
117
+ end
118
+ true
119
+ end
120
+
121
+ def delete_disk(number)
122
+ if @disk_change == :added
123
+ raise RuntimeError, "Can't delete a disk w/o saving changes or reloading"
124
+ else
125
+ @disk_change = :deleted
126
+ load_unless_loaded!
127
+ unless number == 0
128
+ virtual_hardware[:Item].delete_if { |vh| vh[:ResourceType] == '17' && vh[:AddressOnParent].to_i == number }
129
+ end
130
+ end
131
+ true
132
+ end
133
+
134
+ def reload
135
+ super
136
+ reset_tracking
137
+ end
138
+
139
+ def save
140
+ if new_record?
141
+ requires :name
142
+ puts "NOOP"
143
+ return false
144
+ #result = connection.instantiate_vapp_template( stuff )
145
+ #merge_attributes(result.body)
146
+ else
147
+ if on?
148
+ if @changed
149
+ raise RuntimeError, "Can't save cpu, name or memory changes while the VM is on."
150
+ end
151
+ end
152
+ connection.configure_vapp( href, _compose_vapp_data )
153
+ end
154
+ reset_tracking
155
+ end
156
+
157
+ private
158
+
159
+ def reset_tracking
160
+ @disk_change = false
161
+ @changed = false
162
+ true
163
+ end
164
+
165
+ def _compose_vapp_data
166
+ { :name => name,
167
+ :cpus => cpus[:count],
168
+ :memory => memory[:amount],
169
+ :disks => disks
170
+ }
171
+ end
172
+
173
+ def memory_mess
174
+ load_unless_loaded!
175
+ virtual_hardware[:Item].detect { |item| item[:ResourceType] == "4" }
176
+ end
177
+
178
+ def cpu_mess
179
+ load_unless_loaded!
180
+ virtual_hardware[:Item].detect { |item| item[:ResourceType] == "3" }
181
+ end
182
+
183
+ def disk_mess
184
+ load_unless_loaded!
185
+ virtual_hardware[:Item].select { |item| item[:ResourceType] == "17" }
186
+ end
187
+
188
+ def power_operation(op)
189
+ requires :href
190
+ begin
191
+ connection.send(op.keys.first, href + "/power/action/#{op.values.first}" )
192
+ rescue Excon::Errors::InternalServerError => e
193
+ #Frankly we shouldn't get here ...
194
+ raise e unless e.to_s =~ /because it is already powered on/
195
+ end
196
+ true
197
+ end
198
+
199
+ end
200
+ end
201
+ end
202
+ end
203
+ end