class GPUEater::APIv1
Public Class Methods
new()
click to toggle source
# File lib/gpueater.rb, line 10 def initialize @debug = false @base = 'https://www.gpueater.com' if ENV['GPUEATER_URL'] @base = ENV['GPUEATER_URL'] end @homedir = File.expand_path('~') @tmpdir = Dir.tmpdir @cookie_path = File.join(@tmpdir,"gpueater_cookie.txt") @g_config = {} @g_header = {'User-Agent':'RubyAPI'} @conn = Faraday::Connection.new(:url => @base) do |builder| builder.use Faraday::Request::UrlEncoded # builder.use Faraday::Response::Logger builder.use Faraday::Adapter::NetHttpPersistent # gem install net-http-persistent builder.options[:timeout] = 1800 end @alist=["raccoon", "dog", "wild boar", "rabbit", "cow", "horse", "wolf", "hippopotamus", "kangaroo", "fox", "giraffe", "bear", "koala", "bat", "gorilla", "rhinoceros", "monkey", "deer", "zebra", "jaguar", "polar bear", "skunk", "elephant", "raccoon dog", "animal", "reindeer", "rat", "tiger", "cat", "mouse", "buffalo", "hamster", "panda", "sheep", "leopard", "pig", "mole", "goat", "lion", "camel", "squirrel", "donkey"] @blist=["happy", "glad", "comfortable", "pleased", "delighted", "relieved", "calm", "surprised", "exciting"] begin @g_config = JSON.load(open(".eater").read) rescue begin @g_config = JSON.load(open(File.join(@homedir,".eater")).read) rescue puts "You have to define to ~/.eater" exit(9) end end begin @g_header['cookie'] = open(@cookie_path).read rescue => e end end
Public Instance Methods
__________________________()
click to toggle source
# File lib/gpueater.rb, line 267 def __________________________;end
___________image___________()
click to toggle source
def func_post_launch(api,required_fields=[],form={}, e=nil, try=2)
raise e if try <= 0 tag = form['tag'] unless tag form['tag'] = @alist[((rand()*100) % @alist.length).to_i] +"-"+@blist[((rand()*100) % @blist.length).to_i] end required_fields.each{|v| raise "Required field => #{v}" unless form.include?(v) } image = form['image'] ssh_key_id = form['ssh_key_id'] product_id = form['product_id'] unless image.kind_of?(String) end j = nil begin j = JSON.load(_post(api,form).body) rescue => e relogin return func_post(api, required_fields, form, e, try-1) end raise j['error'] if j['error'] j['data']
end
# File lib/gpueater.rb, line 185 def ___________image___________;end
___________instance___________()
click to toggle source
# File lib/gpueater.rb, line 204 def ___________instance___________;end
___________ssh_key___________()
click to toggle source
# File lib/gpueater.rb, line 198 def ___________ssh_key___________;end
__________network__________()
click to toggle source
# File lib/gpueater.rb, line 219 def __________network__________;end
__________storage__________()
click to toggle source
# File lib/gpueater.rb, line 228 def __________storage__________;end
_________extensions__________()
click to toggle source
# File lib/gpueater.rb, line 257 def _________extensions__________;end
_________payment__________()
click to toggle source
# File lib/gpueater.rb, line 248 def _________payment__________;end
_________special__________()
click to toggle source
# File lib/gpueater.rb, line 244 def _________special__________;end
_________subscription__________()
click to toggle source
# File lib/gpueater.rb, line 233 def _________subscription__________;end
_get(u,q={})
click to toggle source
def clear_cache
puts @cookie_path File.delete(@cookie_path)
end
# File lib/gpueater.rb, line 55 def _get(u,q={}) puts u if @debug response = @conn.get do |req| req.url u req.params = q @g_header.each{|k,v| if v req.headers[k] = v end } end return response end
_post(u,form)
click to toggle source
# File lib/gpueater.rb, line 69 def _post(u,form) puts u if @debug response = @conn.post do |req| req.url u @g_header.each{|k,v| if v req.headers[k] = v end } req.body = form end return response end
cancel_transaction()
click to toggle source
# File lib/gpueater.rb, line 246 def cancel_transaction; raise "Not implemented yet"; end
change_instance_tag(form)
click to toggle source
# File lib/gpueater.rb, line 210 def change_instance_tag(form); func_post('/console/servers/change_instance_tag',['instance_id','tag'],form); end
change_snapshot_tag(form)
click to toggle source
# File lib/gpueater.rb, line 189 def change_snapshot_tag(form); func_post('/console/servers/change_snapshot_tag',['snapshot_id','tag'],form); end
close_port(form)
click to toggle source
# File lib/gpueater.rb, line 222 def close_port(form); func_post('/console/servers/delete_port',['instance_id','connection_id','port'],form); end
copy_file()
click to toggle source
# File lib/gpueater.rb, line 258 def copy_file; raise "Not implemented yet"; end
create_image(form)
click to toggle source
# File lib/gpueater.rb, line 193 def create_image(form); func_post('/console/servers/create_user_defined_image',['instance_id','image_name'],form); end
create_volume()
click to toggle source
# File lib/gpueater.rb, line 229 def create_volume; raise "Not implemented yet"; end
delete_file()
click to toggle source
# File lib/gpueater.rb, line 259 def delete_file; raise "Not implemented yet"; end
delete_image(form)
click to toggle source
# File lib/gpueater.rb, line 194 def delete_image(form); func_post('/console/servers/delete_user_defined_image',['fingerprint'],form); end
delete_snapshot(form)
click to toggle source
# File lib/gpueater.rb, line 190 def delete_snapshot(form); func_post('/console/servers/delete_snapshot',['snapshot_id'],form); end
delete_ssh_key(form)
click to toggle source
# File lib/gpueater.rb, line 202 def delete_ssh_key(form); func_post('/console/servers/delete_ssh_key',['id'],form); end
delete_volume()
click to toggle source
# File lib/gpueater.rb, line 230 def delete_volume; raise "Not implemented yet"; end
emergency_restart_instance(form)
click to toggle source
# File lib/gpueater.rb, line 216 def emergency_restart_instance(form); func_post_inss('/console/servers/emergency_restart',['instance_id','machine_resource_id'],form); end
file_list()
click to toggle source
# File lib/gpueater.rb, line 262 def file_list; raise "Not implemented yet"; end
func_get(api,required_fields=[],query={}, e=nil, try=2)
click to toggle source
# File lib/gpueater.rb, line 118 def func_get(api,required_fields=[],query={}, e=nil, try=2) raise e if try <= 0 required_fields.each{|v| raise "Required field => #{v}" unless query.include?(v) } j = nil begin j = JSON.load(_get(api,query).body) rescue => e relogin return func_get(api, required_fields, query, e, try-1) end raise j['error'] if j['error'] j['data'] end
func_post(api,required_fields=[],form={}, e=nil, try=2)
click to toggle source
# File lib/gpueater.rb, line 132 def func_post(api,required_fields=[],form={}, e=nil, try=2) raise e if try <= 0 required_fields.each{|v| raise "Required field => #{v}" unless form.include?(v) } j = nil begin j = JSON.load(_post(api,form).body) rescue => e relogin return func_post(api, required_fields, form, e, try-1) end raise j['error'] if j['error'] j['data'] end
func_post_inss(api,required_fields=[],form={}, e=nil, try=2)
click to toggle source
# File lib/gpueater.rb, line 146 def func_post_inss(api,required_fields=[],form={}, e=nil, try=2) raise e if try <= 0 required_fields.each{|v| raise "Required field => #{v}" unless form.include?(v) } form["instances"] = [{"instance_id"=>form["instance_id"],"machine_resource_id"=>form["machine_resource_id"]}].to_json; j = nil begin j = JSON.load(_post(api,form).body) rescue => e relogin return func_post(api, required_fields, form, e, try-1) end raise j['error'] if j['error'] j['data'] end
generate_ssh_key()
click to toggle source
# File lib/gpueater.rb, line 200 def generate_ssh_key; func_get('/console/servers/ssh_key_gen'); end
image_list()
click to toggle source
# File lib/gpueater.rb, line 186 def image_list; func_get('/console/servers/images'); end
import_image(form)
click to toggle source
# File lib/gpueater.rb, line 195 def import_image(form); func_post('/console/servers/import_image',['url','image_name'],form); end
instance_list()
click to toggle source
# File lib/gpueater.rb, line 209 def instance_list; func_get('/console/servers/instance_list'); end
invoice_list()
click to toggle source
# File lib/gpueater.rb, line 249 def invoice_list; func_get('/console/servers/charge_list'); end
launch_ondemand_instance(form)
click to toggle source
# File lib/gpueater.rb, line 207 def launch_ondemand_instance(form); func_post('/console/servers/launch_ondemand_instance',['product_id','image','ssh_key_id','tag'],form); end
launch_subcription_instance(form)
click to toggle source
# File lib/gpueater.rb, line 208 def launch_subcription_instance(form); raise "Not implemented yet"; end
live_migration()
click to toggle source
# File lib/gpueater.rb, line 245 def live_migration; raise "Not implemented yet"; end
login_instance()
click to toggle source
# File lib/gpueater.rb, line 264 def login_instance; raise "Not implemented yet"; end
make_directory()
click to toggle source
# File lib/gpueater.rb, line 261 def make_directory; raise "Not implemented yet"; end
make_invoice()
click to toggle source
# File lib/gpueater.rb, line 251 def make_invoice; raise "Not implemented yet"; end
move_file()
click to toggle source
# File lib/gpueater.rb, line 260 def move_file; raise "Not implemented yet"; end
network_description(form)
click to toggle source
# File lib/gpueater.rb, line 225 def network_description(form); func_get('/console/servers/instance_info',['instance_id'],form); end
ondemand_list()
click to toggle source
# File lib/gpueater.rb, line 205 def ondemand_list; ProductsResnpose.new(func_get('/console/servers/ondemand_launch_list')); end
open_port(form)
click to toggle source
# File lib/gpueater.rb, line 221 def open_port(form); func_post('/console/servers/add_port',['instance_id','connection_id','port'],form); end
payment_test()
click to toggle source
# File lib/gpueater.rb, line 253 def payment_test puts invoice_list end
port_list(form)
click to toggle source
# File lib/gpueater.rb, line 220 def port_list(form); func_get('/console/servers/port_list',['instance_id'],form); end
refresh_ipv4(form)
click to toggle source
# File lib/gpueater.rb, line 224 def refresh_ipv4(form); func_post('/console/servers/refresh_ipv4',['instance_id'],form); end
register_ssh_key(form)
click to toggle source
# File lib/gpueater.rb, line 201 def register_ssh_key(form); func_post('/console/servers/register_ssh_key',['name','public_key'],form); end
registered_image_list()
click to toggle source
# File lib/gpueater.rb, line 192 def registered_image_list; func_get('/console/servers/registered_image_list'); end
relogin()
click to toggle source
# File lib/gpueater.rb, line 83 def relogin res = _post('/api_login',{'email':@g_config['gpueater']['email'],'password':@g_config['gpueater']['password']}) if res.headers['set-cookie'] @g_header['cookie'] = res.headers['set-cookie'] f = open(@cookie_path,"w") f.write(@g_header['cookie']) f.close end end
renew_ipv4(form)
click to toggle source
# File lib/gpueater.rb, line 223 def renew_ipv4(form); func_post('/console/servers/renew_ipv4',['instance_id'],form); end
restart_instance(form)
click to toggle source
# File lib/gpueater.rb, line 214 def restart_instance(form); func_post_inss('/console/servers/stop',['instance_id','machine_resource_id'],form); func_post_inss('/console/servers/start',['instance_id','machine_resource_id'],form); end
snapshot_list()
click to toggle source
# File lib/gpueater.rb, line 187 def snapshot_list; func_get('/console/servers/snapshots'); end
ssh_key_list()
click to toggle source
# File lib/gpueater.rb, line 199 def ssh_key_list; func_get('/console/servers/ssh_keys'); end
start_instance(form)
click to toggle source
# File lib/gpueater.rb, line 212 def start_instance(form); func_post_inss('/console/servers/start',['instance_id','machine_resource_id'],form); end
stop_instance(form)
click to toggle source
# File lib/gpueater.rb, line 213 def stop_instance(form); func_post_inss('/console/servers/stop',['instance_id','machine_resource_id'],form); end
subscribe_instance()
click to toggle source
# File lib/gpueater.rb, line 237 def subscribe_instance; raise "Not implemented yet"; end
subscribe_network()
click to toggle source
# File lib/gpueater.rb, line 241 def subscribe_network; raise "Not implemented yet"; end
subscribe_storage()
click to toggle source
# File lib/gpueater.rb, line 239 def subscribe_storage; raise "Not implemented yet"; end
subscription_instance_list()
click to toggle source
# File lib/gpueater.rb, line 234 def subscription_instance_list; raise "Not implemented yet"; end
subscription_invoice_list()
click to toggle source
# File lib/gpueater.rb, line 250 def subscription_invoice_list; raise "Not implemented yet"; end
subscription_list()
click to toggle source
# File lib/gpueater.rb, line 206 def subscription_list; raise "Not implemented yet"; end
subscription_network_list()
click to toggle source
# File lib/gpueater.rb, line 236 def subscription_network_list; raise "Not implemented yet"; end
subscription_storage_list()
click to toggle source
# File lib/gpueater.rb, line 235 def subscription_storage_list; raise "Not implemented yet"; end
synchronize_files()
click to toggle source
# File lib/gpueater.rb, line 263 def synchronize_files; raise "Not implemented yet"; end
take_snapshot(form)
click to toggle source
# File lib/gpueater.rb, line 188 def take_snapshot(form); func_post('/console/servers/take_snapshot',['instance_id','tag'],form); end
terminate_instance(form)
click to toggle source
# File lib/gpueater.rb, line 215 def terminate_instance(form); func_post_inss('/console/servers/force_terminate',['instance_id','machine_resource_id'],form); end
transfer_volume()
click to toggle source
# File lib/gpueater.rb, line 231 def transfer_volume; raise "Not implemented yet"; end
tunnel()
click to toggle source
# File lib/gpueater.rb, line 265 def tunnel; raise "Not implemented yet"; end
unsubscribe_instance()
click to toggle source
# File lib/gpueater.rb, line 238 def unsubscribe_instance; raise "Not implemented yet"; end
unsubscribe_network()
click to toggle source
# File lib/gpueater.rb, line 242 def unsubscribe_network; raise "Not implemented yet"; end
unsubscribe_storage()
click to toggle source
# File lib/gpueater.rb, line 240 def unsubscribe_storage; raise "Not implemented yet"; end