def createBranch(self, project, name, platformLabel, namespace=None, description=''): project = self.getProject(project) if project.project_branches and \ name in [b.name for b in project.project_branches]: raise errors.RbuildError("Branch named '%s' already exists" % name) doc = xobj.Document() doc.project_branch = br = xobj.XObj() br.project = xobj.XObj() # Why? for key in ('id', 'name', 'short_name', 'domain_name'): setattr(br.project, key, getattr(project, key)) br.name = name br.platform_label = unicode(platformLabel) br.description = description if namespace: br.namespace = namespace try: br = project.project_branches.append(doc) except robj.errors.HTTPConflictError: raise errors.RbuildError("Branch named '%s' already exists" % name) return br.label
def createProject(self, title, shortName, hostName=None, domainName=None, description='', external=False, external_params=None): assert ((external and external_params is not None) or (not external and external_params is None)) doc = xobj.Document() doc.project = proj = xobj.XObj() proj.name = title proj.short_name = shortName proj.hostname = hostName or shortName proj.description = description or '' if domainName: proj.domain_name = domainName if external: proj.external = 'true' (proj.labels, proj.upstream_url, proj.auth_type, proj.user_name, proj.password, proj.entitlement) = external_params else: proj.external = 'false' try: return self.api.projects.append(doc).project_id except robj.errors.HTTPConflictError: raise errors.RbuildError("A project with conflicting " "parameters already exists")
def createTarget(self, ttype, ddata): ''' Create a target using the descriptor data provided @param ttype: target type @type ttype: string @param ddata: descriptor data for target @type: DescriptorData @return: the created Target @rtype: robj.HTTPData ''' # Construct the target xml target_doc = xobj.Document() target_doc.target = target = xobj.XObj() target.description = ddata.getField('description') target.name = ddata.getField('name') target.zone_name = ddata.getField('zone') target.target_type_name = ttype try: target = self.api.targets.append(target_doc, tag='target') except robj.errors.HTTPConflictError: raise errors.RbuildError( "A target with conflicting parameters already exists") return target
def configureTargetCredentials(self, target, ddata): ''' Configure credentials for a target @param ddata: descriptor for target @type ddata: DescriptorData @param target: target to configure @type target: rObj(target) @return: the configured target @rtype: rObj(target) ''' # make sure our target object is up to date target.refresh() doc = xobj.Document() doc.job = job = xobj.XObj() job.job_type = target.actions[1]._root.job_type job.descriptor = target.actions[1]._root.descriptor job.descriptor_data = xobj.parse(ddata.toxml()).descriptor_data jobObj = target.jobs.append(doc) while jobObj.job_state.name in ['Queued', 'Running']: jobObj.refresh() if jobObj.job_state.name == 'Failed': raise errors.RbuildError('Unable to set credentials') return target
def cancel(self, image): ''' Cancel a currently running image build :param image: image obj :type image: rObj(image) ''' if image.status != '100': raise CancelImageError(msg="Image '%s' is not currently building" % image.image_id) cancelAction = [a for a in image.actions if a.key == self.CANCEL] if not cancelAction: raise CancelImageError(msg="Unable to find cancel action for" " image '%s'" % image.image_id) cancelAction = cancelAction[0] ddata = self.handle.DescriptorConfig.createDescriptorData( fromStream=cancelAction.descriptor) doc = xobj.Document() doc.job = job = xobj.XObj() job.job_type = cancelAction._root.job_type job.descriptor = cancelAction._root.descriptor job.descriptor_data = xobj.parse(ddata.toxml()).descriptor_data return image.jobs.append(doc)
def _createJob(self, action_type, image_name, target_name, doLaunch): rb = self.handle.facade.rbuilder project, branch, stage = self._getProductStage() image_name, _, version = image_name.partition('=') images = rb.getImages( image_name, project=project, branch=branch, stage=stage, trailingVersion=version, ) image, action = self._getAction(images, target_name, action_type) ddata = self.handle.DescriptorConfig.createDescriptorData( fromStream=action.descriptor) doc = xobj.Document() doc.job = job = xobj.XObj() job.job_type = action._root.job_type job.descriptor = action._root.descriptor job.descriptor_data = xobj.parse(ddata.toxml()).descriptor_data if doLaunch: return image.jobs.append(doc)
def _createJob(self, action_type, image_name, target_name, doLaunch): rb = self.handle.facade.rbuilder images = self.getImages(image_name) target = rb.getTargets(name=target_name) if not target: raise errors.PluginError("No target matching '%s'" % target_name) target = target[0] if target.is_configured == 'false': raise errors.PluginError( ("Target '{0}' is not configured. Try" " running \"rbuild edit target '{0}'\" or contacting" " your rbuilder administrator.").format(target.name)) if target.credentials_valid == 'false': raise errors.PluginError( ("Target '{0}' does not have valid" " credentials. Try running \"rbuild edit target '{0}'\"" " and updating your credentials.").format(target.name)) image, action = self._getAction(images, target, action_type) ddata = self.handle.DescriptorConfig.createDescriptorData( fromStream=action.descriptor) doc = xobj.Document() doc.job = job = xobj.XObj() job.job_type = action._root.job_type job.descriptor = action._root.descriptor job.descriptor_data = xobj.parse(ddata.toxml()).descriptor_data if doLaunch: return image.jobs.append(doc)
def _getCancelBuildJob(self, image): cancelAction = image.actions[0] ddata = self.handle.DescriptorConfig.createDescriptorData( fromStream=cancelAction.descriptor) doc = xobj.Document() doc.job = job = xobj.XObj() job.job_type = cancelAction._root.job_type job.descriptor = cancelAction._root.descriptor job.descriptor_data = xobj.parse(ddata.toxml()).descriptor_data return image.jobs.append(doc)
def createBranch(self, project, name, platformLabel, namespace=None, description=''): project = self.getProject(project) doc = xobj.Document() doc.project_branch = br = xobj.XObj() br.project = xobj.XObj() # Why? for key in ('id', 'name', 'short_name', 'domain_name'): setattr(br.project, key, getattr(project, key)) br.name = name br.platform_label = unicode(platformLabel) br.description = description if namespace: br.namespace = namespace br = project.project_branches.append(doc) return br.label
def create(self, user_name, full_name, email, password=None, external_auth=False, is_admin=False, can_create=True): '''Create a rbuilder user :param user_name: login name for user :type user_name: str :param full_name: full name of the user :type full_name: str :param email: user's email address :type email: str :param password: user's password, if not using external authentication :type password: str :param external_auth: whether to use external auth, must not be True if password is provided, default False :type external_auth: bool :param is_admin: is this an admin user, default False :type is_admin: bool :param can_create: can this user create resources, default True :type can_create: bool :raises: rbuild.errors.PluginError ''' if external_auth and password: raise errors.PluginError('Cannot use a password with external' ' authentication') if not external_auth and not password: raise errors.PluginError('Must provide a password if not using' ' external authentication') if is_admin and not self.handle.facade.rbuilder.isAdmin(): raise errors.UnauthorizedActionError('grant admin privilege') # create the user xml document user_doc = xobj.Document() user_doc.user = user = xobj.XObj() user.user_name = user_name user.full_name = full_name user.email = email if password is not None: user.password = password user.external_auth = external_auth user.is_admin = is_admin user.can_create = can_create # POST the new user client = self.handle.facade.rbuilder._getRbuilderRESTClient() client.api.users.append(user_doc)
def createProject(self, title, shortName, hostName=None, domainName=None, description=''): doc = xobj.Document() doc.project = proj = xobj.XObj() proj.name = title proj.short_name = shortName proj.hostname = hostName or shortName proj.description = description or '' if domainName: proj.domain_name = domainName proj.external = 'false' try: return self.api.projects.append(doc).project_id except robj.errors.HTTPConflictError: raise errors.RbuildError("A project with conflicting " "parameters already exists")