class Morpheus::PackagesInterface

Public Instance Methods

destroy(id) click to toggle source
# File lib/morpheus/api/packages_interface.rb, line 70
def destroy(id)
  url = "#{@base_url}/api/packages/#{id}"
  headers = { :params => {}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :delete, url: url, headers: headers}
  execute(opts)
end
export(params, outfile) click to toggle source
# File lib/morpheus/api/packages_interface.rb, line 77
def export(params, outfile)
  url = "#{@base_url}/api/packages/export"
  headers = { params: params, authorization: "Bearer #{@access_token}" }
  opts = {method: :post, url: url, headers: headers}
  # execute(opts, {parse_json: false})
  if Dir.exist?(outfile)
    raise "outfile is invalid. It is the name of an existing directory: #{outfile}"
  end
  # if @verify_ssl == false
  #   opts[:verify_ssl] = OpenSSL::SSL::VERIFY_NONE
  # end
  if @dry_run
    return opts
  end
  http_response = nil
  bad_body = nil
  File.open(outfile, 'w') {|f|
    block = proc { |response|
      if response.code.to_i == 200
        response.read_body do |chunk|
            #puts "writing to #{outfile} ..."
            f.write chunk
        end
      else
        # puts_error (#{response.inspect}) #{chunk} ..."
        bad_body = response.body.to_s
      end
    }
    opts[:block_response] = block
    http_response = Morpheus::RestClient.execute(opts)
  }
  return http_response, bad_body
end
info(params={}) click to toggle source
# File lib/morpheus/api/packages_interface.rb, line 29
def info(params={})
  url = "#{@base_url}/api/packages/info"
  headers = { params: {}, authorization: "Bearer #{@access_token}" }
  headers[:params].merge!(params)
  opts = {method: :get, url: url, headers: headers}
  execute(opts)
end
install(params={}, payload={}) click to toggle source
# File lib/morpheus/api/packages_interface.rb, line 37
def install(params={}, payload={})
  url = "#{@base_url}/api/packages/install"
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
  execute(opts)
end
install_file(local_file, params={}) click to toggle source

def install_file(package_file, params={})

url = "#{@base_url}/api/packages/install-file"
headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/octet-stream'}
payload = package_file
execute(method: :post, url: url, headers: headers, payload: payload, timeout: 36000)

end

# File lib/morpheus/api/packages_interface.rb, line 51
def install_file(local_file, params={})
  url = "#{@base_url}/api/packages/install-file"
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/octet-stream'}
  if !local_file.kind_of?(File)
    local_file = File.new(local_file, 'rb')
  end
  payload = local_file
  headers['Content-Length'] = local_file.size # File.size(local_file)
  opts = {method: :post, url: url, headers: headers, payload: payload}
  execute(opts)
end
list(params={}) click to toggle source

def get(id)

raise "#{self.class}.get() passed a blank id!" if id.to_s == ''
url = "#{@base_url}/api/packages/#{id}"
headers = { params: {}, authorization: "Bearer #{@access_token}" }
opts = {method: :get, url: url, headers: headers}
execute(opts)

end

# File lib/morpheus/api/packages_interface.rb, line 13
def list(params={})
  url = "#{@base_url}/api/packages"
  headers = { params: {}, authorization: "Bearer #{@access_token}" }
  headers[:params].merge!(params)
  opts = {method: :get, url: url, headers: headers}
  execute(opts)
end
update(id, payload) click to toggle source
# File lib/morpheus/api/packages_interface.rb, line 63
def update(id, payload)
  url = "#{@base_url}/api/packages/update/#{id}"
  headers = { :params => {}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
  opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
  execute(opts)
end