Class: Runcible::Extensions::Unit

Inherits:
Resources::Unit show all
Defined in:
lib/runcible/extensions/unit.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resources::Unit

#path, #search

Methods inherited from Base

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

Constructor Details

This class inherits a constructor from Runcible::Base

Class Method Details

.content_typeObject

The content type (e.g. rpm, errata)



28
29
30
# File 'lib/runcible/extensions/unit.rb', line 28

def self.content_type
  fail 'Content type not defined'
end

Instance Method Details

#allRestClient::Response

Retrieves all content of a certain @@type

Returns:

  • (RestClient::Response)

    list of all content for the given type



39
40
41
# File 'lib/runcible/extensions/unit.rb', line 39

def all
  search(content_type, {})
end

#content_typeObject



32
33
34
# File 'lib/runcible/extensions/unit.rb', line 32

def content_type
  self.class.content_type
end

#copy(source_repo_id, destination_repo_id, optional = {}) ⇒ RestClient::Response

copy contents from source repo to the destination repo

Parameters:

  • source_repo_id (String)

    the source repository ID

  • destination_repo_id (String)

    the destination repository ID

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

    container for all optional parameters

Returns:

  • (RestClient::Response)

    a task representing the unit copy operation



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/runcible/extensions/unit.rb', line 123

def copy(source_repo_id, destination_repo_id, optional = {})
  criteria = {:type_ids => [content_type], :filters => {}}
  criteria[:filters]['association'] = {'unit_id' => {'$in' => optional[:ids]}} if optional[:ids]
  criteria[:filters] = optional[:filters] if optional[:filters]
  criteria[:fields] = {:unit => optional[:fields]} if optional[:fields]

  payload = {:criteria => criteria}
  payload[:override_config] = optional[:override_config] if optional.key?(:override_config)

  if optional[:copy_children]
    payload[:override_config] ||= {}
    payload[:override_config][:recursive] = true
  end

  Runcible::Extensions::Repository.new(self.config).unit_copy(destination_repo_id, source_repo_id, payload)
end

#find(id, optional = {}) ⇒ RestClient::Response

Retrieves a single content by it’s content ID

Parameters:

  • id (Array)

    the content ID of the content to retrieve

Returns:

  • (RestClient::Response)

    the requested content



47
48
49
50
# File 'lib/runcible/extensions/unit.rb', line 47

def find(id, optional = {})
  optional[:include_repos] ||= true
  find_all([id], optional).first
end

#find_all(ids, optional = {}) ⇒ RestClient::Response

Retrieves a set of content by the contents IDs

Parameters:

  • ids (Array)

    list of content IDs to retrieve

Returns:

  • (RestClient::Response)

    list of content



56
57
58
59
# File 'lib/runcible/extensions/unit.rb', line 56

def find_all(ids, optional = {})
  optional[:include_repos] ||= true
  search(content_type, { :filters => {'id' => {'$in' => ids}} }, optional)
end

#find_all_by_unit_ids(ids, fields = [], optional = {}) ⇒ RestClient::Response

Retrieves a set of content by the Pulp unit IDs

Parameters:

  • ids (Array)

    list of content unit IDs to retrieve

  • fields (Array) (defaults to: [])

    optional list of to retrieve

Returns:

  • (RestClient::Response)

    list of content



75
76
77
78
79
80
# File 'lib/runcible/extensions/unit.rb', line 75

def find_all_by_unit_ids(ids, fields = [], optional = {})
  optional[:include_repos] ||= true
  criteria = { :filters => { :_id => { '$in' => ids } } }
  criteria[:fields] = fields unless fields.empty?
  search(content_type, criteria, optional)
end

#find_by_unit_id(id, optional = {}) ⇒ RestClient::Response

Retrieves a single content by it’s unit ID

Parameters:

  • id (Array)

    the unit ID of the content to retrieve

Returns:

  • (RestClient::Response)

    the requested content



65
66
67
68
# File 'lib/runcible/extensions/unit.rb', line 65

def find_by_unit_id(id, optional = {})
  optional[:include_repos] ||= true
  find_all_by_unit_ids([id], [], optional).first
end

#unassociate_from_repo(repo_id, filters) ⇒ RestClient::Response

unassociates content units from a repository

Parameters:

  • repo_id (String)

    the repository ID to remove units from

  • filters (Hash)

    the filters to find the units this content type to remove

Returns:

  • (RestClient::Response)

    a task representing the unit unassociate operation



87
88
89
90
91
# File 'lib/runcible/extensions/unit.rb', line 87

def unassociate_from_repo(repo_id, filters)
  criteria = {:type_ids => [content_type]}
  criteria[:filters] = filters
  Runcible::Extensions::Repository.new(self.config).unassociate_units(repo_id, criteria)
end

#unassociate_ids_from_repo(repo_id, ids) ⇒ RestClient::Response

unassociates content units from a repository

Parameters:

  • repo_id (String)

    the repository ID to remove units from

  • ids (Array)

    list of content unit ids of this content type, aka metadata id or content id

    ex: "RHEA-2010:0001" for errata..,
    Note rpms do not have ids, so cant use this.
    

Returns:

  • (RestClient::Response)

    a task representing the unit unassociate operation



101
102
103
# File 'lib/runcible/extensions/unit.rb', line 101

def unassociate_ids_from_repo(repo_id, ids)
  unassociate_from_repo(repo_id, :unit => {'id' => {'$in' => ids}})
end

#unassociate_unit_ids_from_repo(repo_id, ids) ⇒ RestClient::Response

unassociates content units from a repository

Parameters:

  • repo_id (String)

    the repository ID to remove units from

  • ids (Array)

    list of the unique hash ids of the content unit with respect to this repo. unit_id, id are other names for this. for example: “efdd2d63-b275-4728-a298-f68cf4c174e7”

Returns:

  • (RestClient::Response)

    a task representing the unit unassociate operation



113
114
115
# File 'lib/runcible/extensions/unit.rb', line 113

def unassociate_unit_ids_from_repo(repo_id, ids)
  unassociate_from_repo(repo_id, :association => {'unit_id' => {'$in' => ids}})
end