Darshan Deshmukh
Darshan Deshmukh

Reputation: 353

Updating the parent via rally API

I have more than 1000 projects which are in closed state under one of our work space.

I got that data from - https://rally1.rallydev.com/slm/webservice/1.29/subscription?fetch=Workspaces,Name,Projects,State

We want to update the "Parent" for the projects which are marked as "Closed".

import sys
from pyral import Rally, rallyWorkset
options = [arg for arg in sys.argv[1:] if arg.startswith('--')]
args    = [arg for arg in sys.argv[1:] if arg not in options]
server = <server>
apikey = <api_key>
workspace = <workspace>
project = <project_name>
rally = Rally(server,apikey=apikey, workspace=workspace, project=project)
rally.enableLogging('mypyral.log')

Method to check the status of the projects -

projects = rally.getProjects(workspace=workspace)
for proj in projects:
    print ("    %12.12s  %s  %s" % (proj.oid, proj.Name, proj.State))

I didnt find any reference to update the project parent here - Rest API post method - http://pyral.readthedocs.io/en/latest/interface.html?highlight=post

Upvotes: 0

Views: 437

Answers (1)

user2738882
user2738882

Reputation: 1190

I would do it in the following way:

#get object for 'New Parent':

target_project = rally.getProject('NewParentForClosedProjects')

projects = rally.getProjects(workspace=workspace) for proj in projects:

    #get children of project
    children = proj.Children

    for child in children:

        #if project closed:
        if child.State == 'Closed':
            #Then update Parent to new one:
            project_fields = {
                "ObjectID": child.oid,
                "Parent": target_project.ref
            }
            try:
                result = rally.update('Project', project_fields)
                print "Project %s has been successfully updated with new %s parent" % (str(child.Name), str(child.Parent))
            except RallyRESTException, ex:
                print "Update failure for Project %s" % (str(child.Name))
                print ex

Upvotes: 1

Related Questions