class Rightscale::FlexiscaleApi

Rightscale::FlexiscaleApi – RightScale Flexiscale interface

The Rightscale::FlexiscaleApi class provides a complete interface to Flexiscale's Web service. For explanations of the semantics of each call, please refer to Flexiscale's documentation at api.flexiscale.com

Examples:

flexiscale = Rightscale::FlexiscaleApi.new(username, password)

# get servers list
servers = flexiscale.list_servers

# OS images
images = flexiscale.list_operating_system_images

# create a new server
image     = flexiscale.list_operating_system_images.first
package   = flexiscale.list_packages.first
vlan      = flexiscale.list_vlans.first
server_id = flexiscale.create_server('my_awesome_server', package[:fxs_id], 1, 1024, 20, image[:fxs_id], vlan[:fxs_id])

# launch a server
job_id = flexiscale.start_server('my_awesome_server')

# reboot
job_id = flexiscale.reboot_server('my_awesome_server')

# stop and destroy server
job_id = flexiscale.stop_server('my_awesome_server')

if flexiscale.wait_for_jobs(job_id)
  flexiscale.destroy_server('my_awesome_server')
end

Error handling: all operations raise an Rightscale::FlexiscaleError in case of problems.

Constants

DEFAULT_HTTP_CONNECT_TIMEOUT
DEFAULT_HTTP_RECEIVE_TIMEOUT
FLEXISCALE_WSDL
SERVER_STOP_POWEROFF
SERVER_STOP_SHUTDOWN

Attributes

api[R]
last_raw_response[R]
logged_in[R]
params[R]
password[R]
username[R]

Public Class Methods

new(username=nil, password=nil, params={}) click to toggle source

Create a new interface to Flexiscale API. If username or/and password are undefined then ENV and ENV are used.

- params: :raw_response - return SOAP objects as is
          :logger       - logger object (STDOUT is used by default)
          :skip_logging - log nothing 

flexiscale = Rightscale::FlexiscaleApi.new(username, password)
flexiscale.list_packages #=> [{:fxs_id => 12345,
                               :name   => "package"}]

flexiscale = Rightscale::FlexiscaleApi.new(username, password, :raw_response=>true) #=> 
flexiscale.list_packages #=> [#<FlexiScale::Package:0xb78a1904
                                @package_id   = 12345,
                                @package_name = "package">]
# File lib/api/right_flexiscale_api.rb, line 222
    def initialize(username=nil, password=nil, params={})
      @username  = username || ENV['FLEXISCALE_USERNAME']
      @password  = password || ENV['FLEXISCALE_PASSWORD']
      @params    = params
      # vars initialization
      @params[:logger] ||= Logger.new(STDOUT)
      @logged_in = false
      @last_raw_response = nil
      # create a new interface
      @api = ::FlexiScale::FlexiScale.new
      @api.wiredump_dev = STDERR if $DEBUG
      # timeouts: 1 min for connection establishment and
      # 5 min for wait_for_jobs
      @api.options["protocol.http.connect_timeout"] = DEFAULT_HTTP_CONNECT_TIMEOUT
      @api.options["protocol.http.receive_timeout"] = DEFAULT_HTTP_RECEIVE_TIMEOUT
#      @api.options["protocol.http.send_timeout"]
    end

Public Instance Methods

create_server(server_name, package_id, processors, memory, disk_capacity, operating_system_image_id, vlan_id) click to toggle source

Create a server. Returns a new server_id. (Memory in MB, disk_capacity in GB)

flexiscale.create_server('my_awesome_server', 12345, 1, 512, 20, 27, 1552) #=> 1343

api.flexiscale.com/current/doc/create_server.html

# File lib/api/right_flexiscale_api.rb, line 396
def create_server(server_name, package_id, processors, memory, disk_capacity, operating_system_image_id, vlan_id)
  image  = FlexiScale::OperatingSystemImage.new(operating_system_image_id)
  server = FlexiScale::Server.new(nil, server_name, nil, package_id, processors, memory, image, disk_capacity)
  vlan   = FlexiScale::Vlan.new(vlan_id)
  perform_request do
    @api.createServer(server, vlan)
  end
end
destroy_server(server_name) click to toggle source

Destroy a server. Returns true if OK.

flexiscale.destroy_server('my_awesome_server') #=> true

api.flexiscale.com/current/doc/delete_server.html

# File lib/api/right_flexiscale_api.rb, line 498
def destroy_server(server_name)
  perform_request do
    @api.destroyServer(server_name)
  end
  true
end
filter_jobs(limit=50, order_by=:status, direction=:asc) click to toggle source

List a filtered jobs. Returns an array of jobs.

- order_by:   :status || :job_id || :type_id || :started || :finished || :description || :parent_job
- direction:  :asc || :desc

flexiscale.filter(100, :status, :desc ) #=>
      [{:fxs_status  => 2,
        :status      => "completed",
        :started_at  => Fri Jun 13 13:21:27 UTC 2008,
        :description => "start_virtual_server",
        :finished_at => Fri Jun 13 13:23:42 UTC 2008,
        :type_id     => 1322,
        :notes       => "kd-from-home-via-api",
        :fxs_id      => 10928,
        :parent_job  => 0}, ... ]

api.flexiscale.com/current/doc/filter_jobs.html

# File lib/api/right_flexiscale_api.rb, line 599
def filter_jobs(limit=50, order_by=:status, direction=:asc)
  perform_request do
    @api.filterJobs(limit, order_by.to_s, direction.to_s.upcase)
  end
end
list_credits(start_date=nil, end_date=nil) click to toggle source

List credits.

api.flexiscale.com/current/doc/list_credits.html

# File lib/api/right_flexiscale_api.rb, line 718
def list_credits(start_date=nil, end_date=nil)
  perform_request do
    @api.listCredits(start_date && start_date.to_i, end_date && end_date.to_i)
  end
end
list_debit_items(item_type, type_id, start_date=nil, end_date=nil) click to toggle source

List debit items.

- item_type:  :virtual_server || :vlan || :disk_space

flexiscale.list_debit_items(:virtual_server, 1322) #=>
      [{:description => "1 Hour of uptime for server kd test 1",
        :type_id     => 1322,
        :item_value  => 1.0,
        :item_cost   => 0.05,
        :fxs_id      => 738858,
        :debit_id    => 415192,
        :timestamp   => Fri Jun 13 16:45:04 +0400 2008,
        :item_type   => "virtual_server"}]

api.flexiscale.com/current/doc/list_debit_items.html

# File lib/api/right_flexiscale_api.rb, line 699
def list_debit_items(item_type, type_id, start_date=nil, end_date=nil)
  perform_request do
    @api.listDebitItems(item_type.to_s, type_id, 
                        start_date && start_date.to_i, end_date && end_date.to_i)
  end
end
list_debits(start_date=nil, end_date=nil) click to toggle source

List debits.

api.flexiscale.com/current/doc/list_debits.html

# File lib/api/right_flexiscale_api.rb, line 709
def list_debits(start_date=nil, end_date=nil)
  perform_request do
    @api.listDebits(start_date && start_date.to_i, end_date && end_date.to_i)
  end
end
list_disks(*list) click to toggle source

List disks. Returns an array of disks. List is an array of ids.

flexiscale.list_disks #=>
      [{:capacity   => 20,
        :server_id  => 1322,
        :usage      => 0.03,
        :name       => "Server 1322 Operating System",
        :locked     => 0,
        :package_id => 12345,
        :fxs_id     => 2262}, ... ]

api.flexiscale.com/current/doc/list_disks.html

# File lib/api/right_flexiscale_api.rb, line 522
def list_disks(*list)
  perform_request do
    @api.listDisks(list.flatten)
  end
end
list_firewall_protocols() click to toggle source

List firewall protocols.

flexiscale.list_firewall_protocols #=>
      [{:fxs_id=>0,   :name=>"Any"},
       {:fxs_id=>6,   :name=>"TCP"},
       {:fxs_id=>17,  :name=>"UDP"},
       {:fxs_id=>1,   :name=>"ICMP"},
       {:fxs_id=>41,  :name=>"GRE"},
       {:fxs_id=>50,  :name=>"IPSEC-ESP"},
       {:fxs_id=>51,  :name=>"IPSEC-AH"},
       {:fxs_id=>115, :name=>"L2TP"}]

api.flexiscale.com/current/doc/list_firewall_protocols.html

# File lib/api/right_flexiscale_api.rb, line 760
def list_firewall_protocols
  perform_request do
    @api.listFirewallProtocols
  end
end
list_firewall_rules(firewall_id, direction=nil) click to toggle source

List firewall rulles.

- direction:  nil || :in || :out

api.flexiscale.com/current/doc/list_firewall_rules.html

# File lib/api/right_flexiscale_api.rb, line 741
def list_firewall_rules(firewall_id, direction=nil)
  perform_request do
    @api.listFirewallRules(firewall_id, direction && direction.to_s.upcase)
  end
end
list_firewall_template_rules(firewall_template_id, direction=nil) click to toggle source

List firewall template rules.

- direction:  nil || :in || :out

api.flexiscale.com/current/doc/list_firewall_template_rules.html

# File lib/api/right_flexiscale_api.rb, line 811
def list_firewall_template_rules(firewall_template_id, direction=nil)
  perform_request do
    @api.listFirewallTemplateRules(firewall_template_id, direction && direction.to_s.upcase)
  end
end
list_firewall_templates(*list) click to toggle source

List firewall templates.

flexiscale.list_firewall_templates #=>
      [{:fxs_id=>1, :name=>"Linux Web Server",   :default_policy=>"REJECT"},
       {:fxs_id=>2, :name=>"Windows Web Server", :default_policy=>"REJECT"},
       {:fxs_id=>3, :name=>"Linux Email Server", :default_policy=>"REJECT"}]

api.flexiscale.com/current/doc/list_firewall_templates.html

# File lib/api/right_flexiscale_api.rb, line 801
def list_firewall_templates(*list)
  perform_request do
    @api.listFirewallTemplates(list.flatten)
  end
end
list_firewalls(*list) click to toggle source

List firewalls.

api.flexiscale.com/current/doc/list_firewalls.html

# File lib/api/right_flexiscale_api.rb, line 731
def list_firewalls(*list)
  perform_request do
    @api.listFirewalls(list.flatten)
  end
end
list_icmp_protocols() click to toggle source

List ICMP protocols.

flexiscale.list_icmp_protocols #=>
      [{:fxs_id=>0,  :description=>"Echo Reply"},
       {:fxs_id=>8,  :description=>"Echo"},
       {:fxs_id=>3,  :description=>"Destination Unreachable"},
       {:fxs_id=>4,  :description=>"Source Quench"},
       {:fxs_id=>5,  :description=>"Redirect"},
       {:fxs_id=>6,  :description=>"Alternate Host Address"},
       {:fxs_id=>9,  :description=>"Router Advertisement"},
       {:fxs_id=>10, :description=>"Router Solicitation"},
       {:fxs_id=>11, :description=>"Time Exceeded"},
       {:fxs_id=>12, :description=>"Parameter Problem"},
       {:fxs_id=>13, :description=>"Timestamp"},
       {:fxs_id=>14, :description=>"Timestamp Reply"},
       {:fxs_id=>15, :description=>"Information Request"},
       {:fxs_id=>16, :description=>"Information Reply"},
       {:fxs_id=>17, :description=>"Address Mask Request"},
       {:fxs_id=>18, :description=>"Address Mask Reply"}]

api.flexiscale.com/current/doc/list_icmp_protocols.html

# File lib/api/right_flexiscale_api.rb, line 787
def list_icmp_protocols
  perform_request do
    @api.listIcmpProtocols
  end
end
list_ip_blocks(*list) click to toggle source

List IpBlocks. Returns an array of ip_blocks. List is an array of ids.

flexiscale.list_ip_blocks #=>
      [{:block_type       => 29,
        :end_ip           => "92.60.120.70",
        :fxs_id           => 404,
        :customer_vlan_id => 552,
        :start_ip         => "92.60.120.60"}]

api.flexiscale.com/current/doc/list_ip_blocks.html

# File lib/api/right_flexiscale_api.rb, line 674
def list_ip_blocks(*list)
  perform_request do
    @api.listIpBlocks(list.flatten)
  end
end
list_jobs(*list) click to toggle source

List jobs. Returns an array of jobs. List is an array of ids.

flexiscale.list_jobs #=>
      [{:fxs_status  => 2,
        :status      => "completed",
        :started_at  => Fri Jun 13 13:21:27 UTC 2008,
        :description => "start_virtual_server",
        :finished_at => Fri Jun 13 13:23:42 UTC 2008,
        :type_id     => 1322,
        :notes       => "kd-from-home-via-api",
        :fxs_id      => 10928,
        :parent_job  => 0}, ... ]

api.flexiscale.com/current/doc/list_jobs.html

# File lib/api/right_flexiscale_api.rb, line 547
def list_jobs(*list)
  perform_request do
    @api.ListJobs(list.flatten)
  end
end
list_network_interfaces(*list) click to toggle source

List network interfaces. Returns an array of nics. List is an array of ids.

flexiscale.list_network_interfaces #=>
      [{:server_id   => 1322,
        :fxs_id      => 749,
        :vlan_id     => 552,
        :mac_address => "00:0f:4b:22:cb:0c"}, ... ]

api.flexiscale.com/current/doc/list_nics.html

# File lib/api/right_flexiscale_api.rb, line 643
def list_network_interfaces(*list)
  perform_request do
    @api.listNetworkInterfaces(list.flatten)
  end
end
list_operating_system_images() click to toggle source

List available operating system images.

flexiscale.list_operating_system_images #=>
      [{:fxs_id=>1,  :name=>"Centos 5"},
       {:fxs_id=>3,  :name=>"Centos 4"},
       {:fxs_id=>4,  :name=>"Windows Server 2003 Standard"},
       {:fxs_id=>6,  :name=>"Debian 4.0 (Etch)"},
       {:fxs_id=>15, :name=>"Centos 5 64 Bit"},
       {:fxs_id=>16, :name=>"Ubuntu 6.06 LTS"},
       {:fxs_id=>17, :name=>"Windows Server 2003 Standard 64 Bit"},
       {:fxs_id=>18, :name=>"Debian 4.0 64 Bit (Etch)"},
       {:fxs_id=>27, :name=>"Ubuntu 8.04 LTS"}]

api.flexiscale.com/current/doc/list_operating_system_images.html

# File lib/api/right_flexiscale_api.rb, line 623
def list_operating_system_images
  perform_request do
    @api.listOperatingSystemImages
  end
end
list_packages(*list) click to toggle source

List packages. Returns an array of packages. List is an array of ids.

flexiscale.list_packages #=> 
     [{:fxs_id => 12345, 
       :name   => "package"}]

api.flexiscale.com/current/doc/list_packages.html

# File lib/api/right_flexiscale_api.rb, line 352
def list_packages(*list)
  perform_request do
    @api.listPackages(list.flatten)
  end
end
list_running_jobs() click to toggle source

List running jobs. Returns an array of running jobs. List is an array of ids.

flexiscale.list_running_jobs #=> []

api.flexiscale.com/current/doc/list_running_jobs.html

# File lib/api/right_flexiscale_api.rb, line 559
def list_running_jobs
  perform_request do
    @api.listRunningJobs
  end
end
list_servers(*list) click to toggle source

List servers. Returns an array of servers. List is an array of servers names.

flexiscale.list_servers #=>
     [{:memory             => 512,
       :processors         => 1,
       :fxs_id             => 1343,
       :image_id           => 27,
       :image_name         => "Ubuntu 8.04 LTS", 
       :initial_password   => "0000000000000000\n",
       :name               => "my_awesome_server",
       :uptime             => 0,
       :modified           => false,
       :status             => "stopped"
       :fxs_status         => "5",
       :package_id         => 12345,
       :disks              => [2285],
       :disk_capacity      => 20480,
       :ip_addresses       => ["92.60.121.68"],
       :network_interfaces => [778]}, ... ]

api.flexiscale.com/current/doc/list_servers.html

# File lib/api/right_flexiscale_api.rb, line 384
def list_servers(*list)
  perform_request do
    @api.listServers(list.flatten)
  end
end
list_vlans(*list) click to toggle source

List vlans. Returns an array of vlans. List is an array of ids.

flexiscale.list_vlans #=>
      [{:fxs_id => 552, 
        :name   => "Cust15608VLAN1"}]

api.flexiscale.com/current/doc/list_servers.html

# File lib/api/right_flexiscale_api.rb, line 657
def list_vlans(*list)
  perform_request do
    @api.listVlans(list.flatten)
  end
end
login(username=nil, password=nil) click to toggle source

Loging into the API. Returns true on success. If username and/or password are not specified then previously defined values are used.

api.flexiscale.com/current/doc/login.html

# File lib/api/right_flexiscale_api.rb, line 325
def login(username=nil, password=nil)
  @logged_in = false
  @username  = username if username
  @password  = password if password
  # without a block perform_request just logs in
  perform_request
  true
end
logout() click to toggle source

Logout of the API.

api.flexiscale.com/current/doc/login.html

# File lib/api/right_flexiscale_api.rb, line 337
def logout
  @logged_in = false
  perform_request(:no_login=>true) do
    @api.logout
  end
end
modify_server(server_id, processors, memory) click to toggle source

Modify server params. Returns a modified server data. Note: a #stop_start_server request will need to be sent after the modification have been made which will reboot the server and apply the changes

flexiscale.modify_server(1343, 1, 1024) #=>
      {:memory             => 1024,
       :processors         => 1,
       :fxs_id             => 1343,
       :image_id           => 27,
       :image_name         => "Ubuntu 8.04 LTS", 
       :initial_password   => "0000000000000000\n",
       :name               => "my_awesome_server",
       :uptime             => 0,
       :modified           => false,
       :status             => "stopped"
       :fxs_status         => "5",
       :package_id         => 12345,
       :disks              => [2285],
       :disk_capacity      => 20480,
       :ip_addresses       => ["92.60.121.68"],
       :network_interfaces => [778]}

api.flexiscale.com/current/doc/modify_server.html

# File lib/api/right_flexiscale_api.rb, line 428
def modify_server(server_id, processors, memory)
  server = FlexiScale::Server.new(server_id, nil, nil, nil, processors, memory)
  perform_request do
    @api.modifyServer(server)
  end
end
reboot_server(server_name, notes='') click to toggle source

Reboot a server. The response is returned as a integer which is the job number of the request, this can be looked up using wait_for_jobs and list_jobs.

flexiscale.reboot_server('my_awesome_server') #=> 11035

api.flexiscale.com/current/doc/reboot_server.html

# File lib/api/right_flexiscale_api.rb, line 455
def reboot_server(server_name, notes='')
  perform_request do
    @api.rebootServer(server_name, notes)
  end
end
start_server(server_name, notes='') click to toggle source

Start a server. The response is returned as a integer which is the job number of the request, this can be looked up using wait_for_jobs and list_jobs.

flexiscale.start_server('my_awesome_server') #=> 11034

api.flexiscale.com/current/doc/start_server.html

# File lib/api/right_flexiscale_api.rb, line 442
def start_server(server_name, notes='')
  perform_request do
    @api.startServer(server_name, notes)
  end
end
stop_server(server_name, method=:shutdown, notes='') click to toggle source

Stop a server. The response is returned as a integer which is the job number of the request, this can be looked up using wait_for_jobs and list_jobs.

- method:  (:shutdown || Rightscale::FlexiscaleApi::SERVER_STOP_SHUTDOWN) ||
           (:poweroff || Rightscale::FlexiscaleApi::SERVER_STOP_POWEROFF)

flexiscale.stop_server('my_awesome_server') #=> 11036

api.flexiscale.com/current/doc/stop_server.html

# File lib/api/right_flexiscale_api.rb, line 471
def stop_server(server_name, method=:shutdown, notes='')
  perform_request do
    case method.to_s
    when 'shutdown', SERVER_STOP_SHUTDOWN.to_s then @api.stopServer(server_name, SERVER_STOP_SHUTDOWN, notes)
    when 'poweroff', SERVER_STOP_POWEROFF.to_s then @api.stopServer(server_name, SERVER_STOP_POWEROFF, notes)
    end
  end
end
stop_start_server(server_name, notes='') click to toggle source

Stop and Restart an existing server. The response is returned as a integer which is the job number of the request, this can be looked up using wait_for_jobs and list_jobs.

flexiscale.stop_start_server('my_awesome_server') #=> 11037

api.flexiscale.com/current/doc/stop_start_server.html

# File lib/api/right_flexiscale_api.rb, line 487
def stop_start_server(server_name, notes='')
  perform_request do
    @api.stopStartServer(server_name, notes)
  end
end
wait_for_jobs(*list) click to toggle source

Wait for jobs completion. The command returns a boolean value, if true all jobs have been completed successfully, if false one or more jobs failed. List is an array of ids.

flexiscale.wait_for_jobs(1132, 1133) #=> true

For a long wait tasks you may need to increase @api.options. The default value is DEFAULT_HTTP_RECEIVE_TIMEOUT

api.flexiscale.com/current/doc/wait_for_jobs.html

# File lib/api/right_flexiscale_api.rb, line 577
def wait_for_jobs(*list)
  perform_request do
    @api.wait_for_jobs(list.flatten)
  end
end