1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/linode/requests/compute/avail_stackscripts.rb
2012-05-17 11:31:15 -07:00

63 lines
2 KiB
Ruby

module Fog
module Compute
class Linode
class Real
def avail_stackscripts(options={})
result = request(
:expects => 200,
:method => 'GET',
:query => { :api_action => 'avail.stackscripts' }.merge!(options)
)
result.body['DATA'].each { |r| r['DISTRIBUTIONIDLIST'] = r['DISTRIBUTIONIDLIST'].to_s }
result
end
end
class Mock
def avail_stackscripts(stackscript_id=nil)
response = Excon::Response.new
response.status = 200
body = {
"ERRORARRAY" => [],
"ACTION" => "avail.stackscripts"
}
if stackscript_id
mock_stackscript = create_mock_stackscript(stackscript_id)
response.body = body.merge("DATA" => [mock_stackscript])
else
mock_stackscripts = []
10.times do
stackscript_id = rand(1..200)
mock_stackscripts << create_mock_stackscript(stackscript_id)
end
response.body = body.merge("DATA" => mock_stackscripts)
end
response
end
private
def create_mock_stackscript(stackscript_id)
{
"CREATE_DT" => "2011-10-07 00:28:13.0",
"DEPLOYMENTSACTIVE" => 0,
"DEPLOYMENTSTOTAL" => 1,
"DESCRIPTION" => "Prints 'foobar' to the screen. Magic!",
"DISTRIBUTIONIDLIST" => "77,78,64,65,82,83,50,51,73,74,41,42",
"ISPUBLIC" => 1,
"LABEL" => "foobar",
"LATESTREV" => 15149,
"REV_DT" => "2011-10-07 00:33:58.0",
"REV_NOTE" => "Updated update_rubygems_install function.",
"SCRIPT" => "#!/bin/bash\n#\n#\n\necho \"foobar\"",
"STACKSCRIPTID" => stackscript_id,
"USERID" => 1
}
end
end
end
end
end