Class: ForemanPipeline::Job
- Inherits:
-
Katello::Model
- Object
- Katello::Model
- ForemanPipeline::Job
- Includes:
- ActiveModel::Validations, Authorization::Job, Katello::Glue
- Defined in:
- app/models/foreman_pipeline/job.rb
Instance Method Summary collapse
- #available_compute_resources ⇒ Object
- #can_be_promoted? ⇒ Boolean
-
#envs_for_promotion ⇒ Object
we have some to_envs set (== we want to promote), but cv version may already be in those envs.
- #init_run ⇒ Object
- #is_valid? ⇒ Boolean
-
#not_yet_promoted? ⇒ Boolean
this shlould make sure not to trigger cyclic runs in hook actions.
-
#promotion_safe? ⇒ Boolean
If we want to promote, is it safe (or could we get a cycle)?.
-
#should_be_promoted? ⇒ Boolean
Is any to_env set? (Do we want to promote to any env?).
- #target_cv_version ⇒ Object
- #target_cv_version_avail? ⇒ Boolean
Instance Method Details
#available_compute_resources ⇒ Object
84 85 86 87 88 |
# File 'app/models/foreman_pipeline/job.rb', line 84 def available_compute_resources return [] unless hostgroup ids = ComputeAttribute.where(:compute_profile_id => hostgroup.compute_profile_id).pluck(:compute_resource_id).uniq ComputeResource.where(:id => ids) end |
#can_be_promoted? ⇒ Boolean
80 81 82 |
# File 'app/models/foreman_pipeline/job.rb', line 80 def can_be_promoted? !envs_for_promotion.empty? end |
#envs_for_promotion ⇒ Object
we have some to_envs set (== we want to promote), but cv version may already be in those envs
76 77 78 |
# File 'app/models/foreman_pipeline/job.rb', line 76 def envs_for_promotion to_environments.reject { |env| target_cv_version.environments.include?(env) } end |
#init_run ⇒ Object
51 52 53 54 55 |
# File 'app/models/foreman_pipeline/job.rb', line 51 def init_run fail "Cannnot contact Jenkins server: no Jenkins Instance set for the job: #{name}" if jenkins_instance.nil? fail "Cannot log in to Jenkins server: no Jenkins User set for the Jenkins Instance: #{jenkins_instance.name}" if jenkins_instance.jenkins_user.nil? jenkins_instance.create_client(jenkins_instance.jenkins_user.name, jenkins_instance.jenkins_user.token) end |
#is_valid? ⇒ Boolean
36 37 38 |
# File 'app/models/foreman_pipeline/job.rb', line 36 def is_valid? !self.attributes.values.include?(nil) && !self.jenkins_instance.jenkins_user.nil? end |
#not_yet_promoted? ⇒ Boolean
this shlould make sure not to trigger cyclic runs in hook actions
63 64 65 66 67 68 |
# File 'app/models/foreman_pipeline/job.rb', line 63 def not_yet_promoted? # no to_envs means we do not want to promote, no need to check further here return true if to_environments.empty? #we want to promote, but are any of to_envs safe to promote to? can_be_promoted? end |
#promotion_safe? ⇒ Boolean
If we want to promote, is it safe (or could we get a cycle)?
71 72 73 |
# File 'app/models/foreman_pipeline/job.rb', line 71 def promotion_safe? should_be_promoted? ? can_be_promoted? : false end |
#should_be_promoted? ⇒ Boolean
Is any to_env set? (Do we want to promote to any env?)
58 59 60 |
# File 'app/models/foreman_pipeline/job.rb', line 58 def should_be_promoted? !to_environments.empty? end |
#target_cv_version ⇒ Object
44 45 46 47 48 49 |
# File 'app/models/foreman_pipeline/job.rb', line 44 def target_cv_version fail "Cannot fetch target version, no environment set" if environment.nil? fail "Cannot fetch target version, no content view set" if content_view.nil? fail "Content view has no versions!" if content_view.content_view_versions.empty? self.environment.content_view_versions.where(:content_view_id => self.content_view.id).first end |
#target_cv_version_avail? ⇒ Boolean
40 41 42 |
# File 'app/models/foreman_pipeline/job.rb', line 40 def target_cv_version_avail? !target_cv_version.nil? end |