Class: Morpheus::DeployInterface
- Inherits:
-
APIClient
- Object
- APIClient
- Morpheus::DeployInterface
- Defined in:
- lib/morpheus/api/deploy_interface.rb
Instance Method Summary collapse
- #create(instanceId, options = nil) ⇒ Object
- #deploy(id, options) ⇒ Object
- #destroy(id) ⇒ Object
- #get(instanceId, options = nil) ⇒ Object
-
#initialize(access_token, refresh_token, expires_at = nil, base_url = nil) ⇒ DeployInterface
constructor
A new instance of DeployInterface.
- #list_files(id) ⇒ Object
- #upload_file(id, path, destination = nil) ⇒ Object
Constructor Details
#initialize(access_token, refresh_token, expires_at = nil, base_url = nil) ⇒ DeployInterface
Returns a new instance of DeployInterface.
7 8 9 10 11 12 |
# File 'lib/morpheus/api/deploy_interface.rb', line 7 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
#create(instanceId, options = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/morpheus/api/deploy_interface.rb', line 30 def create(instanceId, =nil) url = "#{@base_url}/api/instances/#{instanceId}/deploy" headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } payload = || {} response = Morpheus::RestClient.execute(method: :post, url: url, timeout: 30, headers: headers, payload: payload.to_json) JSON.parse(response.to_s) end |
#deploy(id, options) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/morpheus/api/deploy_interface.rb', line 76 def deploy(id, ) url = "#{@base_url}/api/deploy/#{id}/deploy" payload = if ![:appDeploy].nil? if ![:appDeploy][:config].nil? [:appDeploy][:config] = [:appDeploy][:config].to_json end end headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } response = Morpheus::RestClient.execute(method: :post, url: url, headers: headers, timeout: nil, payload: payload.to_json) JSON.parse(response.to_s) end |
#destroy(id) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/morpheus/api/deploy_interface.rb', line 68 def destroy(id) url = "#{@base_url}/api/deploy/#{id}" headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } response = Morpheus::RestClient.execute(method: :delete, url: url, timeout: 30, headers: headers) JSON.parse(response.to_s) end |
#get(instanceId, options = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/morpheus/api/deploy_interface.rb', line 15 def get(instanceId, =nil) url = "#{@base_url}/api/instances/#{instanceId}/deploy" headers = { params: {}, authorization: "Bearer #{@access_token}" } if .is_a?(Hash) headers[:params].merge!() elsif .is_a?(String) headers[:params]['name'] = end response = Morpheus::RestClient.execute(method: :get, url: url, timeout: 30, headers: headers) JSON.parse(response.to_s) end |
#list_files(id) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/morpheus/api/deploy_interface.rb', line 40 def list_files(id) url = "#{@base_url}/api/deploy/#{id}/files" headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } payload = response = Morpheus::RestClient.execute(method: :get, url: url, timeout: 30, headers: headers) JSON.parse(response.to_s) end |
#upload_file(id, path, destination = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/morpheus/api/deploy_interface.rb', line 50 def upload_file(id,path,destination=nil) url_string = "#{@base_url}/api/deploy/#{id}/files" if !destination.empty? url_string += "/#{destination}" end url = URI.parse(url_string) req = Net::HTTP::Post::Multipart.new url.path, "file" => UploadIO.new(File.new(path,'rb'), "image/jpeg", File.basename(path)) req['Authorization'] = "Bearer #{@access_token}" res = Net::HTTP.start(url.host, url.port) do |http| http.request(req) end res end |