Class: Runcible::Resources::Content

Inherits:
Base
  • Object
show all
Defined in:
lib/runcible/resources/content.rb

Overview

Instance Attribute Summary

Attributes inherited from Base

#logs

Instance Method Summary collapse

Methods inherited from Base

#add_http_auth_header, #add_oauth_header, #call, #combine_get_params, #config, #exception_to_log, #format_payload_json, #generate_payload, #get_response, #initialize, #lazy_config=, #log_debug, #log_exception, #log_info, #logger, #path, #process_response, #required_params

Constructor Details

This class inherits a constructor from Runcible::Base

Instance Method Details

#create_upload_requestRestClient::Response

Creates an Upload Request

Request Body Contents: None

Returns:

  • (RestClient::Response)

    Pulp returns the upload_id which is used for subsequent operations



19
20
21
# File 'lib/runcible/resources/content.rb', line 19

def create_upload_request
  call(:post, upload_path)
end

#delete_upload_request(upload_id) ⇒ RestClient::Response

Delete an upload request

Query Parameters: None

Parameters:

  • upload_id (String)

    the id of the upload_request returned by create_upload_request

Returns:

  • (RestClient::Response)

    none



53
54
55
# File 'lib/runcible/resources/content.rb', line 53

def delete_upload_request(upload_id)
  call(:delete, upload_path("#{upload_id}/"))
end

#import_into_repo(repo_id, unit_type_id, upload_id, unit_key, optional = {}) ⇒ RestClient::Response

Import into a repository

Parameters:

  • repo_id (String)

    identifies the associated repository

  • unit_type_id (String)

    identifies the type of unit the upload represents

  • upload_id (String)

    the id of the upload_request returned by create_upload_request

  • unit_key (Object)

    unique identifier for the new unit; the contents are contingent on the type of unit being uploaded

  • optional (Hash) (defaults to: {})

    container for all optional parameters

Returns:

  • (RestClient::Response)

    none



42
43
44
45
46
# File 'lib/runcible/resources/content.rb', line 42

def import_into_repo(repo_id, unit_type_id, upload_id, unit_key, optional = {})
  required = required_params(binding.send(:local_variables), binding)
  call(:post, Repository.path("#{repo_id}/actions/import_upload/"),
                              :payload => { :required => required, :optional => optional })
end

#list_all_requestsRestClient::Response

List all upload requests

Query Parameters: None

Returns:

  • (RestClient::Response)

    the list of IDs for all upload requests on the server; empty list if there are none



62
63
64
# File 'lib/runcible/resources/content.rb', line 62

def list_all_requests
  call(:get, upload_path)
end

#list_orphans(type_id = nil) ⇒ Object

List all orphaned content optionally by type

Parameters:

  • type_id (defaults to: nil)

    content unit type (rpm, puppet_module, etc.)

Returns:

  • list of orphaned content



80
81
82
# File 'lib/runcible/resources/content.rb', line 80

def list_orphans(type_id = nil)
  call(:get, orphan_path(type_id))
end

#orphan_path(type_id = nil) ⇒ String

Generates an api path for orphaned content

Parameters:

  • type_id (String) (defaults to: nil)

    the type id of the orphaned content

Returns:

  • (String)

    the content path, may contain the type_id if passed



70
71
72
73
74
# File 'lib/runcible/resources/content.rb', line 70

def orphan_path(type_id = nil)
  path = 'content/orphans/'
  path << "#{type_id}/" if type_id
  path
end

#remove_orphans(type_id = nil) ⇒ Object

Delete all orphaned content optionally by type

Parameters:

  • type_id (defaults to: nil)

    content unit type (rpm, puppet_module, etc.)

Returns:

  • list of orphaned content



88
89
90
# File 'lib/runcible/resources/content.rb', line 88

def remove_orphans(type_id = nil)
  call(:delete, orphan_path(type_id))
end

#upload_bits(upload_id, offset, content) ⇒ RestClient::Response

Upload bits

Parameters:

  • upload_id (String)

    the id of the upload_request returned by create_upload_request

  • offset (Numeric)

    offset for file assembly

  • content (File)

    content of the file being uploaded to the server

Returns:

  • (RestClient::Response)

    none



29
30
31
# File 'lib/runcible/resources/content.rb', line 29

def upload_bits(upload_id, offset, content)
  call(:put, upload_path("#{upload_id}/#{offset}/"), :payload => content, :no_log_payload => true)
end

#upload_path(upload_id = nil) ⇒ String

Generates the API path for Contents

Parameters:

  • upload_id (String) (defaults to: nil)

    the id of the upload_request

Returns:

  • (String)

    the content path, may contain the upload_id if passed



11
12
13
# File 'lib/runcible/resources/content.rb', line 11

def upload_path(upload_id = nil)
  upload_id.nil? ? 'content/uploads/' : "content/uploads/#{upload_id}/"
end