Class Rightscale::FlexiscaleApi
In: lib/api/right_flexiscale_api.rb
Parent: Object

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.

Methods

Constants

FLEXISCALE_WSDL = "https://api.flexiscale.com/current/Flexiscale.wsdl"
SERVER_STOP_SHUTDOWN = 1
SERVER_STOP_POWEROFF = 2
DEFAULT_HTTP_CONNECT_TIMEOUT = 60
DEFAULT_HTTP_RECEIVE_TIMEOUT = 300

Attributes

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

Public Class methods

Create a new interface to Flexiscale API. If username or/and password are undefined then ENV[‘FLEXISCALE_USERNAME’] and ENV[‘FLEXISCALE_PASSWORD’] 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">]

Public Instance methods

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

Destroy a server. Returns true if OK.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[Validate]