Class: Rightscale::Slicehost
- Includes:
- RightSlicehostInterface
- Defined in:
- lib/right_slicehost.rb
Overview
# Slices:
sl = Rightscale::Slicehost.new('12345...uvwxyz')
sl.list_images #=>
[{:sls_id=>2, :name=>"CentOS 5.2"},
{:sls_id=>3, :name=>"Gentoo 2008.0"},
{:sls_id=>4, :name=>"Debian 4.0 (etch)"},
{:sls_id=>5, :name=>"Fedora 9"},
{:sls_id=>9, :name=>"Arch 2007.08"},
{:sls_id=>10, :name=>"Ubuntu 8.04.1 LTS (hardy)"},
{:sls_id=>11, :name=>"Ubuntu 8.10 (intrepid)"}]
sl.list_flavors #=>
[{:sls_id=>1, :name=>"256 slice", :price=>2000, :ram=>256},
{:sls_id=>2, :name=>"512 slice", :price=>3800, :ram=>512},
{:sls_id=>3, :name=>"1GB slice", :price=>7000, :ram=>1024},
{:sls_id=>4, :name=>"2GB slice", :price=>13000, :ram=>2048},
{:sls_id=>5, :name=>"4GB slice", :price=>25000, :ram=>4096},
{:sls_id=>6, :name=>"8GB slice", :price=>45000, :ram=>8192},
{:sls_id=>7, :name=>"15.5GB slice", :price=>80000, :ram=>15872}]
sl.create_slice(:flavor_id=>1 , :image_id=>2, :name=>'my-slice' ) #=>
{:flavor_sls_id=>1,
:addresses=>["173.45.224.125"],
:bw_in=>0.0,
:sls_id=>26831,
:name=>"my-slice",
:status=>"build",
:bw_out=>0.0,
:ip_address=>"173.45.224.125",
:progress=>0,
:image_sls_id=>2,
:root_password=>"my-slicen57"}
sl.rebuild_slice(26831, :image_id => 3) #=> true
sl.reboot_slice(26832, :hard) #=> true
sl.delete_slice(26832) #=> true
# DNS:
sl.list_zones #=>
[ {:origin=>"a1.my-domain.com.", :ttl=>300, :sls_id=>45486, :active=>true},
{:origin=>"a2.my-domain.com.", :ttl=>300, :sls_id=>45485, :active=>true},
{:origin=>"a3.my-domain.com.", :ttl=>300, :sls_id=>45487, :active=>false}, ... ]
sl.list_records #=>
[ { :sls_id=>"348257",
:zone_id=>45687,
:data=>"woo-hoo.my-domain.com",
:aux=>"0",
:name=>"wooooohooooo",
:ttl=>86400,
:active=>true,
:record_type=>"CNAME"}, ... ]
Defined Under Namespace
Classes: BackupsParser, FlavorsParser, ImagesParser, RecordsParser, RightHttp2xxParser, SlicesParser, ZonesParser
Constant Summary
Constants included from RightSlicehostInterface
RightSlicehostInterface::DEFAULT_SLICEHOST_URL, RightSlicehostInterface::SLICEHOST_PROBLEMS
Instance Attribute Summary
Attributes included from RightSlicehostInterface
#cache, #connection, #last_errors, #last_request, #last_response, #logger, #params, #slicehost_pasword
Instance Method Summary collapse
-
#build_path(path, sls_id = nil, action = nil) ⇒ Object
:nodoc:.
-
#build_xml(name, params) ⇒ Object
:nodoc:.
-
#create_record(params = {}) ⇒ Object
Create a new record.
-
#create_slice(params = {}) ⇒ Object
Create a new slice.
-
#create_zone(params = {}) ⇒ Object
Create a new zone.
-
#delete_record(sls_id) ⇒ Object
Delete a record.
-
#delete_slice(sls_id) ⇒ Object
Delete a slice.
-
#delete_zone(sls_id) ⇒ Object
Delete a zone.
-
#initialize(slicehost_password = nil, params = {}) ⇒ Slicehost
constructor
A new instance of Slicehost.
-
#list_backups(sls_id = nil) ⇒ Object
List backups.
-
#list_flavors(sls_id = nil) ⇒ Object
List flavors.
-
#list_images(sls_id = nil) ⇒ Object
List images.
-
#list_records(sls_id = nil) ⇒ Object
List DNS Records.
-
#list_slices(sls_id = nil) ⇒ Object
List slices.
-
#list_zones(sls_id = nil) ⇒ Object
List DNS Zones.
-
#reboot_slice(sls_id, hard_reboot = false) ⇒ Object
Reboot a slice (soft reboot is by default).
-
#rebuild_slice(sls_id, params) ⇒ Object
Rebuild a slice.
-
#update_record(sls_id, params = {}) ⇒ Object
Update a record.
-
#update_slice(sls_id, params = {}) ⇒ Object
Update a slice.
-
#update_zone(sls_id, params = {}) ⇒ Object
Update a zone.
Methods included from RightSlicehostInterface
bench_parser, bench_slicehost, #cache_hits?, caching, caching=, #caching?, #cgi_escape_params, #generate_request, #init, #multi_thread, #on_exception, #request_cache_or_info, #request_info, slicehost_problems, #update_cache
Constructor Details
#initialize(slicehost_password = nil, params = {}) ⇒ Slicehost
Returns a new instance of Slicehost.
106 107 108 109 |
# File 'lib/right_slicehost.rb', line 106 def initialize(slicehost_password=nil, params={}) slicehost_password ||= ENV['SLICEHOST_PASSWORD'] init slicehost_password, params end |
Instance Method Details
#build_path(path, sls_id = nil, action = nil) ⇒ Object
:nodoc:
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/right_slicehost.rb', line 111 def build_path(path, sls_id=nil, action=nil) # :nodoc: path = path.to_s unless (sls_id || action) path += '.xml' else path += "/#{sls_id}#{action ? '' : '.xml'}" if sls_id path += "/#{action}.xml" if action end path end |
#build_xml(name, params) ⇒ Object
:nodoc:
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/right_slicehost.rb', line 122 def build_xml(name, params) # :nodoc: xml_params = params.to_a.map do |key,value| key = key.to_s.gsub('_','-') "<#{key}>#{CGI.escape(value.to_s)}</#{key}>" end.join("\n") "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<#{name.to_s}>\n" + "#{xml_params}\n" + "</#{name.to_s}>\n" end |
#create_record(params = {}) ⇒ Object
Create a new record.
sl.create_record(:zone_id => 45687, :data=>"woo-hoo.my-domain.com", :name=>"wooooohooooo", :data=>"woo-hoo.my-domain.com") #=>
[ { :sls_id=>348257,
:zone_id=>45687,
:data=>"woo-hoo.my-domain.com",
:aux=>"0",
:name=>"wooooohooooo",
:ttl=>86400,
:active=>true,
:record_type=>"CNAME"}, ... ]
411 412 413 414 415 416 417 |
# File 'lib/right_slicehost.rb', line 411 def create_record(params={}) params[:active] = (params[:active] ? 'Y' : 'N') unless params[:active].nil? # POST /records.xml req = generate_request(Net::HTTP::Post, build_path(:records)) req[:request].body = build_xml(:record, params) request_info(req, RecordsParser.new(:logger => @logger)).first end |
#create_slice(params = {}) ⇒ Object
Create a new slice.
sl.create_slice(:flavor_id=>1 , :image_id=>2, :name=>'my-slice' ) #=>
{:flavor_sls_id=>1,
:addresses=>["173.45.224.125"],
:bw_in=>0.0,
:sls_id=>26831,
:name=>"my-slice",
:status=>"build",
:bw_out=>0.0,
:ip_address=>"173.45.224.125",
:progress=>0,
:image_sls_id=>2,
:root_password=>"my-slicen57"}
254 255 256 257 258 259 |
# File 'lib/right_slicehost.rb', line 254 def create_slice(params={}) # POST /slices.xml req = generate_request(Net::HTTP::Post, build_path(:slices)) req[:request].body = build_xml(:slice, params) request_info(req, SlicesParser.new(:logger => @logger)).first end |
#create_zone(params = {}) ⇒ Object
Create a new zone.
sl.create_zone(:origin => 'a4.my_domain.ru', :ttl => 111, :active => false) #=>
{ :origin=>"a4.my-domain.com.",
:ttl=>111,
:sls_id=>45689,
:active=>false}
343 344 345 346 347 348 349 |
# File 'lib/right_slicehost.rb', line 343 def create_zone(params={}) params[:active] = (params[:active] ? 'Y' : 'N') unless params[:active].nil? # POST /zones.xml req = generate_request(Net::HTTP::Post, build_path(:zones)) req[:request].body = build_xml(:zone, params) request_info(req, ZonesParser.new(:logger => @logger)).first end |
#delete_record(sls_id) ⇒ Object
Delete a record.
sl.delete_record(348257) #=> true
435 436 437 438 439 |
# File 'lib/right_slicehost.rb', line 435 def delete_record(sls_id) # DELETE /records/id.xml req = generate_request(Net::HTTP::Delete, build_path(:records, sls_id)) request_info(req, RightHttp2xxParser.new(:logger => @logger)) end |
#delete_slice(sls_id) ⇒ Object
Delete a slice.
sl.delete_slice(26831) #=> true
302 303 304 305 306 |
# File 'lib/right_slicehost.rb', line 302 def delete_slice(sls_id) # DELETE /slices/id.xml req = generate_request(Net::HTTP::Delete, build_path(:slices, sls_id)) request_info(req, RightHttp2xxParser.new(:logger => @logger)) end |
#delete_zone(sls_id) ⇒ Object
Delete a zone.
sl.delete_zone(45486) #=> true
367 368 369 370 371 |
# File 'lib/right_slicehost.rb', line 367 def delete_zone(sls_id) # DELETE /zones/id.xml req = generate_request(Net::HTTP::Delete, build_path(:zones, sls_id)) request_info(req, RightHttp2xxParser.new(:logger => @logger)) end |
#list_backups(sls_id = nil) ⇒ Object
List backups.
sl.list_backups #=>
[{:sls_id=>"5-6507",
:slice_sls_id=>26831,
:name=>"backup 1",
:date=>Wed Dec 10 00:43:20 UTC 2008}, ...]
sl.list_backups("5-6507") #=>
{:sls_id=>"5-6507",
:slice_sls_id=>26831,
:name=>"backup 1",
:date=>Wed Dec 10 00:43:20 UTC 2008}
204 205 206 207 208 209 210 |
# File 'lib/right_slicehost.rb', line 204 def list_backups(sls_id=nil) req = generate_request(Net::HTTP::Get, build_path(:backups, sls_id)) result = request_cache_or_info(:list_backups, req, BackupsParser, sls_id.nil?) sls_id ? result.first : result rescue on_exception end |
#list_flavors(sls_id = nil) ⇒ Object
List flavors.
sl.list_flavors #=>
[{:sls_id=>1, :name=>"256 slice", :price=>2000, :ram=>256},
{:sls_id=>2, :name=>"512 slice", :price=>3800, :ram=>512},
{:sls_id=>3, :name=>"1GB slice", :price=>7000, :ram=>1024},
{:sls_id=>4, :name=>"2GB slice", :price=>13000, :ram=>2048},
{:sls_id=>5, :name=>"4GB slice", :price=>25000, :ram=>4096},
{:sls_id=>6, :name=>"8GB slice", :price=>45000, :ram=>8192},
{:sls_id=>7, :name=>"15.5GB slice", :price=>80000, :ram=>15872}]
sl.list_flavors(6) #=> {:sls_id=>6, :name=>"8GB slice", :price=>45000, :ram=>8192}
176 177 178 179 180 181 182 |
# File 'lib/right_slicehost.rb', line 176 def list_flavors(sls_id=nil) req = generate_request(Net::HTTP::Get, build_path(:flavors, sls_id)) result = request_cache_or_info(:list_flavors, req, FlavorsParser, sls_id.nil?) sls_id ? result.first : result rescue on_exception end |
#list_images(sls_id = nil) ⇒ Object
List images.
sl.list_images #=>
[{:sls_id=>2, :name=>"CentOS 5.2"},
{:sls_id=>3, :name=>"Gentoo 2008.0"},
{:sls_id=>4, :name=>"Debian 4.0 (etch)"},
{:sls_id=>5, :name=>"Fedora 9"},
{:sls_id=>9, :name=>"Arch 2007.08"},
{:sls_id=>10, :name=>"Ubuntu 8.04.1 LTS (hardy)"},
{:sls_id=>11, :name=>"Ubuntu 8.10 (intrepid)"}]
sl.list_images(9) #=> {:sls_id=>9, :name=>"Arch 2007.08"}
151 152 153 154 155 156 157 |
# File 'lib/right_slicehost.rb', line 151 def list_images(sls_id=nil) req = generate_request(Net::HTTP::Get, build_path(:images, sls_id)) result = request_cache_or_info(:list_images, req, ImagesParser, sls_id.nil?) sls_id ? result.first : result rescue on_exception end |
#list_records(sls_id = nil) ⇒ Object
List DNS Records
sl.list_records #=>
[ { :sls_id=>"348257",
:zone_id=>45687,
:data=>"woo-hoo.my-domain.com",
:aux=>"0",
:name=>"wooooohooooo",
:ttl=>86400,
:active=>true,
:record_type=>"CNAME"}, ... ]
389 390 391 392 393 394 395 396 397 |
# File 'lib/right_slicehost.rb', line 389 def list_records(sls_id=nil) # GET /records.xml # GET /records/id.xml req = generate_request(Net::HTTP::Get, build_path(:records, sls_id)) result = request_cache_or_info(:list_records, req, RecordsParser, sls_id.nil?) sls_id ? result.first : result rescue on_exception end |
#list_slices(sls_id = nil) ⇒ Object
List slices.
sl.list_slices #=>
[{:bw_in=>0.05,
:sls_id=>26706,
:bw_out=>0.0,
:ip_address=>"173.45.233.125",
:progress=>100,
:status=>"active",
:name=>"slice26706",
:image_sls_id=>11,
:flavor_sls_id=>1,
:addresses=>["173.45.233.125"]}, ...]
230 231 232 233 234 235 236 237 |
# File 'lib/right_slicehost.rb', line 230 def list_slices(sls_id=nil) # GET /slices.xml req = generate_request(Net::HTTP::Get, build_path(:slices, sls_id)) result = request_cache_or_info(:list_slices, req, SlicesParser, sls_id.nil?) sls_id ? result.first : result rescue on_exception end |
#list_zones(sls_id = nil) ⇒ Object
List DNS Zones.
# bunch of zones
sl.list_zones #=>
[ {:origin=>"a1.my-domain.com.", :ttl=>300, :sls_id=>45486, :active=>true},
{:origin=>"a2.my-domain.com.", :ttl=>300, :sls_id=>45485, :active=>true},
{:origin=>"a3.my-domain.com.", :ttl=>300, :sls_id=>45487, :active=>false} ]
# single zone
sl.list_zones(45486) #=>
{:origin=>"a1.my-domain.com.", :ttl=>300, :sls_id=>45486, :active=>true}
325 326 327 328 329 330 331 332 333 |
# File 'lib/right_slicehost.rb', line 325 def list_zones(sls_id=nil) # GET /zones.xml # GET /zones/id.xml req = generate_request(Net::HTTP::Get, build_path(:zones, sls_id)) result = request_cache_or_info(:list_zones, req, ZonesParser, sls_id.nil?) sls_id ? result.first : result rescue on_exception end |
#reboot_slice(sls_id, hard_reboot = false) ⇒ Object
Reboot a slice (soft reboot is by default).
sl.reboot_slice(26831) #=> true
sl.reboot_slice(26832, :hard) #=> true
289 290 291 292 293 294 295 296 |
# File 'lib/right_slicehost.rb', line 289 def reboot_slice(sls_id, hard_reboot = false) # PUT /slices/id/reboot.xml action = hard_reboot ? :hard_reboot : :reboot req = generate_request(Net::HTTP::Put, build_path(:slices, sls_id, action)) request_info(req, RightHttp2xxParser.new) rescue on_exception end |
#rebuild_slice(sls_id, params) ⇒ Object
Rebuild a slice.
sl.rebuild_slice(26831, :image_id => 3) #=> true
276 277 278 279 280 281 282 |
# File 'lib/right_slicehost.rb', line 276 def rebuild_slice(sls_id, params) # PUT /slices/id/rebuild.xml?params req = generate_request(Net::HTTP::Put, build_path(:slices, sls_id, :rebuild), params) request_info(req, RightHttp2xxParser.new) rescue on_exception end |
#update_record(sls_id, params = {}) ⇒ Object
Update a record.
sl.update_record(348257, :ttl => 777, :data=>"oops.my-domain.com") #=> true
423 424 425 426 427 428 429 |
# File 'lib/right_slicehost.rb', line 423 def update_record(sls_id, params={}) params[:active] = (params[:active] ? 'Y' : 'N') unless params[:active].nil? # PUT /zones/id.xml req = generate_request(Net::HTTP::Put, build_path(:records, sls_id)) req[:request].body = build_xml(:record, params) request_info(req, RightHttp2xxParser.new(:logger => @logger)) end |
#update_slice(sls_id, params = {}) ⇒ Object
Update a slice.
sl.update_slice(26831, :name => 'my-awesome-slice') #=> true
265 266 267 268 269 270 |
# File 'lib/right_slicehost.rb', line 265 def update_slice(sls_id, params={}) # PUT /slices/id.xml req = generate_request(Net::HTTP::Put, build_path(:slices, sls_id)) req[:request].body = build_xml(:slice, params) request_info(req, RightHttp2xxParser.new(:logger => @logger)) end |
#update_zone(sls_id, params = {}) ⇒ Object
Update a zone.
sl.update_zone(45486, :acive => false, :ttl => 333) #=> true
355 356 357 358 359 360 361 |
# File 'lib/right_slicehost.rb', line 355 def update_zone(sls_id, params={}) params[:active] = (params[:active] ? 'Y' : 'N') unless params[:active].nil? # PUT /zones/id.xml req = generate_request(Net::HTTP::Put, build_path(:zones, sls_id)) req[:request].body = build_xml(:zone, params) request_info(req, RightHttp2xxParser.new(:logger => @logger)) end |