Class: Content::Pulp::Repository

Inherits:
Object
  • Object
show all
Defined in:
app/services/content/pulp/repository.rb

Direct Known Subclasses

RepositoryClone

Constant Summary collapse

PULP_SELECT_FIELDS =
['name', 'epoch', 'version', 'release', 'arch', 'checksumtype', 'checksum']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Repository

Returns a new instance of Repository.



23
24
25
26
27
28
29
30
31
32
# File 'app/services/content/pulp/repository.rb', line 23

def initialize options = {}
  options.each do |k, v|
    instance_variable_set("@#{k}", v) if respond_to?("#{k}".to_sym)
  end

  raise('must define pulp id') unless pulp_id

  # initiate pulp connection
  Content::Pulp::Configuration.new
end

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type.



4
5
6
# File 'app/services/content/pulp/repository.rb', line 4

def content_type
  @content_type
end

#descriptionObject (readonly)

Returns the value of attribute description.



4
5
6
# File 'app/services/content/pulp/repository.rb', line 4

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'app/services/content/pulp/repository.rb', line 4

def name
  @name
end

#pulp_idObject (readonly)

Returns the value of attribute pulp_id.



4
5
6
# File 'app/services/content/pulp/repository.rb', line 4

def pulp_id
  @pulp_id
end

#relative_pathObject (readonly)

Returns the value of attribute relative_path.



4
5
6
# File 'app/services/content/pulp/repository.rb', line 4

def relative_path
  @relative_path
end

Class Method Details

.create(options = {}) ⇒ Object



9
10
11
# File 'app/services/content/pulp/repository.rb', line 9

def create(options = {})
  new(options).create
end

.delete(pulp_id) ⇒ Object



13
14
15
# File 'app/services/content/pulp/repository.rb', line 13

def delete(pulp_id)
  new(:pulp_id => pulp_id).delete
end

.sync(pulp_id) ⇒ Object



17
18
19
# File 'app/services/content/pulp/repository.rb', line 17

def sync(pulp_id)
  new(:pulp_id => pulp_id).sync
end

Instance Method Details

#auto_publishObject



70
71
72
# File 'app/services/content/pulp/repository.rb', line 70

def auto_publish
  @auto_publish.nil? ? distributor['auto_publish'] : @auto_publish
end

#cancel_running_sync!Object



108
109
110
111
112
113
# File 'app/services/content/pulp/repository.rb', line 108

def cancel_running_sync!
  return if sync_status.blank? || sync_status.not_synced?
  Runcible::Resources::Task.cancel(sync_status.task_id)
rescue RestClient::ResourceNotFound
  # task already done, nothing to do here
end

#checksum_typeObject



46
47
48
# File 'app/services/content/pulp/repository.rb', line 46

def checksum_type
  details['checksum_type']
end

#countersObject



54
55
56
# File 'app/services/content/pulp/repository.rb', line 54

def counters
  details['content_unit_counts']
end

#createObject



38
39
40
# File 'app/services/content/pulp/repository.rb', line 38

def create
  create_repository
end

#create_event_notifierObject

once we keep a list pulp servers, this should be done in create/destroy



116
117
118
119
120
121
122
123
124
125
126
127
# File 'app/services/content/pulp/repository.rb', line 116

def create_event_notifier
  url      = Rails.application.routes.url_helpers.
               events_api_repositories_url(:only_path => false, :host => Setting[:foreman_url])
  type     = '*'
  resource = Runcible::Resources::EventNotifier
  notifs   = resource.list

  #only create a notifier if one doesn't exist with the correct url
  exists   = notifs.select { |n| n['event_types'] == [type] && n['notifier_config']['url'] == url }
  resource.create(resource::NotifierTypes::REST_API, { :url => url }, [type]) if exists.empty?
  true
end

#create_with_distributorObject



34
35
36
# File 'app/services/content/pulp/repository.rb', line 34

def create_with_distributor
  create_repository [pulp_distributor]
end

#deleteObject



94
95
96
97
98
# File 'app/services/content/pulp/repository.rb', line 94

def delete
  Runcible::Resources::Repository.delete(pulp_id)
rescue RestClient::ResourceNotFound => e
  true #not found is not a failure for delete
end

#display_nameObject



42
43
44
# File 'app/services/content/pulp/repository.rb', line 42

def display_name
  details['display_name']
end

#feedObject



58
59
60
# File 'app/services/content/pulp/repository.rb', line 58

def feed
  @feed || importer['config']['feed_url']
end

#last_publishObject



66
67
68
# File 'app/services/content/pulp/repository.rb', line 66

def last_publish
  distributor['last_publish']
end

#last_syncObject



62
63
64
# File 'app/services/content/pulp/repository.rb', line 62

def last_sync
  importer['last_sync']
end

#protectedObject



74
75
76
# File 'app/services/content/pulp/repository.rb', line 74

def protected
  @protected.nil? ? distributor['protected'] : @protected
end

#publishObject



104
105
106
# File 'app/services/content/pulp/repository.rb', line 104

def publish
  Runcible::Extensions::Repository.publish_all(pulp_id)
end

#reload!Object



78
79
80
# File 'app/services/content/pulp/repository.rb', line 78

def reload!
  @details = nil
end

#syncObject



100
101
102
# File 'app/services/content/pulp/repository.rb', line 100

def sync
  Runcible::Resources::Repository.sync(pulp_id)
end

#sync_historyObject



87
88
89
90
91
92
# File 'app/services/content/pulp/repository.rb', line 87

def sync_history
  history = Runcible::Extensions::Repository.sync_history(pulp_id)
  (history || []).map do |sync|
    Content::Pulp::RepositorySyncHistory.new(sync)
  end
end

#sync_scheduleObject



138
139
140
# File 'app/services/content/pulp/repository.rb', line 138

def sync_schedule
  Runcible::Resources::RepositorySchedule.list(pulp_id, Runcible::Extensions::YumImporter::ID)
end

#sync_schedule=(schedule) ⇒ Object



129
130
131
132
133
134
135
136
# File 'app/services/content/pulp/repository.rb', line 129

def sync_schedule=(schedule)
  type = Runcible::Extensions::YumImporter::ID
  if schedule.present?
    Runcible::Resources::RepositorySchedule.create(pulp_id, type, schedule)
  else
    Runcible::Extensions::Repository.remove_schedules(pulp_id, type)
  end
end

#sync_statusObject



82
83
84
85
# File 'app/services/content/pulp/repository.rb', line 82

def sync_status
  status = Runcible::Extensions::Repository.sync_status(pulp_id)
  Content::Pulp::RepositorySyncStatus.new(status.first) unless status.empty?
end