Class: Morpheus::ServersInterface

Inherits:
APIClient
  • Object
show all
Defined in:
lib/morpheus/api/servers_interface.rb

Instance Method Summary collapse

Methods inherited from APIClient

#accounts, #app_templates, #apps, #clouds, #deploy, #deployments, #groups, #instance_types, #instances, #key_pairs, #license, #load_balancers, #logs, #options, #provision_types, #roles, #security_group_rules, #security_groups, #servers, #task_sets, #tasks, #users, #virtual_images

Constructor Details

#initialize(access_token, refresh_token, expires_at = nil, base_url = nil) ⇒ ServersInterface

Returns a new instance of ServersInterface.



5
6
7
8
9
10
# File 'lib/morpheus/api/servers_interface.rb', line 5

def initialize(access_token, refresh_token,expires_at = nil, base_url=nil) 
	@access_token = access_token
	@refresh_token = refresh_token
	@base_url = base_url
	@expires_at = expires_at
end

Instance Method Details

#assign_account(serverId, payload = {}) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/morpheus/api/servers_interface.rb', line 87

def (serverId,payload = {})
	url = "#{@base_url}/api/servers/#{serverId}/assign-account"
	headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
	response = Morpheus::RestClient.execute(method: :put, url: url,
                           timeout: 30, headers: headers, verify_ssl:false, payload: payload.to_json)
	JSON.parse(response.to_s)
end

#create(options) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/morpheus/api/servers_interface.rb', line 29

def create(options)
	url = "#{@base_url}/api/servers"
	headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
	
	payload = options
	response = Morpheus::RestClient.execute(method: :post, url: url,
                           timeout: 30, headers: headers, verify_ssl:false, payload: payload.to_json)
	JSON.parse(response.to_s)
end

#destroy(id, params = {}) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/morpheus/api/servers_interface.rb', line 103

def destroy(id, params={})
	url = "#{@base_url}/api/servers/#{id}"
	headers = { :params => params,:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
	response = Morpheus::RestClient.execute(method: :delete, url: url,
                           timeout: 30, headers: headers, verify_ssl:false)
	JSON.parse(response.to_s)
end

#get(options = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/morpheus/api/servers_interface.rb', line 12

def get(options=nil)
	url = "#{@base_url}/api/servers"
	headers = { params: {}, authorization: "Bearer #{@access_token}" }

	if options.is_a?(Hash)
		headers[:params].merge!(options)
	elsif options.is_a?(Numeric)
		url = "#{@base_url}/api/servers/#{options}"
	elsif options.is_a?(String)
		headers[:params]['name'] = options
	end
	response = Morpheus::RestClient.execute(method: :get, url: url,
                           timeout: 30, headers: headers, verify_ssl:false)
	JSON.parse(response.to_s)
end

#install_agent(serverId, payload = {}) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/morpheus/api/servers_interface.rb', line 55

def install_agent(serverId,payload = {})
	url = "#{@base_url}/api/servers/#{serverId}/install-agent"
	headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
	response = Morpheus::RestClient.execute(method: :put, url: url,
                           timeout: 30, headers: headers, verify_ssl:false, payload: payload.to_json)
	JSON.parse(response.to_s)
end

#reinitialize(serverId, payload = {}) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/morpheus/api/servers_interface.rb', line 79

def reinitialize(serverId,payload = {})
	url = "#{@base_url}/api/servers/#{serverId}/reinitialize"
	headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
	response = Morpheus::RestClient.execute(method: :put, url: url,
                           timeout: 30, headers: headers, verify_ssl:false, payload: payload.to_json)
	JSON.parse(response.to_s)
end

#reprovision(serverId, payload = {}) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/morpheus/api/servers_interface.rb', line 71

def reprovision(serverId,payload = {})
	url = "#{@base_url}/api/servers/#{serverId}/reprovision"
	headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
	response = Morpheus::RestClient.execute(method: :put, url: url,
                           timeout: 30, headers: headers, verify_ssl:false, payload: payload.to_json)
	JSON.parse(response.to_s)
end

#start(serverId, payload = {}) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/morpheus/api/servers_interface.rb', line 47

def start(serverId,payload = {})
	url = "#{@base_url}/api/servers/#{serverId}/start"
	headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
	response = Morpheus::RestClient.execute(method: :put, url: url,
                           timeout: 30, headers: headers, verify_ssl:false, payload: payload.to_json)
	JSON.parse(response.to_s)
end

#stop(serverId, payload = {}) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/morpheus/api/servers_interface.rb', line 39

def stop(serverId,payload = {})
	url = "#{@base_url}/api/servers/#{serverId}/stop"
	headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
	response = Morpheus::RestClient.execute(method: :put, url: url,
                           timeout: 30, headers: headers, verify_ssl:false, payload: payload.to_json)
	JSON.parse(response.to_s)
end

#upgrade(serverId, payload = {}) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/morpheus/api/servers_interface.rb', line 63

def upgrade(serverId,payload = {})
	url = "#{@base_url}/api/servers/#{serverId}/upgrade"
	headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
	response = Morpheus::RestClient.execute(method: :put, url: url,
                           timeout: 30, headers: headers, verify_ssl:false, payload: payload.to_json)
	JSON.parse(response.to_s)
end

#workflow(id, task_set_id, payload) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/morpheus/api/servers_interface.rb', line 95

def workflow(id,task_set_id,payload)
	url = "#{@base_url}/api/servers/#{id}/workflow"
	headers = { :params => {:taskSetId => task_set_id},:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
	response = Morpheus::RestClient.execute(method: :put, url: url,
                           timeout: 30, headers: headers,verify_ssl: false,payload: payload.to_json)
	JSON.parse(response.to_s)
end