Class: Morpheus::InstancesInterface
- Inherits:
-
APIClient
- Object
- APIClient
- Morpheus::InstancesInterface
- Defined in:
- lib/morpheus/api/instances_interface.rb
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) ⇒ 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.
- #restart(id, server = true) ⇒ Object
- #security_groups(id) ⇒ Object
- #start(id, server = true) ⇒ Object
- #stop(id, server = true) ⇒ Object
- #workflow(id, task_set_id, payload) ⇒ Object
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
138 139 140 141 142 143 144 145 146 |
# File 'lib/morpheus/api/instances_interface.rb', line 138 def apply_security_groups(id, ) url = "#{@base_url}/api/instances/#{id}/security-groups" headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } payload = puts "payload #{payload}" 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 |
#backup(id, server = true) ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/morpheus/api/instances_interface.rb', line 106 def backup(id,server=true) url = "#{@base_url}/api/instances/#{id}/backup" headers = {:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } response = Morpheus::RestClient.execute(method: :put, url: url, timeout: 30, headers: 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() url = "#{@base_url}/api/instances" headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } payload = 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 |
#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, ) url = "#{@base_url}/api/instances/#{id}/envs" headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } payload = {envs: } 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 |
#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}" headers = { :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 |
#destroy(id) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/morpheus/api/instances_interface.rb', line 66 def destroy(id) url = "#{@base_url}/api/instances/#{id}" headers = { :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 |
#firewall_disable(id) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/morpheus/api/instances_interface.rb', line 114 def firewall_disable(id) url = "#{@base_url}/api/instances/#{id}/security-groups/disable" headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } response = Morpheus::RestClient.execute(method: :put, url: url, timeout: 30, headers: headers,verify_ssl: false) JSON.parse(response.to_s) end |
#firewall_enable(id) ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/morpheus/api/instances_interface.rb', line 122 def firewall_enable(id) url = "#{@base_url}/api/instances/#{id}/security-groups/enable" headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } response = Morpheus::RestClient.execute(method: :put, 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/instances_interface.rb', line 12 def get(=nil) url = "#{@base_url}/api/instances" headers = { params: {}, authorization: "Bearer #{@access_token}" } if .is_a?(Hash) headers[:params].merge!() elsif .is_a?(Numeric) url = "#{@base_url}/api/instances/#{}" elsif .is_a?(String) headers[:params]['name'] = end response = Morpheus::RestClient.execute(method: :get, url: url, timeout: 30, headers: 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, =nil) url = "#{@base_url}/api/instances/#{id}/envs" headers = { params: {}, authorization: "Bearer #{@access_token}" } response = Morpheus::RestClient.execute(method: :get, url: url, timeout: 30, headers: headers,verify_ssl: false) 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" headers = { :params => {:server => server},:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } response = Morpheus::RestClient.execute(method: :put, url: url, timeout: 30, headers: headers,verify_ssl: false) JSON.parse(response.to_s) end |
#security_groups(id) ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/morpheus/api/instances_interface.rb', line 130 def security_groups(id) url = "#{@base_url}/api/instances/#{id}/security-groups" headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } response = Morpheus::RestClient.execute(method: :get, url: url, timeout: 30, headers: 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" headers = { :params => {:server => server}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } response = Morpheus::RestClient.execute(method: :put, url: url, timeout: 30, headers: 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" headers = { :params => {:server => server}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } response = Morpheus::RestClient.execute(method: :put, url: url, timeout: 30, headers: headers,verify_ssl: false) JSON.parse(response.to_s) end |
#workflow(id, task_set_id, payload) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/morpheus/api/instances_interface.rb', line 98 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' } 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 |