Class: Morpheus::InstancesInterface
Instance Method Summary
collapse
-
#apply_security_groups(id, options) ⇒ Object
-
#backup(id, server = true) ⇒ Object
-
#create(options) ⇒ Object
-
#create_env(id, options) ⇒ Object
-
#del_env(id, name) ⇒ Object
-
#destroy(id, params = {}) ⇒ Object
-
#firewall_disable(id) ⇒ Object
-
#firewall_enable(id) ⇒ Object
-
#get(options = nil) ⇒ Object
-
#get_envs(id, options = nil) ⇒ Object
-
#initialize(access_token, refresh_token, expires_at = nil, base_url = nil) ⇒ InstancesInterface
constructor
A new instance of InstancesInterface.
-
#resize(id, payload) ⇒ Object
-
#restart(id, server = true) ⇒ Object
-
#security_groups(id) ⇒ Object
-
#start(id, server = true) ⇒ Object
-
#stop(id, server = true) ⇒ Object
-
#volumes(id) ⇒ Object
-
#workflow(id, task_set_id, payload) ⇒ Object
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, #servers, #task_sets, #tasks, #users, #virtual_images
Constructor Details
#initialize(access_token, refresh_token, expires_at = nil, base_url = nil) ⇒ InstancesInterface
Returns a new instance of InstancesInterface.
5
6
7
8
9
10
|
# File 'lib/morpheus/api/instances_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
#apply_security_groups(id, options) ⇒ Object
154
155
156
157
158
159
160
161
162
|
# File 'lib/morpheus/api/instances_interface.rb', line 154
def apply_security_groups(id, options)
url = "#{@base_url}/api/instances/#{id}/security-groups"
= { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
payload = options
puts "payload #{payload}"
response = Morpheus::RestClient.execute(method: :post, url: url,
timeout: 30, headers: ,verify_ssl: false, payload: payload.to_json)
JSON.parse(response.to_s)
end
|
#backup(id, server = true) ⇒ Object
122
123
124
125
126
127
128
|
# File 'lib/morpheus/api/instances_interface.rb', line 122
def backup(id,server=true)
url = "#{@base_url}/api/instances/#{id}/backup"
= {:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
response = Morpheus::RestClient.execute(method: :put, url: url,
timeout: 30, headers: ,verify_ssl: false)
JSON.parse(response.to_s)
end
|
#create(options) ⇒ Object
56
57
58
59
60
61
62
63
64
|
# File 'lib/morpheus/api/instances_interface.rb', line 56
def create(options)
url = "#{@base_url}/api/instances"
= { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
payload = options
response = Morpheus::RestClient.execute(method: :post, url: url,
timeout: 30, headers: ,verify_ssl: false, payload: payload.to_json)
JSON.parse(response.to_s)
end
|
#create_env(id, options) ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/morpheus/api/instances_interface.rb', line 36
def create_env(id, options)
url = "#{@base_url}/api/instances/#{id}/envs"
= { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
payload = {envs: options}
response = Morpheus::RestClient.execute(method: :post, url: url,
timeout: 30, headers: ,verify_ssl: false, payload: payload.to_json)
JSON.parse(response.to_s)
end
|
#del_env(id, name) ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/morpheus/api/instances_interface.rb', line 46
def del_env(id, name)
url = "#{@base_url}/api/instances/#{id}/envs/#{name}"
= { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
response = Morpheus::RestClient.execute(method: :delete, url: url,
timeout: 30, headers: ,verify_ssl: false)
JSON.parse(response.to_s)
end
|
#destroy(id, params = {}) ⇒ Object
66
67
68
69
70
71
72
|
# File 'lib/morpheus/api/instances_interface.rb', line 66
def destroy(id, params = {})
url = "#{@base_url}/api/instances/#{id}"
= {:params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
response = Morpheus::RestClient.execute(method: :delete, url: url,
timeout: 30, headers: ,verify_ssl: false)
JSON.parse(response.to_s)
end
|
#firewall_disable(id) ⇒ Object
130
131
132
133
134
135
136
|
# File 'lib/morpheus/api/instances_interface.rb', line 130
def firewall_disable(id)
url = "#{@base_url}/api/instances/#{id}/security-groups/disable"
= { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
response = Morpheus::RestClient.execute(method: :put, url: url,
timeout: 30, headers: ,verify_ssl: false)
JSON.parse(response.to_s)
end
|
#firewall_enable(id) ⇒ Object
138
139
140
141
142
143
144
|
# File 'lib/morpheus/api/instances_interface.rb', line 138
def firewall_enable(id)
url = "#{@base_url}/api/instances/#{id}/security-groups/enable"
= { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
response = Morpheus::RestClient.execute(method: :put, url: url,
timeout: 30, 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/instances_interface.rb', line 12
def get(options=nil)
url = "#{@base_url}/api/instances"
= { params: {}, authorization: "Bearer #{@access_token}" }
if options.is_a?(Hash)
[:params].merge!(options)
elsif options.is_a?(Numeric)
url = "#{@base_url}/api/instances/#{options}"
elsif options.is_a?(String)
[:params]['name'] = options
end
response = Morpheus::RestClient.execute(method: :get, url: url,
timeout: 30, headers: ,verify_ssl: false)
JSON.parse(response.to_s)
end
|
#get_envs(id, options = nil) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/morpheus/api/instances_interface.rb', line 28
def get_envs(id, options=nil)
url = "#{@base_url}/api/instances/#{id}/envs"
= { params: {}, authorization: "Bearer #{@access_token}" }
response = Morpheus::RestClient.execute(method: :get, url: url,
timeout: 30, headers: ,verify_ssl: false)
JSON.parse(response.to_s)
end
|
#resize(id, payload) ⇒ Object
106
107
108
109
110
111
112
|
# File 'lib/morpheus/api/instances_interface.rb', line 106
def resize(id,payload)
url = "#{@base_url}/api/instances/#{id}/resize"
= { :params => {},:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
response = Morpheus::RestClient.execute(method: :put, url: url,
timeout: 30, headers: ,verify_ssl: false,payload: payload.to_json)
JSON.parse(response.to_s)
end
|
#restart(id, server = true) ⇒ Object
90
91
92
93
94
95
96
|
# File 'lib/morpheus/api/instances_interface.rb', line 90
def restart(id,server=true)
url = "#{@base_url}/api/instances/#{id}/restart"
= { :params => {:server => server},:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
response = Morpheus::RestClient.execute(method: :put, url: url,
timeout: 30, headers: ,verify_ssl: false)
JSON.parse(response.to_s)
end
|
#security_groups(id) ⇒ Object
146
147
148
149
150
151
152
|
# File 'lib/morpheus/api/instances_interface.rb', line 146
def security_groups(id)
url = "#{@base_url}/api/instances/#{id}/security-groups"
= { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
response = Morpheus::RestClient.execute(method: :get, url: url,
timeout: 30, headers: ,verify_ssl: false)
JSON.parse(response.to_s)
end
|
#start(id, server = true) ⇒ Object
82
83
84
85
86
87
88
|
# File 'lib/morpheus/api/instances_interface.rb', line 82
def start(id,server=true)
url = "#{@base_url}/api/instances/#{id}/start"
= { :params => {:server => server}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
response = Morpheus::RestClient.execute(method: :put, url: url,
timeout: 30, headers: ,verify_ssl: false)
JSON.parse(response.to_s)
end
|
#stop(id, server = true) ⇒ Object
74
75
76
77
78
79
80
|
# File 'lib/morpheus/api/instances_interface.rb', line 74
def stop(id,server=true)
url = "#{@base_url}/api/instances/#{id}/stop"
= { :params => {:server => server}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
response = Morpheus::RestClient.execute(method: :put, url: url,
timeout: 30, headers: ,verify_ssl: false)
JSON.parse(response.to_s)
end
|
#volumes(id) ⇒ Object
98
99
100
101
102
103
104
|
# File 'lib/morpheus/api/instances_interface.rb', line 98
def volumes(id)
url = "#{@base_url}/api/instances/#{id}/volumes"
= { :params => {},:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
response = Morpheus::RestClient.execute(method: :get, url: url,
timeout: 30, headers: ,verify_ssl: false)
JSON.parse(response.to_s)
end
|
#workflow(id, task_set_id, payload) ⇒ Object
114
115
116
117
118
119
120
|
# File 'lib/morpheus/api/instances_interface.rb', line 114
def workflow(id,task_set_id,payload)
url = "#{@base_url}/api/instances/#{id}/workflow"
= { :params => {:taskSetId => task_set_id},:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
response = Morpheus::RestClient.execute(method: :put, url: url,
timeout: 30, headers: ,verify_ssl: false,payload: payload.to_json)
JSON.parse(response.to_s)
end
|