runcible / lib / runcible / extensions / unit.rb @ a5858c9b
1 | abc913d9 | Eric D. Helms | module Runcible |
---|---|---|---|
2 | module Extensions |
||
3 | class Unit < Runcible::Resources::Unit |
||
4 | # The content type (e.g. rpm, errata)
|
||
5 | 239e0ae8 | Eric D. Helms | def self.content_type |
6 | 3e3ad61c | Partha Aji | fail 'Content type not defined'
|
7 | 661ca339 | Justin Sherrill | end
|
8 | |||
9 | def content_type |
||
10 | self.class.content_type
|
||
11 | 239e0ae8 | Eric D. Helms | end
|
12 | abc913d9 | Eric D. Helms | |
13 | 239e0ae8 | Eric D. Helms | # Retrieves all content of a certain @@type
|
14 | abc913d9 | Eric D. Helms | #
|
15 | # @return [RestClient::Response] list of all content for the given type
|
||
16 | 661ca339 | Justin Sherrill | def all |
17 | search(content_type, {}) |
||
18 | abc913d9 | Eric D. Helms | end
|
19 | |||
20 | # Retrieves a single content by it's content ID
|
||
21 | #
|
||
22 | # @param [Array] id the content ID of the content to retrieve
|
||
23 | # @return [RestClient::Response] the requested content
|
||
24 | 3e3ad61c | Partha Aji | def find(id, optional = {}) |
25 | abc913d9 | Eric D. Helms | find_all([id], optional).first |
26 | end
|
||
27 | |||
28 | # Retrieves a set of content by the contents IDs
|
||
29 | #
|
||
30 | # @param [Array] ids list of content IDs to retrieve
|
||
31 | # @return [RestClient::Response] list of content
|
||
32 | 3e3ad61c | Partha Aji | def find_all(ids, optional = {}) |
33 | 0889fa03 | Justin Sherrill | optional[:include_repos] = optional.fetch(:include_repos, true) |
34 | 3e3ad61c | Partha Aji | search(content_type, { :filters => {'id' => {'$in' => ids}} }, optional) |
35 | abc913d9 | Eric D. Helms | end
|
36 | |||
37 | # Retrieves a single content by it's unit ID
|
||
38 | #
|
||
39 | # @param [Array] id the unit ID of the content to retrieve
|
||
40 | # @return [RestClient::Response] the requested content
|
||
41 | 3e3ad61c | Partha Aji | def find_by_unit_id(id, optional = {}) |
42 | 11cd4518 | Brad Buckingham | find_all_by_unit_ids([id], [], optional).first |
43 | abc913d9 | Eric D. Helms | end
|
44 | |||
45 | # Retrieves a set of content by the Pulp unit IDs
|
||
46 | #
|
||
47 | 11cd4518 | Brad Buckingham | # @param [Array] ids list of content unit IDs to retrieve
|
48 | # @param [Array] fields optional list of to retrieve
|
||
49 | # @return [RestClient::Response] list of content
|
||
50 | 3e3ad61c | Partha Aji | def find_all_by_unit_ids(ids, fields = [], optional = {}) |
51 | 0889fa03 | Justin Sherrill | optional[:include_repos] = optional.fetch(:include_repos, true) |
52 | 3e3ad61c | Partha Aji | criteria = { :filters => { :_id => { '$in' => ids } } } |
53 | 11cd4518 | Brad Buckingham | criteria[:fields] = fields unless fields.empty? |
54 | 661ca339 | Justin Sherrill | search(content_type, criteria, optional) |
55 | abc913d9 | Eric D. Helms | end
|
56 | |||
57 | 0e9f2f09 | Partha Aji | # unassociates content units from a repository
|
58 | #
|
||
59 | # @param [String] repo_id the repository ID to remove units from
|
||
60 | 8abf32bc | Partha Aji | # @param [Hash] filters the filters to find the units this content type to remove
|
61 | 0e9f2f09 | Partha Aji | # @return [RestClient::Response] a task representing the unit unassociate operation
|
62 | 661ca339 | Justin Sherrill | def unassociate_from_repo(repo_id, filters) |
63 | 0e9f2f09 | Partha Aji | criteria = {:type_ids => [content_type]}
|
64 | criteria[:filters] = filters
|
||
65 | 661ca339 | Justin Sherrill | Runcible::Extensions::Repository.new(self.config).unassociate_units(repo_id, criteria) |
66 | 0e9f2f09 | Partha Aji | end
|
67 | |||
68 | # unassociates content units from a repository
|
||
69 | #
|
||
70 | # @param [String] repo_id the repository ID to remove units from
|
||
71 | 2b3280f7 | Partha Aji | # @param [Array] ids list of content unit ids of this
|
72 | 8abf32bc | Partha Aji | # content type, aka metadata id or content id
|
73 | # ex: "RHEA-2010:0001" for errata..,
|
||
74 | # Note rpms do not have ids, so cant use this.
|
||
75 | 0e9f2f09 | Partha Aji | # @return [RestClient::Response] a task representing the unit unassociate operation
|
76 | 661ca339 | Justin Sherrill | def unassociate_ids_from_repo(repo_id, ids) |
77 | 2b3280f7 | Partha Aji | unassociate_from_repo(repo_id, :unit => {'id' => {'$in' => ids}}) |
78 | end
|
||
79 | |||
80 | # unassociates content units from a repository
|
||
81 | #
|
||
82 | # @param [String] repo_id the repository ID to remove units from
|
||
83 | # @param [Array] ids list of the unique hash ids of the content unit
|
||
84 | 926b9789 | Justin Sherrill | # with respect to this repo. unit_id, id are other names for this.
|
85 | 2b3280f7 | Partha Aji | # for example: "efdd2d63-b275-4728-a298-f68cf4c174e7"
|
86 | #
|
||
87 | # @return [RestClient::Response] a task representing the unit unassociate operation
|
||
88 | 661ca339 | Justin Sherrill | def unassociate_unit_ids_from_repo(repo_id, ids) |
89 | 0e9f2f09 | Partha Aji | unassociate_from_repo(repo_id, :association => {'unit_id' => {'$in' => ids}}) |
90 | end
|
||
91 | |||
92 | #copy contents from source repo to the destination repo
|
||
93 | #
|
||
94 | # @param [String] source_repo_id the source repository ID
|
||
95 | # @param [String] destination_repo_id the destination repository ID
|
||
96 | # @param [Hash] optional container for all optional parameters
|
||
97 | # @return [RestClient::Response] a task representing the unit copy operation
|
||
98 | 3e3ad61c | Partha Aji | def copy(source_repo_id, destination_repo_id, optional = {}) |
99 | 0e9f2f09 | Partha Aji | criteria = {:type_ids => [content_type], :filters => {}} |
100 | criteria[:filters]['association'] = {'unit_id' => {'$in' => optional[:ids]}} if optional[:ids] |
||
101 | e06e5c92 | Partha Aji | criteria[:filters] = optional[:filters] if optional[:filters] |
102 | 11cd4518 | Brad Buckingham | criteria[:fields] = {:unit => optional[:fields]} if optional[:fields] |
103 | |||
104 | 0e9f2f09 | Partha Aji | payload = {:criteria => criteria}
|
105 | 3e3ad61c | Partha Aji | payload[:override_config] = optional[:override_config] if optional.key?(:override_config) |
106 | 8fd5ecaf | Partha Aji | |
107 | if optional[:copy_children] |
||
108 | payload[:override_config] ||= {}
|
||
109 | payload[:override_config][:recursive] = true |
||
110 | end
|
||
111 | 11cd4518 | Brad Buckingham | |
112 | 661ca339 | Justin Sherrill | Runcible::Extensions::Repository.new(self.config).unit_copy(destination_repo_id, source_repo_id, payload) |
113 | 0e9f2f09 | Partha Aji | end
|
114 | abc913d9 | Eric D. Helms | end
|
115 | end
|
||
116 | end |