Class: Morpheus::DeployInterface

Inherits:
APIClient show all
Defined in:
lib/morpheus/api/deploy_interface.rb

Instance Method Summary collapse

Methods inherited from APIClient

#accounts, #app_templates, #apps, #archive_buckets, #archive_files, #auth, #clouds, #containers, #custom_instance_types, #dashboard, #deployments, #dry, #dry_run, #execute, #groups, #image_builder, #instance_types, #instances, #key_pairs, #license, #load_balancers, #logs, #monitoring, #option_type_lists, #option_types, #options, #provision_types, #roles, #security_group_rules, #security_groups, #servers, #set_ssl_verification_enabled, #setup, #ssl_verification_enabled?, #task_sets, #tasks, #users, #virtual_images, #whoami

Constructor Details

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

Returns a new instance of DeployInterface.



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

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



27
28
29
30
31
32
# File 'lib/morpheus/api/deploy_interface.rb', line 27

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

#deploy(id, options) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/morpheus/api/deploy_interface.rb', line 65

def deploy(id, options)
  url = "#{@base_url}/api/deploy/#{id}/deploy"
  payload = options
  if !options[:appDeploy].nil?
    if !options[:appDeploy][:config].nil?
      options[:appDeploy][:config] = options[:appDeploy][:config].to_json
    end
  end
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  execute(method: :post, url: url, headers: headers, timeout: nil, payload: payload.to_json)
end

#destroy(id) ⇒ Object



59
60
61
62
63
# File 'lib/morpheus/api/deploy_interface.rb', line 59

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

#get(instanceId, options = nil) ⇒ Object



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

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

  if options.is_a?(Hash)
    headers[:params].merge!(options)
  elsif options.is_a?(String)
    headers[:params]['name'] = options
  end
  execute(method: :get, url: url, headers: headers)
end

#list_files(id) ⇒ Object



34
35
36
37
38
39
# File 'lib/morpheus/api/deploy_interface.rb', line 34

def list_files(id)
  url = "#{@base_url}/api/deploy/#{id}/files"
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  payload = options
  execute(method: :get, url: url, headers: headers)
end

#upload_file(id, path, destination = nil) ⇒ Object

todo: use execute() to support @dry_run?



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/morpheus/api/deploy_interface.rb', line 42

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