def create_unified_job(self, **kwargs): ''' Create a new unified job based on this unified job template. ''' unified_job_class = self._get_unified_job_class() fields = self._get_unified_job_field_names() unified_job = copy_model_by_class(self, unified_job_class, fields, kwargs) eager_fields = kwargs.get('_eager_fields', None) if eager_fields: for fd, val in eager_fields.items(): setattr(unified_job, fd, val) # Set the unified job template back-link on the job parent_field_name = unified_job_class._get_parent_field_name() setattr(unified_job, parent_field_name, self) # For JobTemplate-based jobs with surveys, add passwords to list for perma-redaction if hasattr(self, 'survey_spec') and getattr(self, 'survey_enabled', False): password_list = self.survey_password_variables() hide_password_dict = getattr(unified_job, 'survey_passwords', {}) for password in password_list: hide_password_dict[password] = REPLACE_STR unified_job.survey_passwords = hide_password_dict unified_job.save() # Labels and extra credentials copied here from awx.main.signals import disable_activity_stream with disable_activity_stream(): copy_m2m_relationships(self, unified_job, fields, kwargs=kwargs) return unified_job
def copy_unified_job(self, limit=None): ''' Returns saved object, including related fields. Create a copy of this unified job for the purpose of relaunch ''' unified_job_class = self.__class__ unified_jt_class = self._get_unified_job_template_class() parent_field_name = unified_job_class._get_parent_field_name() fields = unified_jt_class._get_unified_job_field_names() + [parent_field_name] create_data = {"launch_type": "relaunch"} if limit: create_data["limit"] = limit prompts = self.launch_prompts() if self.unified_job_template and prompts: prompts['_eager_fields'] = create_data unified_job = self.unified_job_template.create_unified_job(**prompts) else: unified_job = copy_model_by_class(self, unified_job_class, fields, {}) for fd, val in create_data.items(): setattr(unified_job, fd, val) unified_job.save() # Labels coppied here copy_m2m_relationships(self, unified_job, fields) return unified_job
def create_unified_job(self, **kwargs): ''' Create a new unified job based on this unified job template. ''' new_job_passwords = kwargs.pop('survey_passwords', {}) eager_fields = kwargs.pop('_eager_fields', None) unified_job_class = self._get_unified_job_class() fields = self._get_unified_job_field_names() unallowed_fields = set(kwargs.keys()) - set(fields) if unallowed_fields: raise Exception('Fields {} are not allowed as overrides.'.format( unallowed_fields)) unified_job = copy_model_by_class(self, unified_job_class, fields, kwargs) if eager_fields: for fd, val in eager_fields.items(): setattr(unified_job, fd, val) # Set the unified job template back-link on the job parent_field_name = unified_job_class._get_parent_field_name() setattr(unified_job, parent_field_name, self) # For JobTemplate-based jobs with surveys, add passwords to list for perma-redaction if hasattr(self, 'survey_spec') and getattr(self, 'survey_enabled', False): for password in self.survey_password_variables(): new_job_passwords[password] = REPLACE_STR if new_job_passwords: unified_job.survey_passwords = new_job_passwords kwargs[ 'survey_passwords'] = new_job_passwords # saved in config object for relaunch unified_job.save() # Labels and credentials copied here if kwargs.get('credentials'): Credential = UnifiedJob._meta.get_field( 'credentials').related_model cred_dict = Credential.unique_dict(self.credentials.all()) prompted_dict = Credential.unique_dict(kwargs['credentials']) # combine prompted credentials with JT cred_dict.update(prompted_dict) kwargs['credentials'] = [cred for cred in cred_dict.values()] from awx.main.signals import disable_activity_stream with disable_activity_stream(): copy_m2m_relationships(self, unified_job, fields, kwargs=kwargs) if 'extra_vars' in kwargs: unified_job.handle_extra_data(kwargs['extra_vars']) if not getattr(self, '_deprecated_credential_launch', False): # Create record of provided prompts for relaunch and rescheduling unified_job.create_config_from_prompts(kwargs) return unified_job
def copy_unified_jt(self): ''' Returns saved object, including related fields. Create a copy of this unified job template. ''' unified_jt_class = self.__class__ fields = self._get_unified_jt_copy_names() unified_jt = copy_model_by_class(self, unified_jt_class, fields, {}) time_now = now() unified_jt.name = unified_jt.name.split('@', 1)[0] + ' @ ' + time_now.strftime('%I:%M:%S %p') unified_jt.save() copy_m2m_relationships(self, unified_jt, fields) return unified_jt
def copy_unified_job(self): ''' Returns saved object, including related fields. Create a copy of this unified job for the purpose of relaunch ''' unified_job_class = self.__class__ unified_jt_class = self._get_unified_job_template_class() parent_field_name = unified_job_class._get_parent_field_name() fields = unified_jt_class._get_unified_job_field_names() + [parent_field_name] unified_job = copy_model_by_class(self, unified_job_class, fields, {}) unified_job.launch_type = 'relaunch' unified_job.save() # Labels coppied here copy_m2m_relationships(self, unified_job, fields) return unified_job