Skip to content

Commit

Permalink
Move tasks status blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
nledez committed Aug 28, 2013
1 parent 49caea1 commit 22d67cd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 52 deletions.
24 changes: 12 additions & 12 deletions lib/proxmox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ def initialize(pve_cluster, node, username, password, realm)
end
end

def task_status(upid)
@site["nodes/#{@node}/tasks/#{URI::encode upid}/status"].get @auth_params do |response, request, result, &block|
status = JSON.parse(response.body)['data']['status']
exitstatus = JSON.parse(response.body)['data']['exitstatus']
if exitstatus
"#{status}:#{exitstatus}"
else
"#{status}"
end
end
end

def templates
@site["nodes/#{@node}/storage/local/content"].get @auth_params do |response, request, result, &block|
template_list = Hash.new
Expand Down Expand Up @@ -107,17 +119,5 @@ def openvz_vm_shutdown(vmid)
JSON.parse(response.body)['data']
end
end

def task_status(upid)
@site["nodes/#{@node}/tasks/#{URI::encode upid}/status"].get @auth_params do |response, request, result, &block|
status = JSON.parse(response.body)['data']['status']
exitstatus = JSON.parse(response.body)['data']['exitstatus']
if exitstatus
"#{status}:#{exitstatus}"
else
"#{status}"
end
end
end
end
end
80 changes: 40 additions & 40 deletions spec/lib/proxmox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,46 @@
server2.status.should == "error"
end

it "should get task status" do
# Status done
stub_request(:get, "http://localhost:8006/api2/json/nodes/localhost/tasks/UPID:localhost:00051DA0:119EAABB:521CCB19:vzcreate:200:root@pam:/status").with(
:headers => {
'User-Agent' => 'Ruby',
'Cookie' => /.*/,
'Csrfpreventiontoken' => /.*/
}
).to_return(
:status => 200,
:headers => {
:connection => "close",
:server => "pve-api-daemon/3.0",
:content_type => "application/json;charset=UTF-8",
},
:body => '{"data":{"exitstatus":"OK","status":"stopped","upid":"UPID:localhost:00051DA0:119EAABB:521CCB19:vzcreate:200:root@pam:","node":"localhost","pid":335264,"starttime":1377618713,"user":"root@pam","type":"vzcreate","id":"200","pstart":295611067}}'
)

# Status running
stub_request(:get, "http://localhost:8006/api2/json/nodes/localhost/tasks/UPID:localhost:00055DDA:11A99D07:521CE71F:vzcreate:200:root@pam:/status").with(
:headers => {
'User-Agent' => 'Ruby',
'Cookie' => /.*/,
'Csrfpreventiontoken' => /.*/
}
).to_return(
:status => 200,
:headers => {
:connection => "close",
:server => "pve-api-daemon/3.0",
:content_type => "application/json;charset=UTF-8",
},
:body => '{"data":{"status":"running","upid":"UPID:localhost:00055DDA:11A99D07:521CE71F:vzcreate:200:root@pam:","node":"localhost","pid":351706,"starttime":1377625887,"user":"root@pam","type":"vzcreate","id":"200","pstart":296328455}}'
)

# Get status
@server1.task_status("UPID:localhost:00051DA0:119EAABB:521CCB19:vzcreate:200:root@pam:").should be_eql "stopped:OK"
@server1.task_status("UPID:localhost:00055DDA:11A99D07:521CE71F:vzcreate:200:root@pam:").should be_eql "running"
end

it "should get template list" do
# First template list
stub_request(:get, "http://localhost:8006/api2/json/nodes/localhost/storage/local/content").with(
Expand Down Expand Up @@ -200,46 +240,6 @@
@server1.openvz_delete(201).should be_eql 'NOK: error code = 500'
end

it "should get task status" do
# Status done
stub_request(:get, "http://localhost:8006/api2/json/nodes/localhost/tasks/UPID:localhost:00051DA0:119EAABB:521CCB19:vzcreate:200:root@pam:/status").with(
:headers => {
'User-Agent' => 'Ruby',
'Cookie' => /.*/,
'Csrfpreventiontoken' => /.*/
}
).to_return(
:status => 200,
:headers => {
:connection => "close",
:server => "pve-api-daemon/3.0",
:content_type => "application/json;charset=UTF-8",
},
:body => '{"data":{"exitstatus":"OK","status":"stopped","upid":"UPID:localhost:00051DA0:119EAABB:521CCB19:vzcreate:200:root@pam:","node":"localhost","pid":335264,"starttime":1377618713,"user":"root@pam","type":"vzcreate","id":"200","pstart":295611067}}'
)

# Status running
stub_request(:get, "http://localhost:8006/api2/json/nodes/localhost/tasks/UPID:localhost:00055DDA:11A99D07:521CE71F:vzcreate:200:root@pam:/status").with(
:headers => {
'User-Agent' => 'Ruby',
'Cookie' => /.*/,
'Csrfpreventiontoken' => /.*/
}
).to_return(
:status => 200,
:headers => {
:connection => "close",
:server => "pve-api-daemon/3.0",
:content_type => "application/json;charset=UTF-8",
},
:body => '{"data":{"status":"running","upid":"UPID:localhost:00055DDA:11A99D07:521CE71F:vzcreate:200:root@pam:","node":"localhost","pid":351706,"starttime":1377625887,"user":"root@pam","type":"vzcreate","id":"200","pstart":296328455}}'
)

# Get status
@server1.task_status("UPID:localhost:00051DA0:119EAABB:521CCB19:vzcreate:200:root@pam:").should be_eql "stopped:OK"
@server1.task_status("UPID:localhost:00055DDA:11A99D07:521CE71F:vzcreate:200:root@pam:").should be_eql "running"
end

it "should get container status" do
# VM Status
stub_request(:get, "http://localhost:8006/api2/json/nodes/localhost/openvz/200/status/current").with(
Expand Down

0 comments on commit 22d67cd

Please sign in to comment.