Class: Morpheus::InstancesInterface

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

Instance Method Summary collapse

Methods inherited from APIClient

#account_groups, #accounts, #app_templates, #apps, #archive_buckets, #archive_files, #auth, #blueprints, #cloud_datastores, #cloud_policies, #clouds, #custom_instance_types, #cypher, #dashboard, #deploy, #deployments, #dry, #dry_run, #execute, #execute_schedules, #execution_request, #file_copy_request, #group_policies, #groups, #image_builder, #instance_types, #instances, #key_pairs, #library_container_scripts, #library_container_templates, #library_container_types, #library_container_upgrades, #library_instance_types, #library_layouts, #license, #load_balancers, #logs, #monitoring, #network_domains, #network_groups, #network_pool_servers, #network_pools, #network_proxies, #network_services, #networks, #option_type_lists, #option_types, #options, #packages, #policies, #power_schedules, #processes, #provision_types, #roles, #security_group_rules, #servers, #set_ssl_verification_enabled, #setup, #ssl_verification_enabled?, #storage_providers, #task_sets, #tasks, #user_groups, #user_settings, #user_sources, #users, #virtual_images, #whoami

Constructor Details

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

Returns a new instance of InstancesInterface.



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

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

#action(id, action_code, payload = {}) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/morpheus/api/instances_interface.rb', line 124

def action(id, action_code, payload={})
  url, params = "", {}
  if id.is_a?(Array)
    url = "#{@base_url}/api/instances/action"
    params = {ids: id, code: action_code}
  else
    url = "#{@base_url}/api/instances/#{id}/action"
    params = {code: action_code}
  end
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
  execute(opts)
end

#apply_security_groups(id, options) ⇒ Object



202
203
204
205
206
207
208
# File 'lib/morpheus/api/instances_interface.rb', line 202

def apply_security_groups(id, options)
  url = "#{@base_url}/api/instances/#{id}/security-groups"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  payload = options
  opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
  execute(opts)
end

#available_actions(id) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/morpheus/api/instances_interface.rb', line 110

def available_actions(id)
  url, params = "", {}
  if id.is_a?(Array)
    url = "#{@base_url}/api/instances/actions"
    params = {ids: id}
  else
    url = "#{@base_url}/api/instances/#{id}/actions"
    params = {}
  end
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :get, url: url, headers: headers}
  execute(opts)
end

#backup(id, server = true) ⇒ Object



159
160
161
162
163
164
# File 'lib/morpheus/api/instances_interface.rb', line 159

def backup(id,server=true)
  url = "#{@base_url}/api/instances/#{id}/backup"
  headers = {:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :put, url: url, headers: headers}
  execute(opts)
end

#backups(id, params) ⇒ Object



166
167
168
169
170
171
# File 'lib/morpheus/api/instances_interface.rb', line 166

def backups(id, params)
  url = "#{@base_url}/api/instances/#{id}/backups"
  headers = { params: params, authorization: "Bearer #{@access_token}" }
  opts = {method: :get, url: url, headers: headers}
  execute(opts)
end

#clone(id, options) ⇒ Object



173
174
175
176
177
178
179
# File 'lib/morpheus/api/instances_interface.rb', line 173

def clone(id, options)
  url = "#{@base_url}/api/instances/#{id}/clone"
  headers = {:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  payload = options
  opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
  execute(opts)
end

#containers(instance_id, params = {}) ⇒ Object



223
224
225
226
227
228
# File 'lib/morpheus/api/instances_interface.rb', line 223

def containers(instance_id, params={})
  url = "#{@base_url}/api/instances/#{instance_id}/containers"
  headers = { params: params, authorization: "Bearer #{@access_token}" }
  opts = {method: :get, url: url, headers: headers}
  execute(opts)
end

#create(options) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/morpheus/api/instances_interface.rb', line 52

def create(options)
  url = "#{@base_url}/api/instances"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  payload = options
  opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
  execute(opts)
end

#create_env(id, options) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/morpheus/api/instances_interface.rb', line 37

def create_env(id, options)
  url = "#{@base_url}/api/instances/#{id}/envs"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  payload = options
  opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
  execute(opts)
end

#del_env(id, name) ⇒ Object



45
46
47
48
49
50
# File 'lib/morpheus/api/instances_interface.rb', line 45

def del_env(id, name)
  url = "#{@base_url}/api/instances/#{id}/envs/#{name}"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :delete, url: url, headers: headers}
  execute(opts)
end

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



68
69
70
71
72
73
# File 'lib/morpheus/api/instances_interface.rb', line 68

def destroy(id, params = {})
  url = "#{@base_url}/api/instances/#{id}"
  headers = {:params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :delete, url: url, headers: headers}
  execute(opts)
end

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



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

def eject(id, params={})
  url = "#{@base_url}/api/instances/#{id}/eject"
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :put, url: url, headers: headers}
  execute(opts)
end

#firewall_disable(id) ⇒ Object



181
182
183
184
185
186
# File 'lib/morpheus/api/instances_interface.rb', line 181

def firewall_disable(id)
  url = "#{@base_url}/api/instances/#{id}/security-groups/disable"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :put, url: url, headers: headers}
  execute(opts)
end

#firewall_enable(id) ⇒ Object



188
189
190
191
192
193
# File 'lib/morpheus/api/instances_interface.rb', line 188

def firewall_enable(id)
  url = "#{@base_url}/api/instances/#{id}/security-groups/enable"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :put, url: url, headers: headers}
  execute(opts)
end

#get(options = nil) ⇒ Object



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

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

  if options.is_a?(Hash)
    headers[:params].merge!(options)
  elsif options.is_a?(Numeric)
    url = "#{@base_url}/api/instances/#{options}"
  elsif options.is_a?(String)
    headers[:params]['name'] = options
  end
  opts = {method: :get, url: url, headers: headers}
  execute(opts)
end

#get_envs(id, options = nil) ⇒ Object



30
31
32
33
34
35
# File 'lib/morpheus/api/instances_interface.rb', line 30

def get_envs(id, options=nil)
  url = "#{@base_url}/api/instances/#{id}/envs"
  headers = { params: {}, authorization: "Bearer #{@access_token}" }
  opts = {method: :get, url: url, headers: headers}
  execute(opts)
end

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



265
266
267
268
269
270
# File 'lib/morpheus/api/instances_interface.rb', line 265

def history(id, params={})
  url = "#{@base_url}/api/instances/#{id}/history"
  headers = { params: params, authorization: "Bearer #{@access_token}" }
  opts = {method: :get, url: url, headers: headers}
  execute(opts)
end

#history_details(id, process_id, params = {}) ⇒ Object



272
273
274
275
276
277
# File 'lib/morpheus/api/instances_interface.rb', line 272

def history_details(id, process_id, params={})
  url = "#{@base_url}/api/instances/#{id}/history/#{process_id}"
  headers = { params: params, authorization: "Bearer #{@access_token}" }
  opts = {method: :get, url: url, headers: headers}
  execute(opts)
end

#history_event_details(id, process_event_id, params = {}) ⇒ Object



279
280
281
282
283
284
# File 'lib/morpheus/api/instances_interface.rb', line 279

def history_event_details(id, process_event_id, params={})
  url = "#{@base_url}/api/instances/#{id}/history/events/#{process_event_id}"
  headers = { params: params, authorization: "Bearer #{@access_token}" }
  opts = {method: :get, url: url, headers: headers}
  execute(opts)
end

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



209
210
211
212
213
214
# File 'lib/morpheus/api/instances_interface.rb', line 209

def import_snapshot(id, params={})
  url = "#{@base_url}/api/instances/#{id}/import-snapshot"
  headers = {:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :put, url: url, headers: headers}
  execute(opts)
end

#list(options = {}) ⇒ Object



26
27
28
# File 'lib/morpheus/api/instances_interface.rb', line 26

def list(options={})
  get(options)
end

#remove_load_balancer(id, payload = {}) ⇒ Object



251
252
253
254
255
256
# File 'lib/morpheus/api/instances_interface.rb', line 251

def remove_load_balancer(id, payload={})
  url = "#{@base_url}/api/instances/#{id}/load-balancer"
  headers = {authorization: "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :delete, url: url, headers: headers, payload: payload.to_json}
  execute(opts)
end

#resize(id, payload) ⇒ Object



145
146
147
148
149
150
# File 'lib/morpheus/api/instances_interface.rb', line 145

def resize(id,payload)
  url = "#{@base_url}/api/instances/#{id}/resize"
  headers = { :params => {},:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :put, url: url, headers: headers,payload: payload.to_json}
  execute(opts)
end

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



89
90
91
92
93
94
# File 'lib/morpheus/api/instances_interface.rb', line 89

def restart(id, params={})
  url = "#{@base_url}/api/instances/#{id}/restart"
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :put, url: url, headers: headers}
  execute(opts)
end

#security_groups(id) ⇒ Object



195
196
197
198
199
200
# File 'lib/morpheus/api/instances_interface.rb', line 195

def security_groups(id)
  url = "#{@base_url}/api/instances/#{id}/security-groups"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :get, url: url, headers: headers}
  execute(opts)
end

#service_plans(params) ⇒ Object



216
217
218
219
220
221
# File 'lib/morpheus/api/instances_interface.rb', line 216

def service_plans(params)
  url = "#{@base_url}/api/instances/service-plans"
  headers = { params: params, authorization: "Bearer #{@access_token}" }
  opts = {method: :get, url: url, headers: headers}
  execute(opts)
end

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



82
83
84
85
86
87
# File 'lib/morpheus/api/instances_interface.rb', line 82

def start(id, params={})
  url = "#{@base_url}/api/instances/#{id}/start"
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :put, url: url, headers: headers}
  execute(opts)
end

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



75
76
77
78
79
80
# File 'lib/morpheus/api/instances_interface.rb', line 75

def stop(id, params={})
  url = "#{@base_url}/api/instances/#{id}/stop"
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :put, url: url, headers: headers}
  execute(opts)
end

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



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

def suspend(id, params={})
  url = "#{@base_url}/api/instances/#{id}/suspend"
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :put, url: url, headers: headers}
  execute(opts)
end

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



230
231
232
233
234
235
# File 'lib/morpheus/api/instances_interface.rb', line 230

def threshold(id, params={})
  url = "#{@base_url}/api/instances/#{id}/threshold"
  headers = { params: params, authorization: "Bearer #{@access_token}" }
  opts = {method: :get, url: url, headers: headers}
  execute(opts)
end

#update(id, options) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/morpheus/api/instances_interface.rb', line 60

def update(id, options)
  url = "#{@base_url}/api/instances/#{id}"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  payload = options
  opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
  execute(opts)
end

#update_load_balancer(id, payload) ⇒ Object



244
245
246
247
248
249
# File 'lib/morpheus/api/instances_interface.rb', line 244

def update_load_balancer(id, payload)
  url = "#{@base_url}/api/instances/#{id}/load-balancer"
  headers = {authorization: "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
  execute(opts)
end

#update_notes(id, payload) ⇒ Object



258
259
260
261
262
263
# File 'lib/morpheus/api/instances_interface.rb', line 258

def update_notes(id, payload)
  url = "#{@base_url}/api/instances/#{id}/notes"
  headers = {authorization: "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
  execute(opts)
end

#update_threshold(id, payload) ⇒ Object



237
238
239
240
241
242
# File 'lib/morpheus/api/instances_interface.rb', line 237

def update_threshold(id, payload)
  url = "#{@base_url}/api/instances/#{id}/threshold"
  headers = {authorization: "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
  execute(opts)
end

#volumes(id) ⇒ Object



138
139
140
141
142
143
# File 'lib/morpheus/api/instances_interface.rb', line 138

def volumes(id)
  url = "#{@base_url}/api/instances/#{id}/volumes"
  headers = { :params => {},:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :get, url: url, headers: headers}
  execute(opts)
end

#workflow(id, task_set_id, payload) ⇒ Object



152
153
154
155
156
157
# File 'lib/morpheus/api/instances_interface.rb', line 152

def workflow(id,task_set_id,payload)
  url = "#{@base_url}/api/instances/#{id}/workflow"
  headers = { :params => {:taskSetId => task_set_id},:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :put, url: url, headers: headers,payload: payload.to_json}
  execute(opts)
end