bbrowning-deltacloud-core 0.0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/COPYING +502 -0
  2. data/Rakefile +85 -0
  3. data/bin/deltacloudd +88 -0
  4. data/config.ru +5 -0
  5. data/deltacloud.rb +14 -0
  6. data/lib/deltacloud/base_driver.rb +19 -0
  7. data/lib/deltacloud/base_driver/base_driver.rb +189 -0
  8. data/lib/deltacloud/base_driver/features.rb +159 -0
  9. data/lib/deltacloud/base_driver/mock_driver.rb +37 -0
  10. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +340 -0
  11. data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +170 -0
  12. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +45 -0
  13. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +322 -0
  14. data/lib/deltacloud/drivers/mock/mock_driver.rb +275 -0
  15. data/lib/deltacloud/drivers/opennebula/cloud_client.rb +116 -0
  16. data/lib/deltacloud/drivers/opennebula/occi_client.rb +204 -0
  17. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +241 -0
  18. data/lib/deltacloud/drivers/rackspace/rackspace_client.rb +129 -0
  19. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +150 -0
  20. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +254 -0
  21. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +84 -0
  22. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +144 -0
  23. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +261 -0
  24. data/lib/deltacloud/hardware_profile.rb +153 -0
  25. data/lib/deltacloud/helpers.rb +5 -0
  26. data/lib/deltacloud/helpers/application_helper.rb +56 -0
  27. data/lib/deltacloud/helpers/conversion_helper.rb +38 -0
  28. data/lib/deltacloud/helpers/hardware_profiles_helper.rb +35 -0
  29. data/lib/deltacloud/method_serializer.rb +84 -0
  30. data/lib/deltacloud/models/base_model.rb +58 -0
  31. data/lib/deltacloud/models/image.rb +26 -0
  32. data/lib/deltacloud/models/instance.rb +37 -0
  33. data/lib/deltacloud/models/instance_profile.rb +47 -0
  34. data/lib/deltacloud/models/realm.rb +25 -0
  35. data/lib/deltacloud/models/storage_snapshot.rb +26 -0
  36. data/lib/deltacloud/models/storage_volume.rb +27 -0
  37. data/lib/deltacloud/state_machine.rb +84 -0
  38. data/lib/deltacloud/validation.rb +70 -0
  39. data/lib/drivers.rb +38 -0
  40. data/lib/sinatra/accept_media_types.rb +128 -0
  41. data/lib/sinatra/lazy_auth.rb +56 -0
  42. data/lib/sinatra/rabbit.rb +272 -0
  43. data/lib/sinatra/respond_to.rb +269 -0
  44. data/lib/sinatra/static_assets.rb +83 -0
  45. data/lib/sinatra/url_for.rb +51 -0
  46. data/public/favicon.ico +0 -0
  47. data/public/images/grid.png +0 -0
  48. data/public/images/logo-wide.png +0 -0
  49. data/public/images/rails.png +0 -0
  50. data/public/images/topbar-bg.png +0 -0
  51. data/public/javascripts/application.js +32 -0
  52. data/public/javascripts/jquery-1.4.2.min.js +154 -0
  53. data/public/stylesheets/compiled/application.css +613 -0
  54. data/public/stylesheets/compiled/ie.css +31 -0
  55. data/public/stylesheets/compiled/print.css +27 -0
  56. data/public/stylesheets/compiled/screen.css +456 -0
  57. data/server.rb +342 -0
  58. data/support/fedora/deltacloudd +68 -0
  59. data/support/fedora/rubygem-deltacloud-core.spec +91 -0
  60. data/tests/deltacloud_test.rb +60 -0
  61. data/tests/images_test.rb +94 -0
  62. data/tests/instances_test.rb +136 -0
  63. data/tests/realms_test.rb +56 -0
  64. data/tests/storage_snapshots_test.rb +48 -0
  65. data/tests/storage_volumes_test.rb +48 -0
  66. data/torquebox-ec2-config.ru +8 -0
  67. data/views/accounts/index.html.haml +11 -0
  68. data/views/accounts/show.html.haml +30 -0
  69. data/views/api/show.html.haml +15 -0
  70. data/views/api/show.xml.haml +5 -0
  71. data/views/docs/collection.html.haml +37 -0
  72. data/views/docs/collection.xml.haml +14 -0
  73. data/views/docs/index.html.haml +15 -0
  74. data/views/docs/index.xml.haml +5 -0
  75. data/views/docs/operation.html.haml +31 -0
  76. data/views/docs/operation.xml.haml +10 -0
  77. data/views/errors/auth_exception.html.haml +8 -0
  78. data/views/errors/auth_exception.xml.haml +2 -0
  79. data/views/errors/backend_error.html.haml +17 -0
  80. data/views/errors/backend_error.xml.haml +8 -0
  81. data/views/errors/validation_failure.html.haml +11 -0
  82. data/views/errors/validation_failure.xml.haml +7 -0
  83. data/views/hardware_profiles/index.html.haml +25 -0
  84. data/views/hardware_profiles/index.xml.haml +4 -0
  85. data/views/hardware_profiles/show.html.haml +19 -0
  86. data/views/hardware_profiles/show.xml.haml +17 -0
  87. data/views/images/index.html.haml +30 -0
  88. data/views/images/index.xml.haml +7 -0
  89. data/views/images/show.html.haml +21 -0
  90. data/views/images/show.xml.haml +5 -0
  91. data/views/instance_states/show.gv.erb +45 -0
  92. data/views/instance_states/show.html.haml +31 -0
  93. data/views/instance_states/show.xml.haml +8 -0
  94. data/views/instances/index.html.haml +30 -0
  95. data/views/instances/index.xml.haml +23 -0
  96. data/views/instances/new.html.haml +55 -0
  97. data/views/instances/show.html.haml +43 -0
  98. data/views/instances/show.xml.haml +41 -0
  99. data/views/layout.html.haml +26 -0
  100. data/views/realms/index.html.haml +29 -0
  101. data/views/realms/index.xml.haml +12 -0
  102. data/views/realms/show.html.haml +15 -0
  103. data/views/realms/show.xml.haml +10 -0
  104. data/views/root/index.html.haml +4 -0
  105. data/views/storage_snapshots/index.html.haml +20 -0
  106. data/views/storage_snapshots/index.xml.haml +11 -0
  107. data/views/storage_snapshots/show.html.haml +14 -0
  108. data/views/storage_snapshots/show.xml.haml +9 -0
  109. data/views/storage_volumes/index.html.haml +21 -0
  110. data/views/storage_volumes/index.xml.haml +13 -0
  111. data/views/storage_volumes/show.html.haml +20 -0
  112. data/views/storage_volumes/show.xml.haml +13 -0
  113. metadata +361 -0
@@ -0,0 +1,84 @@
1
+ #
2
+ # Copyright (C) 2009 RimuHosting Ltd
3
+ # Author: Ivan Meredith <ivan@ivan.net.nz>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "net/http"
20
+ require "net/https"
21
+ require "rubygems"
22
+ require "json"
23
+ require "deltacloud/base_driver"
24
+
25
+ module Deltacloud
26
+ module Drivers
27
+ module RimuHosting
28
+
29
+ class RimuHostingClient
30
+ def initialize(credentials ,baseuri = 'https://rimuhosting.com/r')
31
+ @uri = URI.parse(baseuri)
32
+ @service = Net::HTTP.new(@uri.host, @uri.port)
33
+ @service.use_ssl = true
34
+ @auth = "rimuhosting apikey=#{credentials.password}"
35
+ end
36
+
37
+ def request(resource, data='', method='GET')
38
+ headers = {"Accept" => "application/json", "Content-Type" => "application/json"}
39
+ if(!@auth.nil?)
40
+ headers["Authorization"] = @auth
41
+ end
42
+ r = @service.send_request(method, @uri.path + resource, data, headers)
43
+ puts r.body
44
+ res = JSON.parse(r.body)
45
+ res = res[res.keys[0]]
46
+
47
+ if(res['response_type'] == "ERROR" and ( (res['error_info']['error_class'] == "PermissionException") or
48
+ (res['error_info']['error_class'] == "LoginRequired") ))
49
+ raise Deltacloud::AuthException.new
50
+ end
51
+ res
52
+ end
53
+
54
+ def list_images
55
+ request('/distributions')["distro_infos"]
56
+ end
57
+
58
+ def list_plans
59
+ request('/pricing-plans;server-type=VPS')["pricing_plan_infos"]
60
+ end
61
+
62
+ def list_nodes
63
+ request('/orders;include_inactive=N')["about_orders"]
64
+ end
65
+
66
+ def set_server_state(id, state)
67
+ json = {"reboot_request" => {"running_state" => state}}.to_json
68
+ request("/orders/order-#{id}-a/vps/running-state", json, 'PUT')
69
+ end
70
+
71
+ def delete_server(id)
72
+ request("/orders/order-#{id}-a/vps",'', 'DELETE')
73
+ end
74
+
75
+ def create_server(image_id, plan_code, name)
76
+ json = {:new_vps => {:instantiation_options => {:domain_name => name, :distro => image_id},
77
+ :pricing_plan_code => plan_code}}.to_json
78
+ request('/orders/new-vps',json, 'POST')[:about_order]
79
+ end
80
+ end
81
+
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,144 @@
1
+ #
2
+ # Copyright (C) 2009 RimuHosting Ltd
3
+ # Author: Ivan Meredith <ivan@ivan.net.nz>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "deltacloud/base_driver"
20
+ require "deltacloud/drivers/rimuhosting/rimuhosting_client"
21
+
22
+ module Deltacloud
23
+ module Drivers
24
+ module RimuHosting
25
+
26
+ class RimuHostingDriver < Deltacloud::BaseDriver
27
+
28
+ feature :instances, :user_name
29
+
30
+ def images(credentails, opts=nil)
31
+ rh = RimuHostingClient.new(credentails)
32
+ images = rh.list_images.map do | image |
33
+ Image.new({
34
+ :id => image["distro_code"].gsub(/\./,"-"),
35
+ :name => image["distro_code"],
36
+ :description => image["distro_description"],
37
+ :owner_id => "root",
38
+ :architecture => "x86"
39
+ })
40
+ end
41
+ images.sort_by{|e| [e.description]}
42
+ images = filter_on( images, :id, opts)
43
+ images
44
+ end
45
+
46
+ def hardware_profiles(credentials, opts = nil)
47
+ rh = RimuHostingClient.new(credentials)
48
+ results = rh.list_plans.map do |plan|
49
+ # FIXME: x86 is not a valid architecture; what is Rimu offering ?
50
+ # FIXME: VPS plans offer a range of memory/storage, but that's
51
+ # not contained in hte pricing_plan_infos
52
+ HardwareProfile.new(plan["pricing_plan_code"]) do
53
+ memory plan["minimum_memory_mb"].to_f
54
+ storage plan["minimum_disk_gb"].to_i
55
+ architecture "x86"
56
+ end
57
+ end
58
+ filter_hardware_profiles(results, opts)
59
+ end
60
+
61
+ def realms(credentials, opts=nil)
62
+ [Realm.new( {
63
+ :id=>"rimu",
64
+ :name=>"RimuHosting",
65
+ :state=> "AVAILABLE"
66
+ } )]
67
+ end
68
+
69
+ def instances(credentials, opts=nil)
70
+ rh = RimuHostingClient.new(credentials)
71
+ instances = rh.list_nodes.map do | inst |
72
+ convert_srv_to_instance(inst)
73
+ end
74
+ instances = filter_on( instances, :id, opts)
75
+ instances = filter_on( instances, :state, opts )
76
+ instances
77
+ end
78
+
79
+ def reboot_instance(credentials, id)
80
+ rh = RimuHostingClient.new(credentials)
81
+ rh.set_server_state(id, :RESTARTING)
82
+ end
83
+
84
+ def start_instance(credentials, id)
85
+ rh = RimuHostingClient.new(credentials)
86
+ rh.set_server_state(id, :STARTED)
87
+ end
88
+
89
+ def stop_instance(credentials, id)
90
+ destroy_instance(credentials, id)
91
+ end
92
+
93
+ def destroy_instance(credentials, id)
94
+ rh = RimuHostingClient.new(credentials)
95
+ rh.delete_server(id)
96
+ end
97
+
98
+ def create_instance(credentials, image_id, opts)
99
+ rh = RimuHostingClient.new(credentials)
100
+ # really need to raise an exception here.
101
+ hwp_id = opts[:hwp_id] || 1
102
+ # really bad, but at least its a fqdn
103
+ name = Time.now.to_s + '.com'
104
+ if (opts[:name]) then
105
+ name = opts[:name]
106
+ end
107
+ convert_srv_to_instance(rh.create_server(image_id, hwp_id, name))
108
+
109
+ end
110
+
111
+ def convert_srv_to_instance( inst )
112
+ Instance.new({
113
+ :id => inst["order_oid"].to_s,
114
+ :name => inst["domain_name"],
115
+ :image_id => "lenny",
116
+ :state => "RUNNING",
117
+ :name => inst["domain_name"],
118
+ :realm_id => "RH",
119
+ :owner_id => "root",
120
+ :instance_profile => InstanceProfile.new("none"),
121
+ :actions => instance_actions_for("RUNNING"),
122
+ :public_addresses => inst["allocated_ips"]["primary_ip"]
123
+ })
124
+ end
125
+
126
+ define_instance_states do
127
+ start.to( :pending ) .automatically
128
+
129
+ pending.to( :running ) .automatically
130
+
131
+ running.to( :running ) .on(:reboot)
132
+ running.to( :shutting_down ) .on(:stop)
133
+
134
+ shutting_down.to( :stopped ) .automatically
135
+
136
+ stopped.to( :finish ) .automatically
137
+ end
138
+
139
+
140
+ end
141
+
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,261 @@
1
+ # Copyright (C) 2010 Red Hat, Inc.
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ #
17
+ # This driver uses the fog library (Geemus - Wesley Beary) to talk to terremark... see
18
+ # http://github.com/geemus/fog
19
+ # see terremark vcloud express api at:
20
+ # https://community.vcloudexpress.terremark.com/en-us/product_docs/w/wiki/d-complete-vcloud-express-api-document.aspx
21
+ #
22
+ # 02 May 2010
23
+ #
24
+ require 'deltacloud/base_driver'
25
+ require 'fog'
26
+ require 'excon'
27
+ require 'nokogiri'
28
+
29
+ module Deltacloud
30
+ module Drivers
31
+ module Terremark
32
+
33
+ class TerremarkDriver < Deltacloud::BaseDriver
34
+
35
+ feature :instances, :user_name
36
+
37
+ #--
38
+ # Vapp State Map... for use with convert_instance (get an integer back from terremark)
39
+ #--
40
+ VAPP_STATE_MAP = { "0" => "PENDING", "1" => "PENDING", "2" => "STOPPED", "4" => "RUNNING" }
41
+
42
+ #--
43
+ # HARDWARE PROFILES
44
+ #--
45
+ define_hardware_profile 'default' do
46
+ cpu [1,2,4,8]
47
+ memory [512, 1024, 2048, 4096, 8192]
48
+ storage (1..500).to_a
49
+ end
50
+ #storage_disks [1..15]
51
+
52
+ #--
53
+ # IMAGES
54
+ #--
55
+ #aka "vapp_templates"
56
+ def images(credentials, opts=nil)
57
+ image_list = []
58
+ terremark_client = new_client(credentials)
59
+ vdc_id = terremark_client.default_vdc_id
60
+ catalogItems = terremark_client.get_catalog(vdc_id).body['CatalogItems']
61
+ catalogItems.each{ |catalog_item|
62
+ current_item_id = catalog_item['href'].split('/').last
63
+ current_item = terremark_client.get_catalog_item(current_item_id).body['Entity']
64
+ if(current_item['type'] == 'application/vnd.vmware.vcloud.vAppTemplate+xml')
65
+ image_list << convert_image(current_item, credentials.user)
66
+ end
67
+ } #end of catalogItems.each
68
+ image_list = filter_on( image_list, :id, opts )
69
+ image_list = filter_on( image_list, :architecture, opts )
70
+ image_list = filter_on( image_list, :owner_id, opts )
71
+ image_list
72
+ end
73
+
74
+ #--
75
+ # REALMS
76
+ #--
77
+ #only one realm... everything in US?
78
+ def realms(credentials, opts=nil)
79
+ [Realm.new( {
80
+ :id=>"US-Miami",
81
+ :name=>"United States - Miami",
82
+ :state=> "AVAILABLE"
83
+ } )]
84
+ end
85
+
86
+ #--
87
+ # INSTANCES
88
+ #--
89
+ #aka vApps
90
+ def instances(credentials, opts=nil)
91
+ instances = []
92
+ terremark_client = new_client(credentials)
93
+ vdc_items = terremark_client.get_vdc(terremark_client.default_vdc_id()).body['ResourceEntities']
94
+ vdc_items.each{|current_item|
95
+ if(current_item['type'] == 'application/vnd.vmware.vcloud.vApp+xml')
96
+ vapp_id = current_item['href'].split('/').last
97
+ vapp = terremark_client.get_vapp(vapp_id)
98
+ instances << convert_instance(vapp, terremark_client, credentials.user)
99
+ end
100
+ }#end vdc_items.each
101
+ instances = filter_on( instances, :id, opts )
102
+ instances
103
+ end
104
+
105
+ #--
106
+ # FINITE STATE MACHINE
107
+ #--
108
+ #by default new instance --> powered_off
109
+ define_instance_states do
110
+ start.to(:pending) .on( :create )
111
+ pending.to(:stopped) .automatically
112
+ stopped.to(:running) .on( :start )
113
+ running.to(:running) .on( :reboot )
114
+ running.to(:shutting_down) .on( :stop )
115
+ shutting_down.to(:stopped) .automatically
116
+ stopped.to(:end) .on( :destroy )
117
+ end
118
+
119
+
120
+ #--
121
+ # CREATE INSTANCE
122
+ #--
123
+ #launch a vapp template. Needs a name, ram, no. cpus, id of vapp_template
124
+ def create_instance(credentials, image_id, opts)
125
+ new_vapp = nil
126
+ vapp_opts = {} #assemble options to pass to Fog::Terremark::Real.instantiate_vapp_template
127
+ terremark_hwp = hardware_profiles(credentials, {:name => 'default'}).first #sanity check values against default
128
+ name = opts['name'] #name could be nil or length 0 or too long
129
+ name = "inst#{Time.now.to_i}" if (name.nil? || (name.length == 0))
130
+ name = name.slice(0..13) #name < 15 chars (says terremark)
131
+ unless ( (terremark_hwp.include?(:cpu, opts[:hwp_cpu].to_i)) &&
132
+ (terremark_hwp.include?(:memory, opts[:hwp_memory].to_i)) ) then
133
+ raise Deltacloud::Validation::Failure.new(Deltacloud::Validation::Param.new(["cpu"]), "Error with cpu and/or memory values. you said cpu->#{opts[:hwp_cpu]} and mem->#{opts[:hwp_memory]}")
134
+ end
135
+ vapp_opts['cpus'] = opts[:hwp_cpu]
136
+ vapp_opts['memory'] = opts[:hwp_memory]
137
+ terremark_client = new_client(credentials)
138
+ #######
139
+ #FIXME# what happens if there is an issue getting the new vapp id? (eg even though created succesfully)
140
+ #######
141
+ vapp_id = terremark_client.instantiate_vapp_template(name, image_id, vapp_opts).body['href'].split('/').last
142
+ new_vapp = terremark_client.get_vapp(vapp_id)
143
+ return convert_instance(new_vapp, terremark_client, credentials.user) #return an Instance object
144
+ end
145
+
146
+ #--
147
+ # REBOOT INSTANCE
148
+ #--
149
+ def reboot_instance(credentials, id)
150
+ terremark_client = new_client(credentials)
151
+ terremark_client.power_reset(id)
152
+ end
153
+
154
+ #--
155
+ # START INSTANCE
156
+ #--
157
+ def start_instance(credentials, id)
158
+ terremark_client = new_client(credentials)
159
+ terremark_client.power_on(id)
160
+ end
161
+
162
+ #--
163
+ # STOP INSTANCE
164
+ #--
165
+ def stop_instance(credentials, id)
166
+ terremark_client = new_client(credentials)
167
+ terremark_client.power_shutdown(id)
168
+ end
169
+
170
+ #--
171
+ # DESTROY INSTANCE
172
+ #--
173
+ #shuts down... in terremark need to do a futher delete to get rid of a vapp entirely
174
+ def destroy_instance(credentials, id)
175
+ terremark_client = new_client(credentials)
176
+ terremark_client.delete_vapp(id)
177
+ end
178
+
179
+ #--
180
+ # PRIVATE METHODS:
181
+ #--
182
+
183
+ private
184
+
185
+ #--
186
+ # CONVERT IMAGE
187
+ #--
188
+ #gets a vapp_template from a catalog and makes it a Image
189
+ def convert_image(catalog_vapp_template, account_name)
190
+ name = catalog_vapp_template['name']
191
+ #much fudging ensues
192
+ #arch = name.scan(/(36|24).bit/).first
193
+ #k enuf o'that now!
194
+ arch = "n/a" #Leaving out entirely as we don't get one from terremark (could parse but its a fudge)
195
+ Image.new( {
196
+ :id => catalog_vapp_template['href'].split('/').last,
197
+ :name => catalog_vapp_template['name'],
198
+ :architecture => arch,
199
+ :owner_id => account_name,
200
+ :description => catalog_vapp_template['name']
201
+ })
202
+ end
203
+
204
+ #--
205
+ # CONVERT INSTANCE
206
+ #--
207
+ def convert_instance(vapp, terremark_client, account_name)
208
+ vapp_private_ip = vapp.body['IpAddress']
209
+ vapp_public_ip = terremark_client.get_public_ips(terremark_client.default_vdc_id).body['PublicIpAddresses'].first['name']#get_public_address(terremark_client, vapp_private_ip)
210
+ vapp_status = vapp.body['status']
211
+ current_state = VAPP_STATE_MAP[vapp_status] #status == 0->BEING_CREATED 2->OFF 4->ON
212
+ profile = InstanceProfile.new("default")
213
+ name = vapp.body['name']
214
+ if current_state != "PENDING" #can only grab this stuff after instance is created
215
+ profile.cpu = vapp.body['VirtualHardware']['cpu']
216
+ profile.memory = vapp.body['VirtualHardware']['ram']
217
+ #######
218
+ #FIXME# could be more that one disk... but for now capture only first
219
+ #######
220
+ disk = ((vapp.body['VirtualHardware']['disks'].first.to_i) / 1024 / 1024).to_s
221
+ profile.storage = disk
222
+ #######
223
+ #FIXME# this is a hack, shouldn't place this info next to name as some clients may rely on name field... probably will introduce
224
+ ####### a new field in the API for this (e.g. description/text field... human readable)
225
+ #name = "#{name} - [ #{vapp.body['OperatingSystem']['Description']} ]"
226
+ end
227
+ Instance.new( {
228
+ :id => vapp.body['href'].split('/').last,
229
+ :owner_id => "#{account_name}",
230
+ #:image_id => "n/a", #cant get this... see https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60/t/376.aspx
231
+ :name => name,
232
+ :realm_id => "US-Miami",
233
+ :state => current_state,
234
+ :actions => instance_actions_for(current_state),
235
+ :public_addresses => vapp_public_ip,
236
+ :private_addresses => vapp_private_ip,
237
+ :instance_profile => profile
238
+ } )
239
+ end
240
+
241
+ #--
242
+ # NEW CLIENT
243
+ #--
244
+ #use supplied credentials to make a new client for talking to terremark
245
+ def new_client(credentials)
246
+ #Fog constructor expecting credentials[:terremark_password] and credentials[:terremark_username]
247
+ terremark_credentials = {:terremark_vcloud_username => "#{credentials.user}", :terremark_vcloud_password => "#{credentials.password}" }
248
+ terremark_client = Fog::Terremark::Vcloud.new(terremark_credentials)
249
+ vdc_id = terremark_client.default_vdc_id
250
+ if (vdc_id.nil?)
251
+ raise DeltaCloud::AuthException.new
252
+ end
253
+ terremark_client
254
+ end
255
+
256
+
257
+ end
258
+
259
+ end
260
+ end
261
+ end