Class | Rightscale::FlexiscaleApi |
In: |
lib/api/right_flexiscale_api.rb
|
Parent: | Object |
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.
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 |
api | [R] | |
last_raw_response | [R] | |
logged_in | [R] | |
params | [R] | |
password | [R] | |
username | [R] |
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">]
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
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}, ... ]
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"}]
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}, ... ]
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"}]
List firewall template rules.
- direction: nil || :in || :out
api.flexiscale.com/current/doc/list_firewall_template_rules.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"}]
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"}]
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"}]
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}, ... ]
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"}, ... ]
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"}]
List running jobs. Returns an array of running jobs. List is an array of ids.
flexiscale.list_running_jobs #=> []
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]}, ... ]
List vlans. Returns an array of vlans. List is an array of ids.
flexiscale.list_vlans #=> [{:fxs_id => 552, :name => "Cust15608VLAN1"}]
Loging into the API. Returns true on success. If username and/or password are not specified then previously defined values are used.
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]}
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
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
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
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
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