def __main__(): # hard coded user = '******' password = '******' base_url = 'https://192.168.1.117' # login ucd = ucdclient.ucdclient( base_url, user, password , debug=0) ''' Create an Auth Realm ''' authz_realm_uri = '/security/authorizationRealm' authz_realm_name = 'AuthzTestRealm' new_authz_realm = { 'name': authz_realm_name , 'description' : '', 'authorizationModuleClassName': 'com.urbancode.security.authorization.internal.InternalAuthorizationModule', 'properties': {'group-mapper': '00000000000000000000000000000000'}} body = json.dumps( new_authz_realm ) #r = ucd.post( uri=authz_realm_uri, data=body ) print ucd.create_authz_realm( 'testing' ) # 200 ok should have new authz realm content in response text # 403 already exists ? #ucd.debug_response( r ) group_name = 'TestGroup' authz_realm_id = '' new_group = '' ''' Create a group ''' security_group_uri = '/security/group'
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help','server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ( '-s', '--server'): base_url = a elif o in ( '-u', '--user'): user = a elif o in ( '-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() ucd = ucdclient.ucdclient( base_url, user, password , debug )
def __main__(): # hard coded user = '******' password = '******' base_url = 'https://192.168.1.117' ucd = ucdclient.ucdclient( base_url, user, password , 0 ) application_name = 'JPetStore' ts = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') snapshot_name = 'AS-%s' % ( ts ) snapshot_description = 'Automated snapshot' # Get application id # /rest/deploy/application r = ucd.get( '/rest/deploy/application?name=%s' % (application_name) ) application = r.json()[0] #print( application ) # Get components and get latest version id of each get_application_components_uri = '/rest/deploy/component?&filterFields=applications.id&filterValue_applications.id=%s&filterType_applications.id=eq&filterClass_applications.id=UUID' % ( application['id'] ) r = ucd.get( get_application_components_uri ) components = r.json() # Create Snapshot with all components at latest version snapshot_uri = '/rest/deploy/snapshot' application_snapshot = { 'name' : snapshot_name, 'applicationId' : application['id'], 'description': snapshot_description, 'versionIds' : [] } body = json.dumps( application_snapshot ) r = ucd.put( uri=snapshot_uri, data=body ) snapshot = r.json() #pprint( snapshot ) # Build up an array of version ids by grabbing each of the applications components # and grabbing the latestVersion id snapshot_versions = { 'versionIds' : [] } for component in components: component_latest_version_uri = '/rest/deploy/component/%s/latestVersion' % ( component['id'] ) r = ucd.get( component_latest_version_uri ) if r.status_code == 200: component_version = r.json() snapshot_versions['versionIds'].append( component_version['id']) else: print('%s : Gettting latest version failed, skipping as this components has no versions.' % ( component['name']) ) #ucd.debug_response( r ) body = json.dumps( snapshot_versions ) #pprint( body ) snapshot_versions_uri = '/rest/deploy/snapshot/%s/versions' % ( snapshot['id'] ) ucd.put( uri=snapshot_versions_uri, data=body ) # does not return the updated snapshot just a HTTP 204 for updated # To get the final view of the snapshot we grab it at the end get_snapshot_uri = '/rest/deploy/snapshot/%s' % ( snapshot['id'] ) r = ucd.get( get_snapshot_uri ) updated_snapshot = r.json() pprint( updated_snapshot )
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help', 'server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ('-s', '--server'): base_url = a elif o in ('-u', '--user'): user = a elif o in ('-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # hard coded rest_uri = '/rest/plugin/automationPlugin' rest_uri_src = '/rest/plugin/sourceConfigPlugins' plugin_dir = '/Users/sgwilbur/Dropbox/UCD-plugins/' verbose = 0 delete_plugins = 1 # Peel and specfic arguments off the end for this call arg1, arg2 = sys.argv[-2:] ucd = ucdclient.ucdclient(base_url, user, password, debug) current_plugins = ucd.get_json(rest_uri) for plugin in current_plugins: print plugin['name'], " (", plugin['version'], ")" if verbose: print plugin['id'] print plugin['pluginId'] print plugin['version'] print plugin['versionNumber'] print plugin['description'][0:100], "..." print plugin['ghostedDate']
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help', 'server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ('-s', '--server'): base_url = a elif o in ('-u', '--user'): user = a elif o in ('-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() ucd = ucdclient.ucdclient(base_url, user, password, debug) uri = '/rest/deploy/component/443318b8-d98e-42e6-8a68-ab4cc9f1c4ca/runProcess' print 'NN-DHP: Calling nndhp_scripts::iib_setup on SDT-TEST0' request_body = { "environmentId": "16cc9353-967f-4406-8ba9-d1ea94e86591", "resourceId": "6378aa93-4428-46c3-a9c2-b3fdb6169307", "componentProcessId": "7da51aab-6263-4eed-b0cb-8cfea993adf7", "properties": {} } # print 'NN-DHP: Calling nndhp_scripts::test_mqsistart on DEV1' # request_body = { # "environmentId":"b0813fcd-86ef-4848-b5e6-efc91e1d4fe2", # "resourceId":"0765dfbe-89f4-4f19-a37e-eeb14a045f2f", # "componentProcessId":"63f6fc22-a3b3-48c5-845f-dde04cb3444a", # "properties":{} # } request_id = ucd.put_json(uri=uri, data=json.dumps(request_body)) print request_id
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help','server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ( '-s', '--server'): base_url = a elif o in ( '-u', '--user'): user = a elif o in ( '-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # Peel and specfic arguments off the end for this call arg1, arg2 = sys.argv[-2:] ucd = ucdclient.ucdclient( base_url, user, password , debug ) uri = '/rest/workflow/currentActivity?rowsPerPage=10&pageNumber=1&orderField=startDate&sortType=desc' activities = ucd.get_json( uri ) #pprint( activities[0] ) print 'Found %d activites' % (len(activities)) # return for activity in activities: cancel_uri = '/rest/workflow/%s/cancel' % ( activity['id'] ) r = ucd.put( uri=cancel_uri ) if r.status_code not in [ 200, 201 ]: print( 'Error cancelling') ucd.debug_response( r ) else: print( 'I think we cancelled it')
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help', 'server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ('-s', '--server'): base_url = a elif o in ('-u', '--user'): user = a elif o in ('-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() ucd = ucdclient.ucdclient(base_url, user, password, debug) # https://www.ibm.com/support/knowledgecenter/SS4GSP_6.1.3/com.ibm.udeploy.api.doc/topics/rest_cli_environment_createenvironment_put.html #application_id ='aa93dec4-b721-4106-bb1d-c314ccf91286' application_id = 'Node+App+2' name = 'ENV' description = 'environment' color = '#00B2EF' environment_cli_uri = '/cli/environment/createEnvironment?' environment_cli_params = 'application=%s&name=%s' % (application_id, name) #environment_cli_params = 'application=%s' % ( application_id ) # r = ucd.put( uri='%s%s' % (environment_cli_uri, environment_cli_params) ) #r = ucd.post( '/cli/environment/createEnvironment?application=Node+App+2&name=ENV5' ) r = ucd.put_plain( '/cli/environment/createEnvironment?application=Node+App+2&name=ENV5') ucd.debug_response(r)
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help','server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ( '-s', '--server'): base_url = a elif o in ( '-u', '--user'): user = a elif o in ( '-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() ucd = ucdclient.ucdclient( base_url, user, password , debug ) # https://www.ibm.com/support/knowledgecenter/SS4GSP_6.1.3/com.ibm.udeploy.api.doc/topics/rest_cli_environment_createenvironment_put.html #application_id ='aa93dec4-b721-4106-bb1d-c314ccf91286' application_id ='Node+App+2' name = 'ENV' description = 'environment' color = '#00B2EF' environment_cli_uri = '/cli/environment/createEnvironment?' environment_cli_params = 'application=%s&name=%s' % ( application_id, name ) #environment_cli_params = 'application=%s' % ( application_id ) # r = ucd.put( uri='%s%s' % (environment_cli_uri, environment_cli_params) ) #r = ucd.post( '/cli/environment/createEnvironment?application=Node+App+2&name=ENV5' ) r = ucd.put_plain( '/cli/environment/createEnvironment?application=Node+App+2&name=ENV5' ) ucd.debug_response( r )
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help','server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ( '-s', '--server'): base_url = a elif o in ( '-u', '--user'): user = a elif o in ( '-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # Peel and specfic arguments off the end for this call arg1, arg2 = sys.argv[-2:] ucd = ucdclient.ucdclient( base_url, user, password , debug ) uri = '/rest/deploy/component/componentSizeReport?rowsPerPage=10&pageNumber=1&orderField=sizeOnDisk&sortType=desc' components = ucd.get_json( uri=uri ) for component in components: pprint( component ) versions_uri = '/rest/deploy/version?rowsPerPage=10&pageNumber=1&orderField=dateCreated&sortType=desc&filterFields=component.id&filterFields=active&filterValue_component.id=%s&filterType_component.id=eq&filterClass_component.id=UUID&filterValue_active=true&filterType_active=eq&filterClass_active=Boolean&outputType=BASIC&outputType=LINKED' % ( component['id'] ) versions_info = ucd.get_json( uri=versions_uri )
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help', 'server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ('-s', '--server'): base_url = a elif o in ('-u', '--user'): user = a elif o in ('-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # Peel and specfic arguments off the end for this call arg1, arg2 = sys.argv[-2:] ucd = ucdclient.ucdclient(base_url, user, password, debug) #comp_template_id = '5b36f7a2-a458-48bd-b046-7a44656c5861' comp_template_id = '250f14f1-8042-435f-893e-8bc267183c82' comp_template_uri = '/rest/deploy/componentTemplate/%s/' % ( comp_template_id) comp_template = ucd.get_json(uri=comp_template_uri) pprint(comp_template)
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help', 'server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ('-s', '--server'): base_url = a elif o in ('-u', '--user'): user = a elif o in ('-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # Peel and specfic arguments off the end for this call arg1, arg2 = sys.argv[-2:] ucd = ucdclient.ucdclient(base_url, user, password, debug) application_id = '20a54351-138d-4854-9f74-9a33f27e3e6f' get_process_for_app_uri = '/rest/deploy/applicationProcessRequest/table?rowsPerPage=10&pageNumber=1&orderField=calendarEntry.scheduledDate&sortType=desc&filterFields=application.id&filterValue_application.id=%s&filterType_application.id=eq&filterClass_application.id=UUID&outputType=BASIC&outputType=LINKED' % ( application_id) p = ucd.get_json(uri=get_process_for_app_uri) pprint(p)
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ["help", "server=", "user="******"password="******"option -a not recognized" usage() sys.exit(2) for o, a in opts: if o == "-v": debug = True elif o in ("-h", "--help"): usage() sys.exit() elif o in ("-s", "--server"): base_url = a elif o in ("-u", "--user"): user = a elif o in ("-p", "--password"): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print ("Missing required arguments") usage() sys.exit() # Peel and specfic arguments off the end for this call arg1, arg2 = sys.argv[-2:] ucd = ucdclient.ucdclient(base_url, user, password, debug) # comp_template_id = '5b36f7a2-a458-48bd-b046-7a44656c5861' comp_template_id = "250f14f1-8042-435f-893e-8bc267183c82" comp_template_uri = "/rest/deploy/componentTemplate/%s/" % (comp_template_id) comp_template = ucd.get_json(uri=comp_template_uri) pprint(comp_template)
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help','server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ( '-s', '--server'): base_url = a elif o in ( '-u', '--user'): user = a elif o in ( '-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # Peel and specfic arguments off the end for this call arg1, arg2 = sys.argv[-2:] ucd = ucdclient.ucdclient( base_url, user, password , debug ) application_id = '20a54351-138d-4854-9f74-9a33f27e3e6f' get_process_for_app_uri = '/rest/deploy/applicationProcessRequest/table?rowsPerPage=10&pageNumber=1&orderField=calendarEntry.scheduledDate&sortType=desc&filterFields=application.id&filterValue_application.id=%s&filterType_application.id=eq&filterClass_application.id=UUID&outputType=BASIC&outputType=LINKED' % ( application_id ) p = ucd.get_json( uri=get_process_for_app_uri ) pprint( p )
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help', 'server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ('-s', '--server'): base_url = a elif o in ('-u', '--user'): user = a elif o in ('-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # Peel and specfic arguments off the end for this call arg1, arg2 = sys.argv[-2:] ucd = ucdclient.ucdclient(base_url, user, password, debug) r = ucd.post('/rest/historyCleanup/runCleanupNow') ucd.debug_response(r)
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help','server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ( '-s', '--server'): base_url = a elif o in ( '-u', '--user'): user = a elif o in ( '-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # Peel and specfic arguments off the end for this call arg1, arg2 = sys.argv[-2:] ucd = ucdclient.ucdclient( base_url, user, password , debug ) r = ucd.post( '/rest/historyCleanup/runCleanupNow' ) ucd.debug_response( r )
def __main__(): # hard coded user = '******' password = '******' base_url = 'https://192.168.1.117' # login ucd = ucdclient.ucdclient(base_url, user, password, debug=0) ''' Create an Auth Realm ''' authz_realm_uri = '/security/authorizationRealm' authz_realm_name = 'AuthzTestRealm' new_authz_realm = { 'name': authz_realm_name, 'description': '', 'authorizationModuleClassName': 'com.urbancode.security.authorization.internal.InternalAuthorizationModule', 'properties': { 'group-mapper': '00000000000000000000000000000000' } } body = json.dumps(new_authz_realm) #r = ucd.post( uri=authz_realm_uri, data=body ) print ucd.create_authz_realm('testing') # 200 ok should have new authz realm content in response text # 403 already exists ? #ucd.debug_response( r ) group_name = 'TestGroup' authz_realm_id = '' new_group = '' ''' Create a group ''' security_group_uri = '/security/group'
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help', 'server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ('-s', '--server'): base_url = a elif o in ('-u', '--user'): user = a elif o in ('-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() ucd = ucdclient.ucdclient(base_url, user, password, debug) component_name = 'SVN Component 1' version = '1.1'
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help', 'server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ('-s', '--server'): base_url = a elif o in ('-u', '--user'): user = a elif o in ('-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() ucd = ucdclient.ucdclient(base_url, user, password, debug) sleep_time = 30 environments = ['DEV', 'UAT', 'PROD'] snapshots = ['SNAP-1', 'SNAP-2', 'SNAP-3', 'SNAP-4'] #for i in range(1, 100): while True: #environment = random.choice(environments) for environment in environments: snapshot = random.choice(snapshots) request_body = { 'application': 'APP00001', 'applicationProcess': 'Install', 'environment': environment, 'snapshot': snapshot, 'onlyChanged': 'false' } print '%s: Calling %s on %s environment with snapshot %s' % ( request_body['application'], request_body['applicationProcess'], request_body['environment'], request_body['snapshot']) request_id = ucd.put_json( uri='/cli/applicationProcessRequest/request', data=json.dumps(request_body)) print request_id time.sleep(sleep_time)
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help','server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ( '-s', '--server'): base_url = a elif o in ( '-u', '--user'): user = a elif o in ( '-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # Peel and specfic arguments off the end for this call arg1, arg2 = sys.argv[-2:] ucd = ucdclient.ucdclient( base_url, user, password , debug ) application_name = 'NN-DHP' # used to search process names for sub-string match process_filter = 'DHP-IIB / DHP-IIB' # Get all applicationProcess applications_uri = '/rest/deploy/application' applications = ucd.get_json( uri=applications_uri ) application_id = '' for app in applications: if app['name'] == application_name: application_id = app['id'] break if application_id == '': print( 'Application with name [%s] not found' % ( application_name ) ) pprint( applications ) sys.exit(1) # Find processes for specific app_id app_processes_uri = '/rest/deploy/application/%s/processes/false?rowsPerPage=10&pageNumber=1&sortType=asc' % (application_id) processes = ucd.get_json( uri=app_processes_uri ) # Inspect all the processes that get returned # pprint( processes ) for process in processes: pprint( process ) # Create a list of process ids of all the process names that contain the filter processes_to_delete = [ process['id'] for process in processes if process_filter in process['name'] ] print( 'Processes to be deleted: ') pprint( processes_to_delete ) for process_id in processes_to_delete: delete_uri = '/rest/deploy/applicationProcess/%s' % ( process_id ) r = ucd.delete( uri=delete_uri ) pprint( r )
def __main__(): # hard coded user = '******' password = '******' base_url = 'https://192.168.1.117' ucd = ucdclient.ucdclient(base_url, user, password, 0) application_name = 'JPetStore' ts = datetime.datetime.fromtimestamp( time.time()).strftime('%Y-%m-%d %H:%M:%S') snapshot_name = 'AS-%s' % (ts) snapshot_description = 'Automated snapshot' # Get application id # /rest/deploy/application r = ucd.get('/rest/deploy/application?name=%s' % (application_name)) application = r.json()[0] #print( application ) # Get components and get latest version id of each get_application_components_uri = '/rest/deploy/component?&filterFields=applications.id&filterValue_applications.id=%s&filterType_applications.id=eq&filterClass_applications.id=UUID' % ( application['id']) r = ucd.get(get_application_components_uri) components = r.json() # Create Snapshot with all components at latest version snapshot_uri = '/rest/deploy/snapshot' application_snapshot = { 'name': snapshot_name, 'applicationId': application['id'], 'description': snapshot_description, 'versionIds': [] } body = json.dumps(application_snapshot) r = ucd.put(uri=snapshot_uri, data=body) snapshot = r.json() #pprint( snapshot ) # Build up an array of version ids by grabbing each of the applications components # and grabbing the latestVersion id snapshot_versions = {'versionIds': []} for component in components: component_latest_version_uri = '/rest/deploy/component/%s/latestVersion' % ( component['id']) r = ucd.get(component_latest_version_uri) if r.status_code == 200: component_version = r.json() snapshot_versions['versionIds'].append(component_version['id']) else: print( '%s : Gettting latest version failed, skipping as this components has no versions.' % (component['name'])) #ucd.debug_response( r ) body = json.dumps(snapshot_versions) #pprint( body ) snapshot_versions_uri = '/rest/deploy/snapshot/%s/versions' % ( snapshot['id']) ucd.put(uri=snapshot_versions_uri, data=body) # does not return the updated snapshot just a HTTP 204 for updated # To get the final view of the snapshot we grab it at the end get_snapshot_uri = '/rest/deploy/snapshot/%s' % (snapshot['id']) r = ucd.get(get_snapshot_uri) updated_snapshot = r.json() pprint(updated_snapshot)
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help','server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ( '-s', '--server'): base_url = a elif o in ( '-u', '--user'): user = a elif o in ( '-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() ucd = ucdclient.ucdclient( base_url, user, password , debug ) team_name = 'Team1' team = ucd.create_team( team_name, '' ) app_name = 'Application2' application = ucd.create_application( app_name ) if not application: print( 'App not created, must already exist' ) application = ucd.get_application( app_name ) components = ['comp1', 'comp2', 'comp3', 'comp4'] new_comp_ids = [] for component_name in components: print( 'Creating new component %s' % ( component_name ) ) new_component_body = { 'name' : component_name, 'description' : ' Testing the programmatic creation of components', 'sourceConfigPlugin' : 'Subversion', 'properties': { 'SubversionComponentProperties/repoUrl' : 'svn://localhost/component1/tags', 'SubversionComponentProperties/watchTags' : 'true', 'SubversionComponentProperties/includes' : '**/*', 'SubversionComponentProperties/excludes' : '', 'SubversionComponentProperties/user' : 'admin', 'SubversionComponentProperties/password' : 'admin', 'SubversionComponentProperties/svnPath' : 'svn', 'SubversionComponentProperties/saveFileExecuteBits' : 'false', 'SubversionComponentProperties/extensions' : '', }, 'importAutomatically' : 'false', 'useVfs' : 'true', 'defaultVersionType' : 'FULL', } # Create Component new_comp = ucd.create_component( new_component_body ) if not new_comp: print( 'Not created, must already exist' ) new_comp = ucd.get_component( component_name ) new_comp_ids.append( new_comp['id'] ) pprint( new_comp ) ## Need to add some versions # ./udclient --weburl https://localhost:8443 --username admin --password admin createVersion -component comp1 -name 1.1 # ./udclient --weburl https://localhost:8443 --username admin --password admin addVersionFiles -component comp1 -version 1.1 -base . udclient.cmd # # Add components to app # PUT /rest/deploy/application/19473061-4298-4c12-88a0-ed81be852d19/addComponents # {"components":["97de696d-835a-4392-a2f2-8009e41b7b43","0d905c22-e09b-43c2-a310-c5a6c227a1c2"]} add_comps_to_app_uri = '/rest/deploy/application/%s/addComponents' % ( application['id']) components_to_add_body = { 'components': new_comp_ids } updated_application = ucd.put_json( uri=add_comps_to_app_uri, data=json.dumps( components_to_add_body ) ) pprint( updated_application ) application_id ='Node+App+2' name = 'DEV' description = 'environment' color = '#00B2EF' environment_create_uri = '/cli/environment/createEnvironment?application=%s&name=%s&description=%s&color=%s' % ( app_name, name, description, color ) environment_create_uri = '/cli/environment/createEnvironment?application=%s&name=%s' % ( app_name, name ) # TODO: I think this is a bug it seems to only accept text/plain content type environment = ucd.put_plain( uri=environment_create_uri ) pprint( environment ) continue # Add any Tags we need to for this component ucd.tag_component( new_comp['id'], 'CompTag0' )
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help','server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ( '-s', '--server'): base_url = a elif o in ( '-u', '--user'): user = a elif o in ( '-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # define here if you want to do this static-like #role_name1 = 'Observer' #role_name2 = 'Stakeholder' # Pull the last two items off the arguments list role_name1, role_name2 = sys.argv[-2:] ucd = ucdclient.ucdclient( base_url, user, password , debug ) # Get teams #print( 'Get Teams') #r = ucd.get( uri=team_uri ) #teams = r.json() #for current_team in teams: #current_team_uri = team_uri + '/' + current_team['id'] #r = ucd.get( uri=current_team_uri ) #current_team_full = r.json() #print_team( current_team_full ) # Get roles #print( 'Get Roles') r = ucd.get( uri=role_uri ) if r.status_code != 200: ucd.debug_response( r ) return # Get the quick list of roles roles = r.json() print( 'Defined Roles: ' + ', '.join([ role['name'] for role in roles] ) ) #pprint( roles ) # Get Action Mappings only, otherwise they are included when you get the role # '/security/role/<id>/actionMappings' # Build a simple Role dictionary, slighly different than the version that # comes from just pulling the role /security/role/<id> as the actions are a # dictionary instead of a list for easier referencing instead of searching # and make the simple set operations possible role_dict = {} for role in roles: role_dict[ role['name'] ] = {} role_dict[ role['name'] ]['name'] = role['name'] role_dict[ role['name'] ]['id'] = role['id'] current_role_uri = '%s/%s/actionMappings' % (role_uri, role['id'] ) r = ucd.get( uri=current_role_uri ) #ucd.debug_response( r ) actions = r.json() action_dict = {} for cur_action in actions: action_dict[ cur_action['action']['id'] ] = cur_action['action'] role_dict[ role['name'] ]['actions'] = action_dict #pprint( actions ) #pprint( role_dict ) # Compare the roles if role_name1 in role_dict and role_name2 in role_dict: compare_roles( role_dict[ role_name1 ], role_dict[ role_name2 ] ) else: print('Either %s or %s are not valid Roles' % (role_name1, role_name2) )
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help','server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ( '-s', '--server'): base_url = a elif o in ( '-u', '--user'): user = a elif o in ( '-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() ucd = ucdclient.ucdclient( base_url, user, password , debug ) # Just by name # /rest/agent?rowsPerPage=250&pageNumber=1&orderField=name&sortType=asc&filterFields=name&filterValue_name=ucd&filterType_name=like&filterClass_name=String # By name and status # /rest/agent?rowsPerPage=250&pageNumber=1&orderField=name&sortType=asc&filterFields=name&filterFields=status&filterValue_name=ucd&filterType_name=like&filterClass_name=String&filterValue_status=ONLINE&filterType_status=eq&filterClass_status=Enum # By name, status, and version # /rest/agent?rowsPerPage=250&pageNumber=1&orderField=name&sortType=asc&filterFields=name&filterFields=status&filterFields=agentVersion&filterValue_name=ucd&filterType_name=like&filterClass_name=String&filterValue_status=ONLINE&filterType_status=eq&filterClass_status=Enum&filterValue_agentVersion=6&filterType_agentVersion=like&filterClass_agentVersion=String rows_per_page = 1 status = 'OFFLINE' agents_offline = '/rest/agent?rowsPerPage=%d&pageNumber=1&orderField=name&sortType=asc&filterFields=status&filterValue_status=%s&filterType_status=eq&filterClass_status=Enum' % ( rows_per_page, status ) agents_offline = '/rest/agent?orderField=name&sortType=asc&filterFields=status&filterValue_status=%s&filterType_status=eq&filterClass_status=Enum' % ( status ) print( 'Checking for offline agents with query: %s' % ( agents_offline ) ) agents = ucd.get_json( uri=agents_offline ) print( 'Found %d agents offline.' % ( len(agents) ) ) for agent in agents: # http://www-01.ibm.com/support/knowledgecenter/SS4GSP_6.2.0/com.ibm.udeploy.api.doc/topics/rest_cli_agentcli_delete.html?lang=en r = ucd.delete( uri='/cli/agentCLI?agent=%s' % ( agent['id'] ) ) if r.status_code != 204: print( 'Error deleting agent %s, error %s' % (agent['id'], r.text )) ucd.debug_response( r )
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help', 'server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ('-s', '--server'): base_url = a elif o in ('-u', '--user'): user = a elif o in ('-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() ucd = ucdclient.ucdclient(base_url, user, password, debug) component_name = 'SVN Component 1' # Get list of existing components components = ucd.get_json('/rest/deploy/component') existing_component_names = [comp['name'] for comp in components] if component_name in existing_component_names: for comp in components: if component_name == comp['name']: print('Found existing component.') comp_id = comp['id'] continue else: print('Creating new component.') new_component_body = { 'name': component_name, 'description': ' Testing the programmatic creation of components', 'sourceConfigPlugin': 'Subversion', 'properties': { 'SubversionComponentProperties/repoUrl': 'svn://localhost/component1/tags', 'SubversionComponentProperties/watchTags': 'true', 'SubversionComponentProperties/includes': '**/*', 'SubversionComponentProperties/excludes': '', 'SubversionComponentProperties/user': '******', 'SubversionComponentProperties/password': '******', 'SubversionComponentProperties/svnPath': 'svn', 'SubversionComponentProperties/saveFileExecuteBits': 'false', 'SubversionComponentProperties/extensions': '', }, 'importAutomatically': 'false', 'useVfs': 'true', 'defaultVersionType': 'FULL', } body = json.dumps(new_component_body) r = ucd.put(uri='/cli/component/create', data=body) if r.status_code == 200: print('Submitted component successfully!') comp_id = r.json()['id'] else: ucd.debug_response(r) raise Exception('Failed to Create or Update Component exiting.') # Add any Tags we need to for this component tag_uri = '/cli/component/tag?component=%s&tag=%s' % (comp_id, 'CompTag0') r = ucd.put(tag_uri) if r.status_code == 204: print('Successfully added Tag to component') else: ucd.debug_response(r) raise Exception('Failed to tag component') # Import new versions import_uri = '/rest/deploy/component/%s/integrate' % (comp_id) integrate_props = {'properties': {'versionOrTag': '1.0'}} body = json.dumps(integrate_props) r = ucd.put(uri=import_uri, data=body) if r.status_code == 200: print( 'Successfully submitted Version import request, check the Component Configuration page for more information.' ) else: ucd.debug_response(r) raise Exception('Failed to request import.')
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help','server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ( '-s', '--server'): base_url = a elif o in ( '-u', '--user'): user = a elif o in ( '-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # Peel and specfic arguments off the end for this call arg1, arg2 = sys.argv[-2:] ucd = ucdclient.ucdclient( base_url, user, password , debug ) agents = ucd.get_json( '/rest/agent' ) #pprint( agents ) # {"name":"ucdandr","agentId":"45bdeeda-a26e-4c85-85bf-0dbee7bdb890","parentId":"2dac4c05-d78b-4ad5-9c6e-dec3a9358aba"} name_regex = re.compile( 'ucd.*' ) tags = ['prd'] for agent in agents: pprint( agent ) if( re.match( name_regex, agent['name'] ) ): print( 'Found an agent matching the pattern: %s ' % (agent['name']) ) agent_tags = [ tag['name'] for tag in agent['tags'] ] # build sets and check length of union if len( set( i for i in tags) & set(i for i in agent_tags)): print( 'Found an agent with tags we are lookign for' ) print( 'Tags we want: ', tags ) print( ' Agent tags: ', agent_tags ) data = { "name": agent['name'], "agentId": agent['id'], "parentId": "2dac4c05-d78b-4ad5-9c6e-dec3a9358aba" } r = ucd.put( '/rest/resource/resource', data=json.dumps(data) ) pprint( r )
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help', 'server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ('-s', '--server'): base_url = a elif o in ('-u', '--user'): user = a elif o in ('-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # Peel and specfic arguments off the end for this call arg1, arg2 = sys.argv[-2:] ucd = ucdclient.ucdclient(base_url, user, password, debug) #snapshot_id = '683564c6-9ec7-4a5b-b78c-e01f383be7d1' snapshot_id = 'ab757d3c-c96e-47a6-b580-6b3aff8071bf' snapshot = ucd.get_json(uri='/rest/deploy/snapshot/%s' % (snapshot_id)) pprint(snapshot) versions = ucd.get_json(uri='/rest/deploy/snapshot/%s/versions' % (snapshot_id)) #pprint( versions ) #return print("\n#### Delete the Snapshot ###") if snapshot['active'] == 'True': response = ucd.delete(uri='/rest/deploy/snapshot/%s' % (snapshot_id)) if response.status_code != 204: print('ERROR: %s' % (response)) print("\n#### Iterate overs versions inside the Snapshot ####") for version in versions: #pprint( version ) for d_version in version['desiredVersions']: pprint(d_version) version_id = d_version['id'] version_name = d_version['name'] if version_id: print(version['name']) print('\t%s : %s' % (version_id, version_name)) response = ucd.delete(uri='/rest/deploy/snapshot/%s' % (snapshot_id)) if response.status_code != 200: print('ERROR deleting component %s : %s' % (version['name'], response.text))
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help', 'server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ('-s', '--server'): base_url = a elif o in ('-u', '--user'): user = a elif o in ('-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() ucd = ucdclient.ucdclient(base_url, user, password, debug) # Just by name # /rest/agent?rowsPerPage=250&pageNumber=1&orderField=name&sortType=asc&filterFields=name&filterValue_name=ucd&filterType_name=like&filterClass_name=String # By name and status # /rest/agent?rowsPerPage=250&pageNumber=1&orderField=name&sortType=asc&filterFields=name&filterFields=status&filterValue_name=ucd&filterType_name=like&filterClass_name=String&filterValue_status=ONLINE&filterType_status=eq&filterClass_status=Enum # By name, status, and version # /rest/agent?rowsPerPage=250&pageNumber=1&orderField=name&sortType=asc&filterFields=name&filterFields=status&filterFields=agentVersion&filterValue_name=ucd&filterType_name=like&filterClass_name=String&filterValue_status=ONLINE&filterType_status=eq&filterClass_status=Enum&filterValue_agentVersion=6&filterType_agentVersion=like&filterClass_agentVersion=String rows_per_page = 1 status = 'OFFLINE' agents_offline = '/rest/agent?rowsPerPage=%d&pageNumber=1&orderField=name&sortType=asc&filterFields=status&filterValue_status=%s&filterType_status=eq&filterClass_status=Enum' % ( rows_per_page, status) agents_offline = '/rest/agent?orderField=name&sortType=asc&filterFields=status&filterValue_status=%s&filterType_status=eq&filterClass_status=Enum' % ( status) print('Checking for offline agents with query: %s' % (agents_offline)) agents = ucd.get_json(uri=agents_offline) print('Found %d agents offline.' % (len(agents))) for agent in agents: # http://www-01.ibm.com/support/knowledgecenter/SS4GSP_6.2.0/com.ibm.udeploy.api.doc/topics/rest_cli_agentcli_delete.html?lang=en r = ucd.delete(uri='/cli/agentCLI?agent=%s' % (agent['id'])) if r.status_code != 204: print('Error deleting agent %s, error %s' % (agent['id'], r.text)) ucd.debug_response(r)
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help', 'server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ('-s', '--server'): base_url = a elif o in ('-u', '--user'): user = a elif o in ('-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # Peel and specfic arguments off the end for this call arg1, arg2 = sys.argv[-2:] ucd = ucdclient.ucdclient(base_url, user, password, debug) # ... Do some stuff ... delete_tokens = False tokens_uri = '/security/authtoken' users_uri = '/security/user' # Get Current Tokens tokens = ucd.get_json(tokens_uri) pprint(tokens) # Create authtoken # Get users to get userId users = ucd.get_json('/security/user/?name=*') #print( users ) # Create a new token # admin - 11/5/2015 12:00 PM token_body = { 'userId': "20000000000000000000000001000000", 'description': "", 'host': "", 'expDate': "2015-11-05T06:00:00.000Z", 'expTime': "1970-01-01T18:00:00.000Z", 'expiration': 1446746400000, } # Create a new token r = ucd.put(uri=tokens_uri, data=json.dumps(token_body)) token = r.json() pprint(token) # Test to see if we can update a token # tokenator - 11/9/15 9:30 AM token_body_updated = { 'id': token['id'], 'token': token['token'], 'userId': "18ea7889-76f2-4ea0-ab8a-43558b23f1ab", 'description': "Updated", 'host': "", 'expDate': "2015-11-09T06:00:00.000Z", 'expTime': "1970-01-01T15:30:00.000Z", 'expiration': 1447083000000, } token_uri = '%s/%s' % (tokens_uri, token['id']) r = ucd.put(uri=token_uri, data=json.dumps(token_body_updated)) # Nope ucd.debug_response(r) #token = r.json() #pprint( token ) #return # Delete all the current tokens tokens = ucd.get_json(tokens_uri) #print( tokens ) if delete_tokens: for token in tokens: token_uri = '%s/%s' % (tokens_uri, token['id']) r = ucd.delete(token_uri) ucd.debug_response(r)
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help','server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ( '-s', '--server'): base_url = a elif o in ( '-u', '--user'): user = a elif o in ( '-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() ucd = ucdclient.ucdclient( base_url, user, password , debug ) component_name = 'SVN Component 1' # Get list of existing components components = ucd.get_json( '/rest/deploy/component') existing_component_names = [ comp['name'] for comp in components ] if component_name in existing_component_names: for comp in components: if component_name == comp['name']: print( 'Found existing component.') comp_id = comp['id'] continue else: print( 'Creating new component.') new_component_body = { 'name' : component_name, 'description' : ' Testing the programmatic creation of components', 'sourceConfigPlugin' : 'Subversion', 'properties': { 'SubversionComponentProperties/repoUrl' : 'svn://localhost/component1/tags', 'SubversionComponentProperties/watchTags' : 'true', 'SubversionComponentProperties/includes' : '**/*', 'SubversionComponentProperties/excludes' : '', 'SubversionComponentProperties/user' : 'admin', 'SubversionComponentProperties/password' : 'admin', 'SubversionComponentProperties/svnPath' : 'svn', 'SubversionComponentProperties/saveFileExecuteBits' : 'false', 'SubversionComponentProperties/extensions' : '', }, 'importAutomatically' : 'false', 'useVfs' : 'true', 'defaultVersionType' : 'FULL', } body = json.dumps( new_component_body ) r = ucd.put( uri='/cli/component/create', data=body ) if r.status_code == 200: print( 'Submitted component successfully!') comp_id = r.json()['id'] else: ucd.debug_response( r ) raise Exception( 'Failed to Create or Update Component exiting.') # Add any Tags we need to for this component tag_uri = '/cli/component/tag?component=%s&tag=%s' % ( comp_id, 'CompTag0') r = ucd.put( tag_uri ) if r.status_code == 204: print( 'Successfully added Tag to component') else: ucd.debug_response( r ) raise Exception( 'Failed to tag component') # Import new versions import_uri = '/rest/deploy/component/%s/integrate' % ( comp_id ) integrate_props = { 'properties' : { 'versionOrTag' : '1.0' } } body = json.dumps( integrate_props ) r = ucd.put( uri=import_uri, data=body ) if r.status_code == 200: print( 'Successfully submitted Version import request, check the Component Configuration page for more information.') else: ucd.debug_response( r ) raise Exception( 'Failed to request import.')
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help','server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ( '-s', '--server'): base_url = a elif o in ( '-u', '--user'): user = a elif o in ( '-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # Peel and specfic arguments off the end for this call arg1, arg2 = sys.argv[-2:] ucd = ucdclient.ucdclient( base_url, user, password , debug ) # ... Do some stuff ... delete_tokens = False tokens_uri = '/security/authtoken' users_uri = '/security/user' # Get Current Tokens tokens = ucd.get_json( tokens_uri ) pprint( tokens ) # Create authtoken # Get users to get userId users = ucd.get_json( '/security/user/?name=*' ) #print( users ) # Create a new token # admin - 11/5/2015 12:00 PM token_body = { 'userId': "20000000000000000000000001000000", 'description': "", 'host': "", 'expDate': "2015-11-05T06:00:00.000Z", 'expTime': "1970-01-01T18:00:00.000Z", 'expiration': 1446746400000, } # Create a new token r = ucd.put( uri=tokens_uri, data=json.dumps(token_body) ) token = r.json() pprint( token ) # Test to see if we can update a token # tokenator - 11/9/15 9:30 AM token_body_updated = { 'id': token['id'], 'token': token['token'], 'userId': "18ea7889-76f2-4ea0-ab8a-43558b23f1ab", 'description': "Updated", 'host': "", 'expDate': "2015-11-09T06:00:00.000Z", 'expTime': "1970-01-01T15:30:00.000Z", 'expiration': 1447083000000, } token_uri = '%s/%s' % (tokens_uri, token['id']) r = ucd.put( uri=token_uri, data=json.dumps(token_body_updated) ) # Nope ucd.debug_response( r ) #token = r.json() #pprint( token ) #return # Delete all the current tokens tokens = ucd.get_json( tokens_uri ) #print( tokens ) if delete_tokens: for token in tokens: token_uri = '%s/%s' % (tokens_uri, token['id']) r = ucd.delete( token_uri ) ucd.debug_response( r )
def __main__(): global debug, user, password, base_url try: #opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:a:ve:", ['help','server=', 'user='******'password='******'application=','environment=']) opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:a:ve:P:S:", [ 'help', 'server=', 'user='******'password='******'application=', 'environment=', 'process=', 'snapshot=' ]) except getopt.GetoptError as err: # print help information and exit: print(err) # will print something like "option -a not recognized" usage() sys.exit(2) for o, a in opts: if o == '-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ('-s', '--server'): base_url = a elif o in ('-u', '--user'): user = a elif o in ('-p', '--password'): password = a elif o in ('-a', '--application'): application = a elif o in ('-e', '--environment'): environment = a elif o in ('-P', '--process'): process = a elif o in ('-S', '--snapshot'): snapshot = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() ucd = ucdclient.ucdclient(base_url, user, password, debug) # process = 'install' # snapshot = '0.7.020170412' request_body = { 'application': application, 'applicationProcess': process, 'environment': environment, 'snapshot': snapshot, 'onlyChanged': 'false' } print '%s: Calling %s on %s environment with snapshot %s' % ( request_body['application'], request_body['applicationProcess'], request_body['environment'], request_body['snapshot']) pprint(request_body) request_id = ucd.put_json(uri='/cli/applicationProcessRequest/request', data=json.dumps(request_body)) print request_id
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help', 'server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ('-s', '--server'): base_url = a elif o in ('-u', '--user'): user = a elif o in ('-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # hard coded rest_uri = '/rest/plugin/automationPlugin' rest_uri_src = '/rest/plugin/sourceConfigPlugins' plugin_dir = '/Volumes/Scribe/home/[email protected]/clients/35143 - Macys/20160623/plugins/' verbose = 0 delete_plugins = 0 # Peel and specfic arguments off the end for this call arg1, arg2 = sys.argv[-2:] ucd = ucdclient.ucdclient(base_url, user, password, debug) ## Look at the current plugins current_plugins = ucd.get_json(rest_uri) for plugin in current_plugins: # {u'description': u'This plugin provides steps for launching instances, terminating instances, associating ip addresses, waiting for instances, creating a security group, and getting the public DNS for the Amazon EC2 tool.', u'pluginId': u'com.urbancode.air.plugin.AmazonEC2', u'versionNumber': 4, u'version': u'4.423632', u'ghostedDate': 0, u'id': u'4db7cc91-6993-4287-8cdd-a1e80ec1f5be', u'name': u'AmazonEC2'} print('%s %s %s(%s) ' % (plugin['pluginId'], plugin['name'], plugin['versionNumber'], plugin['version'])) #pprint( plugin ) # if delete_plugins: # print 'Deleting plugin.' # r = s.delete( url = base_url + rest_uri + '/' + plugin['id'] ) # # print_h( r, s ) # if r.status_code == 200: # print 'Success!' # else: # print 'Something went wrong...' # print_h( r, s ) installed_plugins = [plugin['pluginId'] for plugin in current_plugins] file_list = os.listdir(plugin_dir) plugins_list = [ cur_file for cur_file in file_list if cur_file.endswith('.zip') ] #post_url = base_url + rest_uri + "?UCD_SESSION_KEY=" + ucd.session.headers['UCD_SESSION_KEY'] post_url = '%s%s?UCD_SESSION_KEY=%s' % ( base_url, rest_uri, ucd.session.headers['UCD_SESSION_KEY']) for cur_plugin in plugins_list: plugin_archive = zipfile.ZipFile(os.path.join(plugin_dir, cur_plugin), 'r') info_xml = plugin_archive.read('info.xml') plugin_type = re.search('<integration type="(.*)"/>', info_xml).group(1) plugin_description = re.search( '<tool-description>(.*)</tool-description>', info_xml).group(1).strip() plugin_release_version = re.search( '<release-version>(.*)</release-version>', info_xml).group(1).strip() #print info_xml # <identifier version="6" id="com.urbancode.air.plugin.MavenResolve" name="Maven Resolve"/> plugin_xml = plugin_archive.read('plugin.xml') m = re.search('<identifier version="(.*)" id="(.*)" name="(.*)"/>', plugin_xml) plugin_major_version = m.group(1).strip() plugin_id = m.group(2).strip() plugin_name = m.group(3).strip() #print( ' %s %s %s ' % (plugin_type, plugin_description, plugin_release_version ) ) #print( ' %s %s %s ' % (plugin_major_version, plugin_id, plugin_name ) ) print(' %s %s %s(%s) %s' % (plugin_id, plugin_name, plugin_major_version, plugin_release_version, plugin_type)) if plugin_id in installed_plugins: print('Already installed, lets check the version') # FIXME: this will prevent any version updates from being applied. continue else: print " Uploading: ", cur_plugin files = { 'file': (cur_plugin, open(os.path.join(plugin_dir, cur_plugin), 'rb'), 'application/zip', { 'Expires': '0' }) } r = ucd.session.post(post_url, files=files) if r.status_code == 200: print 'Success!' else: print 'Something went wrong...' ucd.debug_response(r)
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help', 'server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ('-s', '--server'): base_url = a elif o in ('-u', '--user'): user = a elif o in ('-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # Peel and specfic arguments off the end for this call arg1, arg2 = sys.argv[-2:] ucd = ucdclient.ucdclient(base_url, user, password, debug) agents = ucd.get_json('/rest/agent') #pprint( agents ) # {"name":"ucdandr","agentId":"45bdeeda-a26e-4c85-85bf-0dbee7bdb890","parentId":"2dac4c05-d78b-4ad5-9c6e-dec3a9358aba"} name_regex = re.compile('ucd.*') tags = ['prd'] for agent in agents: pprint(agent) if (re.match(name_regex, agent['name'])): print('Found an agent matching the pattern: %s ' % (agent['name'])) agent_tags = [tag['name'] for tag in agent['tags']] # build sets and check length of union if len(set(i for i in tags) & set(i for i in agent_tags)): print('Found an agent with tags we are lookign for') print('Tags we want: ', tags) print(' Agent tags: ', agent_tags) data = { "name": agent['name'], "agentId": agent['id'], "parentId": "2dac4c05-d78b-4ad5-9c6e-dec3a9358aba" } r = ucd.put('/rest/resource/resource', data=json.dumps(data)) pprint(r)
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help','server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ( '-s', '--server'): base_url = a elif o in ( '-u', '--user'): user = a elif o in ( '-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # hard coded rest_uri = '/rest/plugin/automationPlugin' rest_uri_src= '/rest/plugin/sourceConfigPlugins' plugin_dir = '/Volumes/Scribe/home/[email protected]/clients/35143 - Macys/20160623/plugins/' verbose = 0 delete_plugins = 0 # Peel and specfic arguments off the end for this call arg1, arg2 = sys.argv[-2:] ucd = ucdclient.ucdclient( base_url, user, password , debug ) ## Look at the current plugins current_plugins = ucd.get_json( rest_uri ) for plugin in current_plugins: # {u'description': u'This plugin provides steps for launching instances, terminating instances, associating ip addresses, waiting for instances, creating a security group, and getting the public DNS for the Amazon EC2 tool.', u'pluginId': u'com.urbancode.air.plugin.AmazonEC2', u'versionNumber': 4, u'version': u'4.423632', u'ghostedDate': 0, u'id': u'4db7cc91-6993-4287-8cdd-a1e80ec1f5be', u'name': u'AmazonEC2'} print( '%s %s %s(%s) ' % (plugin['pluginId'], plugin['name'], plugin['versionNumber'], plugin['version']) ) #pprint( plugin ) # if delete_plugins: # print 'Deleting plugin.' # r = s.delete( url = base_url + rest_uri + '/' + plugin['id'] ) # # print_h( r, s ) # if r.status_code == 200: # print 'Success!' # else: # print 'Something went wrong...' # print_h( r, s ) installed_plugins = [ plugin['pluginId'] for plugin in current_plugins ] file_list = os.listdir( plugin_dir ); plugins_list = [ cur_file for cur_file in file_list if cur_file.endswith('.zip') ] #post_url = base_url + rest_uri + "?UCD_SESSION_KEY=" + ucd.session.headers['UCD_SESSION_KEY'] post_url = '%s%s?UCD_SESSION_KEY=%s' % (base_url, rest_uri, ucd.session.headers['UCD_SESSION_KEY'] ) for cur_plugin in plugins_list: plugin_archive = zipfile.ZipFile( os.path.join( plugin_dir, cur_plugin), 'r') info_xml = plugin_archive.read('info.xml') plugin_type = re.search( '<integration type="(.*)"/>', info_xml).group(1) plugin_description = re.search( '<tool-description>(.*)</tool-description>', info_xml).group(1).strip() plugin_release_version = re.search( '<release-version>(.*)</release-version>', info_xml).group(1).strip() #print info_xml # <identifier version="6" id="com.urbancode.air.plugin.MavenResolve" name="Maven Resolve"/> plugin_xml = plugin_archive.read('plugin.xml') m = re.search( '<identifier version="(.*)" id="(.*)" name="(.*)"/>', plugin_xml ) plugin_major_version = m.group(1).strip() plugin_id = m.group(2).strip() plugin_name = m.group(3).strip() #print( ' %s %s %s ' % (plugin_type, plugin_description, plugin_release_version ) ) #print( ' %s %s %s ' % (plugin_major_version, plugin_id, plugin_name ) ) print( ' %s %s %s(%s) %s' % ( plugin_id, plugin_name, plugin_major_version, plugin_release_version, plugin_type ) ) if plugin_id in installed_plugins: print( 'Already installed, lets check the version') # FIXME: this will prevent any version updates from being applied. continue else: print " Uploading: ", cur_plugin files = {'file': ( cur_plugin , open( os.path.join( plugin_dir, cur_plugin) , 'rb'), 'application/zip', {'Expires': '0'})} r = ucd.session.post(post_url, files=files) if r.status_code == 200: print 'Success!' else: print 'Something went wrong...' ucd.debug_response( r )
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help', 'server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ('-s', '--server'): base_url = a elif o in ('-u', '--user'): user = a elif o in ('-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() # define here if you want to do this static-like #role_name1 = 'Observer' #role_name2 = 'Stakeholder' # Pull the last two items off the arguments list role_name1, role_name2 = sys.argv[-2:] ucd = ucdclient.ucdclient(base_url, user, password, debug) # Get teams #print( 'Get Teams') #r = ucd.get( uri=team_uri ) #teams = r.json() #for current_team in teams: #current_team_uri = team_uri + '/' + current_team['id'] #r = ucd.get( uri=current_team_uri ) #current_team_full = r.json() #print_team( current_team_full ) # Get roles #print( 'Get Roles') r = ucd.get(uri=role_uri) if r.status_code != 200: ucd.debug_response(r) return # Get the quick list of roles roles = r.json() print('Defined Roles: ' + ', '.join([role['name'] for role in roles])) #pprint( roles ) # Get Action Mappings only, otherwise they are included when you get the role # '/security/role/<id>/actionMappings' # Build a simple Role dictionary, slighly different than the version that # comes from just pulling the role /security/role/<id> as the actions are a # dictionary instead of a list for easier referencing instead of searching # and make the simple set operations possible role_dict = {} for role in roles: role_dict[role['name']] = {} role_dict[role['name']]['name'] = role['name'] role_dict[role['name']]['id'] = role['id'] current_role_uri = '%s/%s/actionMappings' % (role_uri, role['id']) r = ucd.get(uri=current_role_uri) #ucd.debug_response( r ) actions = r.json() action_dict = {} for cur_action in actions: action_dict[cur_action['action']['id']] = cur_action['action'] role_dict[role['name']]['actions'] = action_dict #pprint( actions ) #pprint( role_dict ) # Compare the roles if role_name1 in role_dict and role_name2 in role_dict: compare_roles(role_dict[role_name1], role_dict[role_name2]) else: print('Either %s or %s are not valid Roles' % (role_name1, role_name2))
def __main__(): global debug, user, password, base_url try: opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:v", ['help', 'server=', 'user='******'password='******'-v': debug = True elif o in ('-h', '--help'): usage() sys.exit() elif o in ('-s', '--server'): base_url = a elif o in ('-u', '--user'): user = a elif o in ('-p', '--password'): password = a else: assert False, "unhandled option" usage() sys.exit() if not base_url or not password: print('Missing required arguments') usage() sys.exit() ucd = ucdclient.ucdclient(base_url, user, password, debug) props = {} # Loop over all apps app_rest_uri = '/rest/deploy/application' applications = ucd.get_json(app_rest_uri) # Filter down to a specific app that I want by name, could also do something like # this with tags if desired... #filter_app_name = 'UCD App' #applications = [ app for app in applications if app['name'] == filter_app_name ] for app in applications: cur_app = {} app_name = app['name'] app_id = app['id'] props[app_name] = {'name': app_name, 'id': app_id} # Get app properties app_properties = ucd.get_json( '/cli/application/getProperties?application=' + app_id) app['properties'] = app_properties # Get all components for the current application, but just take what I want from the component obj via a dict comprehension components = ucd.get_json('/rest/deploy/application' + '/' + app_id + '/components') components = [{ 'name': component['name'], 'id': component['id'] } for component in components] for comp in components: current_component = ucd.get_json( '/cli/component/getProperties?component=' + comp['id']) comp['properties'] = current_component # Get processes and iterate comp_processes = ucd.get_json('/rest/deploy/component/' + comp['id'] + '/processes/false') comp_processes = [{ 'name': process['name'], 'id': process['id'] } for process in comp_processes] for comp_process in comp_processes: #comp_processes = ucd.get_json( '/cli/componentProcess/info?component=' + comp['id'] +'&componentProcess=' + comp_process['name'] ) # TODO: Get properties for the current process comp_process['properties'] = [] comp['processes'] = comp_processes app['components'] = components # Loop over each process for the current application # TODO: not sure how to get these props? processes = ucd.get_json('/rest/deploy/application' + '/' + app_id + '/processes/' + 'false') for process in processes: current_processes = ucd.get_json( '/rest/deploy/applicationProcess/' + process['id'] + '/' + str(process['version'])) process['properties'] = current_processes app['processes'] = [] # Loop over each environment for the current application, simplify output environments = ucd.get_json('/rest/deploy/application' + '/' + app_id + '/environments/' + 'false') environments = [{ 'name': environment['name'], 'id': environment['id'] } for environment in environments] for env in environments: current_env = ucd.get_json('/rest/deploy/environment/' + env['id']) # Get environment properties env_properties = ucd.get_json( '/cli/environment/getProperties?environment=' + env['id']) env['properties'] = env_properties # Get environment component properties, requires component list to check with env_comp_properties = {} for component in components: cur_env_comp_properties = ucd.get_json( '/cli/environment/componentProperties?environment=' + env['id'] + '&component=' + component['id']) env_comp_properties[ component['name']] = cur_env_comp_properties env['compProperties'] = env_comp_properties # Get all resources for current environment base_resources = ucd.get_json( '/cli/environment/getBaseResources?environment=' + env['id']) base_resources = [{ 'id': resource['id'], 'name': resource['name'] } for resource in base_resources] # print( base_resources ) for resource in base_resources: resource_properties = ucd.get_json( '/cli/resource/getProperties?resource=' + resource['id']) resource['properties'] = resource_properties env['resources'] = base_resources app['environments'] = environments # For reference you can inspect the dict blob I have assembled # pprint( applications ) # pprint( applications, depth=3 ) with open('properties.html', 'w+') as outfile: outfile.write("<html><head></head><body>") for app in applications: #pprint( app ) outfile.write("<hr/>") outfile.write("<h3>" + app['name'] + " (" + app['id'] + ")</h3>") outfile.write("<table border='1'>") outfile.write("<tr>") outfile.write("<td> Scope </td>") outfile.write("<td> Location </td>") outfile.write("<td> Name </td>") outfile.write("<td> Value </td>") outfile.write("<td> Description </td>") outfile.write("</tr>") for app_properties in app['properties']: outfile.write("<tr>") outfile.write("<td> application </td>") outfile.write("<td>" + app['name'] + " </td>") outfile.write("<td>" + app_properties['name'] + "</td>") outfile.write("<td>" + app_properties['value'] + "</td>") outfile.write("<td>" + app_properties['description'] + "</td>") outfile.write("</tr>") for component in app['components']: for component_properties in component['properties']: outfile.write("<td> component </td>") outfile.write("<td> " + component['name'] + " </td>") outfile.write("<td>" + component_properties['name'] + "</td>") outfile.write("<td>" + component_properties['value'] + "</td>") outfile.write("<td>" + component_properties['description'] + "</td>") outfile.write("</tr>") # For each component process for component_process in component['processes']: for component_process_properties in component_process[ 'properties']: outfile.write("<td> component process </td>") outfile.write("<td> " + component['name'] + "/" + component_process['name'] + " </td>") outfile.write("<td>" + component_process_properties['name'] + "</td>") outfile.write("<td>" + component_process_properties['value'] + "</td>") outfile.write( "<td>" + component_process_properties['description'] + "</td>") outfile.write("</tr>") for environment in app['environments']: # for cur_prop in environment['properties']: outfile.write("<td> environment </td>") outfile.write("<td>" + environment['name'] + "</td>") outfile.write("<td>" + cur_prop['name'] + "</td>") outfile.write("<td>" + cur_prop['value'] + "</td>") outfile.write("<td>" + cur_prop['description'] + "</td>") outfile.write("</tr>") # for comp_name, env_comp_props in environment[ 'compProperties'].iteritems(): for cur_prop in env_comp_props: outfile.write("<td> environment component </td>") outfile.write("<td>" + environment['name'] + " / " + comp_name + "</td>") outfile.write("<td>" + cur_prop['name'] + "</td>") outfile.write("<td>" + cur_prop['value'] + "</td>") outfile.write("<td>" + cur_prop['description'] + "</td>") outfile.write("</tr>") # for resource in environment['resources']: for cur_prop in resource['properties']: outfile.write("<td> resource </td>") outfile.write("<td>" + resource['name'] + "</td>") outfile.write("<td>" + cur_prop['name'] + "</td>") outfile.write("<td>" + cur_prop['value'] + "</td>") outfile.write("<td>" + cur_prop['description'] + "</td>") outfile.write("</tr>") # # pprint( app['processes'], depth=2 ) # for process in app['processes']: # pprint( process['properties'] ) for cur_prop in process['properties']: outfile.write("<td> process </td>") outfile.write("<td>" + process['name'] + "</td>") outfile.write("<td>" + cur_prop['name'] + "</td>") outfile.write("<td>" + cur_prop['value'] + "</td>") outfile.write("<td>" + cur_prop['description'] + "</td>") outfile.write("</tr>") outfile.write("</table>") outfile.write("</body></html>")