예제 #1
0
def __main__():

    # hard coded
    user = '******'
    password = '******'
    base_url = 'https://192.168.1.117/ucd01'

    applications_uri = '/cli/deploy/application'
    ucd = ucclient(base_url, user, password, 0)

    request_uri = '/rest/process/request'
    # process_body = { 'id': '58bf971b-1c0d-4d44-9f34-7617e9026278', 'processPath': 'processes/58bf971b-1c0d-4d44-9f34-7617e9026278', 'processVersion': '2', 'resource': '/Application1/DEV/local' }
    process_body = {
        'processId': '58bf971b-1c0d-4d44-9f34-7617e9026278',
        'processVersion': '3',
        'resource': '/Application1/DEV/local',
        'properties': [{
            'prop1': 'prop1Value'
        }],
        'prop1': 'prop1Value'
    }
    #process_body = {}
    body = json.dumps(process_body)
    #print( 'Body: %s ' % ( body ) )
    #r = ucd.post( uri=request_uri, data=body )
    #r = ucd.post( uri=request_uri, data=body )
    #ucd.debug_response( r )

    # /rest/deploy/applicationProcessRequest/ef49f792-6eaa-4b40-9590-30853948f382
    # /rest/approval/approval/da94fcea-d39e-44fd-a010-0f34ec65f3d5/withTrace

    process_request_id = '3a4ac63e-7823-469a-a9be-5901e3e523ca'
    process_request_uri = '/rest/process/request/%s/trace' % (
        process_request_id)

    process_request_id = 'ef49f792-6eaa-4b40-9590-30853948f382'
    process_request_uri = '/rest/deploy/applicationProcessRequest/%s' % (
        process_request_id)

    r = ucd.get(uri=process_request_uri)

    if r.status_code != 200:
        ucd.debug_response(r)
        raise Exception('Failed to get Process Request Information')

    process_request = r.json()
    pprint(process_request)
def __main__():

    # hard coded
    user = "******"
    password = "******"
    base_url = "https://192.168.1.117/ucd01"

    applications_uri = "/cli/deploy/application"
    ucd = ucclient(base_url, user, password, 0)

    request_uri = "/rest/process/request"
    # process_body = { 'id': '58bf971b-1c0d-4d44-9f34-7617e9026278', 'processPath': 'processes/58bf971b-1c0d-4d44-9f34-7617e9026278', 'processVersion': '2', 'resource': '/Application1/DEV/local' }
    process_body = {
        "processId": "58bf971b-1c0d-4d44-9f34-7617e9026278",
        "processVersion": "3",
        "resource": "/Application1/DEV/local",
        "properties": [{"prop1": "prop1Value"}],
        "prop1": "prop1Value",
    }
    # process_body = {}
    body = json.dumps(process_body)
    # print( 'Body: %s ' % ( body ) )
    # r = ucd.post( uri=request_uri, data=body )
    # r = ucd.post( uri=request_uri, data=body )
    # ucd.debug_response( r )

    # /rest/deploy/applicationProcessRequest/ef49f792-6eaa-4b40-9590-30853948f382
    # /rest/approval/approval/da94fcea-d39e-44fd-a010-0f34ec65f3d5/withTrace

    process_request_id = "3a4ac63e-7823-469a-a9be-5901e3e523ca"
    process_request_uri = "/rest/process/request/%s/trace" % (process_request_id)

    process_request_id = "ef49f792-6eaa-4b40-9590-30853948f382"
    process_request_uri = "/rest/deploy/applicationProcessRequest/%s" % (process_request_id)

    r = ucd.get(uri=process_request_uri)

    if r.status_code != 200:
        ucd.debug_response(r)
        raise Exception("Failed to get Process Request Information")

    process_request = r.json()
    pprint(process_request)
예제 #3
0
def __main__():

    # hard coded
    user = '******'
    password = '******'
    base_url = 'https://192.168.1.117'

    uri_security_group = '/security/group'
    delete_from_auth_realm_name = 'TestAuthRealm'

    ucd = ucclient(base_url, user, password, 0)

    r = ucd.get(uri=uri_security_group)

    if r.status_code != 200:
        ucd.debug_response(r)
        raise Exception('Failed to get groups')

    groups = r.json()

    for group in groups:
        auth_realm_name = group['authorizationRealm']['name']
        #print( '%s %s %s' % ( group['name'] , group['id'], auth_realm_name ) )

        if auth_realm_name == delete_from_auth_realm_name:
            group_name = group['name']
            group_id = group['id']

            print('Found one to delete')
            print('%s %s %s' % (group_name, group_id, auth_realm_name))

            uri_delete_group = '%s/%s' % (uri_security_group, group_id)
            r = ucd.delete(uri=uri_delete_group)

            if r.status_code != 200:
                print('Error deleting Group %s with id %s' %
                      (group_name, group_id))
                ucd.debug_response(r)
def __main__():

  # hard coded
  user = '******'
  password = '******'
  base_url = 'https://192.168.1.117'

  uri_security_group = '/security/group'
  delete_from_auth_realm_name = 'TestAuthRealm'

  ucd = ucclient( base_url, user, password , 0)

  r = ucd.get( uri=uri_security_group )

  if r.status_code != 200:
    ucd.debug_response( r )
    raise Exception( 'Failed to get groups' )

  groups = r.json()

  for group in groups:
    auth_realm_name = group['authorizationRealm']['name']
    #print( '%s %s %s' % ( group['name'] , group['id'], auth_realm_name ) )

    if auth_realm_name == delete_from_auth_realm_name:
      group_name = group['name']
      group_id = group['id']

      print( 'Found one to delete' )
      print( '%s %s %s' % ( group_name , group_id, auth_realm_name ) )

      uri_delete_group = '%s/%s' % ( uri_security_group, group_id )
      r = ucd.delete( uri=uri_delete_group )

      if r.status_code != 200:
        print( 'Error deleting Group %s with id %s' % ( group_name, group_id ) )
        ucd.debug_response( r )
def __main__():

    # hard coded
    user = '******'
    password = '******'
    base_url = 'https://192.168.1.117'
    ucd = ucclient(base_url, user, password, debug=0)

    team_name = 'Team1'
    new_team_uri = '/cli/team/create?team=%s&description=%s' % (team_name,
                                                                'description')

    r = ucd.put(uri=new_team_uri)
    print("Create new team response: %s" % (r.text))

    # get the existing applications
    #response = ucd.get( uri=applications_uri )
    # print( "Get existing applications: %s" % ( response.json() ) )
    '''
   Create a new Application
   http://www-01.ibm.com/support/knowledgecenter/SS4GSP_6.1.1/com.ibm.udeploy.api.doc/topics/rest_cli_application.html?lang=en

  '''
    applications_uri = '/cli/application/create'
    app_name = 'Application2'
    print "Try and create %s " % (app_name)
    new_app = {
        'name': app_name,
        'description': '',
        'notificationSchemeId': '',
        'enforceCompleteSnapshots': 'false',
        'teamMappings': [],
    }
    body = json.dumps(new_app)
    r = ucd.put(uri=applications_uri, data=body)
    print("Create new application response: %s " % (r.text))
    #ucd.debug_response( r )
    '''
   Get Application Properties
   http://www-01.ibm.com/support/knowledgecenter/SS4GSP_6.1.1/com.ibm.udeploy.api.doc/topics/rest_cli_application_getproperties_get.html?lang=en
   example:
   GET /cli/application/getProperties?application=JPetStore
  '''
    print "Get Application properties for %s " % (app_name)
    property_get_uri = '/cli/application/getProperties?application=%s' % (
        app_name)
    r = ucd.get(uri=property_get_uri)
    # 200 ok created
    # 400 if app already exists
    #ucd.debug_reponse( r )
    '''
   Set a property
   http://www-01.ibm.com/support/knowledgecenter/SS4GSP_6.1.1/com.ibm.udeploy.api.doc/topics/rest_cli_application_propvalue_put.html?lang=en
   example:
   PUT /cli/application/propValue?application=JPetStore&name=Prop4&value=value4
  '''
    prop_name = 'testing.property1'
    prop_value = 'test value'
    prop_is_secure = 'false'
    print "Set property %s to value %s on application %s" % (
        prop_name, prop_value, app_name)
    property_set_uri = '/cli/application/propValue?application=%s&name=%s&value=%s&isSecure=%s' % (
        app_name, prop_name, prop_value, prop_is_secure)
    r = ucd.put(uri=property_set_uri)
    # 200 ok on create
    # 200 on update if already exists
    ucd.debug_response(r)
    '''
   Get a specific property value
http://www-01.ibm.com/support/knowledgecenter/SS4GSP_6.1.1/com.ibm.udeploy.api.doc/topics/rest_cli_application_getproperty_get.html?lang=en
   GET /cli/application/getProperty?application=JPetStore&name=Prop4

  '''
    print "Get property %s value on application %s " % (prop_name, app_name)
    property_get_uri = '/cli/application/getProperty?application=%s&name=%s' % (
        app_name, prop_name)
    r = ucd.get(uri=property_get_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()

    # Peel and specfic arguments off the end for this call
    arg1, arg2 = sys.argv[-2:]

    ucr = ucclient(base_url, user, password, debug)

    start_time_ms = 1438401600000
    end_time_ms = 1441080000000

    c_start = time.gmtime(start_time_ms / 1000)
    c_end = time.gmtime(end_time_ms / 1000)

    print "Times: "
    print ts_tostr(c_start)
    print ts_tostr(c_end)

    query_uri = '?'
    # After
    attribute_name = 'scheduledDate'
    attribute_class = 'Long'

    query_uri += 'filterFields=%(name)s&filterType_%(name)s=%(type)s&filterClass_%(name)s=%(class)s&filterValue_%(name)s=%(value)d' % {
        'name': attribute_name,
        'type': 'ge',
        'class': attribute_class,
        'value': start_time_ms
    }
    #query_uri += 'filterFields=%(name)s&filterType_%(name)s=%(type)s&filterClass_%(name)s=%(class)s&filterValue_%(name)s=%(value)d' % { 'name': attribute_name, 'type': 'ge', 'class': attribute_class, 'value' : time.mktime( c_start ) }

    # Before
    #attribute_name = 'endTimeOverride' # Only works if the value has been overriden for completed deployments that this is not explicity set this filter fails
    attribute_name = 'scheduledDate'
    attribute_class = 'Long'

    query_uri += '&'
    query_uri += 'filterFields=%(name)s&filterType_%(name)s=%(type)s&filterClass_%(name)s=%(class)s&filterValue_%(name)s=%(value)d' % {
        'name': attribute_name,
        'type': 'lt',
        'class': attribute_class,
        'value': end_time_ms
    }
    #query_uri += 'filterFields=%(name)s&filterType_%(name)s=%(type)s&filterClass_%(name)s=%(class)s&filterValue_%(name)s=%(value)d' % { 'name': attribute_name, 'type': 'lt', 'class': attribute_class, 'value' : time.mktime( c_end ) }
    query_uri += '&orderField=%(name)s&sortType=asc' % {'name': attribute_name}

    #query_uri = ''

    query_uri = '/scheduledDeployments%s' % (query_uri)
    print "Getting scheduledDeployments calling %s " % (query_uri)

    r = ucr.get(query_uri)
    if r.status_code == 200:
        sds = r.json()
    else:
        ucr.debug_response(r)
        sys.exit(1)

    print 'Filtered results (%s)' % (r.headers['content-range'])
    filtered_results = [
        ts_tostr(time.gmtime(sd['scheduledDate'] / 1000)) for sd in sds
    ]

    print_sds(sds)

    query_uri = ''
    query_uri = '/scheduledDeployments%s' % (query_uri)
    r = ucr.get(query_uri)
    if r.status_code == 200:
        sds = r.json()
    else:
        ucr.debug_response(r)

    print 'Unfiltered results (%s)' % (r.headers['content-range'])
    unfiltered_results = [
        ts_tostr(time.gmtime(sd['scheduledDate'] / 1000)) for sd in sds
    ]
    print_sds(sds)

    print '\nDiff'
    for sd in unfiltered_results:
        if sd not in filtered_results:
            print sd

    get_specific_deployment = '/scheduledDeployments/7a15c95e-ccbe-47e0-a6af-20b8e9b79433'
def __main__():

  # hard coded
  user = '******'
  password = '******'
  base_url = 'https://192.168.1.117'
  ucd = ucclient( base_url, user, password , debug=0)



  team_name = 'Team1'
  new_team_uri = '/cli/team/create?team=%s&description=%s' % ( team_name, 'description')

  r = ucd.put( uri=new_team_uri )
  print( "Create new team response: %s" % ( r.text ) )

  # get the existing applications
  #response = ucd.get( uri=applications_uri )
  # print( "Get existing applications: %s" % ( response.json() ) )

  '''
   Create a new Application
   http://www-01.ibm.com/support/knowledgecenter/SS4GSP_6.1.1/com.ibm.udeploy.api.doc/topics/rest_cli_application.html?lang=en

  '''
  applications_uri = '/cli/application/create'
  app_name = 'Application2'
  print "Try and create %s " % ( app_name )
  new_app = {'name': app_name,'description':'','notificationSchemeId':'','enforceCompleteSnapshots':'false','teamMappings':[], }
  body = json.dumps( new_app )
  r = ucd.put(uri=applications_uri, data=body )
  print( "Create new application response: %s " % ( r.text ) )
  #ucd.debug_response( r )

  '''
   Get Application Properties
   http://www-01.ibm.com/support/knowledgecenter/SS4GSP_6.1.1/com.ibm.udeploy.api.doc/topics/rest_cli_application_getproperties_get.html?lang=en
   example:
   GET /cli/application/getProperties?application=JPetStore
  '''
  print "Get Application properties for %s " % (app_name)
  property_get_uri = '/cli/application/getProperties?application=%s' % ( app_name )
  r = ucd.get( uri=property_get_uri )
  # 200 ok created
  # 400 if app already exists
  #ucd.debug_reponse( r )

  '''
   Set a property
   http://www-01.ibm.com/support/knowledgecenter/SS4GSP_6.1.1/com.ibm.udeploy.api.doc/topics/rest_cli_application_propvalue_put.html?lang=en
   example:
   PUT /cli/application/propValue?application=JPetStore&name=Prop4&value=value4
  '''
  prop_name = 'testing.property1'
  prop_value = 'test value'
  prop_is_secure = 'false'
  print "Set property %s to value %s on application %s" % ( prop_name, prop_value, app_name )
  property_set_uri = '/cli/application/propValue?application=%s&name=%s&value=%s&isSecure=%s' % ( app_name, prop_name, prop_value, prop_is_secure )
  r = ucd.put( uri=property_set_uri )
  # 200 ok on create
  # 200 on update if already exists
  ucd.debug_response( r )

  '''
   Get a specific property value
http://www-01.ibm.com/support/knowledgecenter/SS4GSP_6.1.1/com.ibm.udeploy.api.doc/topics/rest_cli_application_getproperty_get.html?lang=en
   GET /cli/application/getProperty?application=JPetStore&name=Prop4

  '''
  print "Get property %s value on application %s " % ( prop_name, app_name )
  property_get_uri = '/cli/application/getProperty?application=%s&name=%s' % ( app_name, prop_name )
  r = ucd.get( uri=property_get_uri )
  ucd.debug_response( r )
def __main__():

  global debug, user, password, base_url

  mode = ''
  fname = ''

  try:
    opts, args = getopt.getopt(sys.argv[1:], "hs:u:p:m:f:v", ['help','server=', 'user='******'password='******'mode=', 'file='])
  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 ( '-m', '--mode' ):
      mode = a
    elif o in ( '-f', '--file' ):
      fname = a
    else:
      assert False, "unhandled option"
      usage()
      sys.exit()

  if not base_url or not password or not mode or not fname:
    print('Missing required arguments')
    usage()
    sys.exit()

  ucr = ucclient( base_url, user, password , 0 )

  if mode == 'export':
    # Pull the events and cleanup the data before writing it out
    events = ucr.get_json( '/events' )
    events_start = copy.deepcopy( events )
    #pprint( events_obj )

    write_csv( events_start, fname )

  elif mode == 'import':

    # Now lets' read it back out
    event_types = ucr.get_json( '/eventTypes' )

    events_readin = read_csv( event_types, fname=fname )

    for event in events_readin:
      # pprint( event )

      if 'id' in event:
        # looks like an existing event, try and update
        r = ucr.put( uri='/events/%s' % ( event['id'] ), data=json.dumps(event) )
        if r.status_code in [200, 201]:
          print( 'Successfully updated event: %s ' % ( r.json()['name'] ) )
        else:
          ucr.debug_response( r )
          print( 'Failed to update event: %s \nserver returned: %s' % ( event, r.text ) )
      else:
        r = ucr.post( uri='/events/', data=json.dumps(event) )
        if r.status_code  in [200, 201]:
          print( 'Sucessfully created new event: %s ' % ( r.json()['name'] ) )
        else:
          ucr.debug_response( r )
          print( 'Failed to submit event: %s \nserver returned: %s' % (event, r.text ) )

  # elif mode == 'test':
  #
  #   events_readin = read_csv( event_types, fname=fname )
  #
  #   ###
  #   ### Failing on dataCreated which is actually using the ms part of the epoch...
  #   ###
  #   if events_start == events_readin:
  #     print( 'yey!')
  #   else:
  #     print( 'boo, they ain\'t match')
  #     pprint( events_start[0] )
  #     pprint( events_readin[0] )

  else:
    print('Invalid mode: %s' % (mode) )
    usage()
    sys.exit()
예제 #9
0
def __main__():

    # hard coded
    user = '******'
    password = '******'
    base_url = 'https://192.168.1.117'

    applications_uri = '/cli/deploy/application'
    ucd = ucclient(base_url, user, password, 0)
    '''
   Create a new Application
   http://www-01.ibm.com/support/knowledgecenter/SS4GSP_6.1.1/com.ibm.udeploy.api.doc/topics/rest_cli_application.html?lang=en
  '''
    app_name = 'Application'
    applications_uri = '/cli/application/create'
    print "Try and create %s " % (app_name)
    new_app = {
        'name': app_name,
        'description': '',
        'notificationSchemeId': '',
        'enforceCompleteSnapshots': 'false',
        'teamMappings': [],
    }
    body = json.dumps(new_app)
    r = ucd.put(uri=applications_uri, data=body)
    print("Create new application response: %s %s " % (r.status_code, r.text))
    #ucd.debug_response( r )

    team_name = 'Team1'
    new_team_uri = '/cli/team/create?team=%s&description=%s' % (team_name,
                                                                'description')

    r = ucd.put(uri=new_team_uri)
    print("Create new team response: %s" % (r.text))
    '''
   Add Group to team
   /cli/teamsecurity/groups?group=<name>&team=<name>&type=<name of type>
   http://www-01.ibm.com/support/knowledgecenter/SS4GSP_6.1.1/com.ibm.udeploy.api.doc/topics/rest_cli_teamsecurity_groups_put.html
  '''
    group_name = 'Team1Group'
    role_name = 'ConfigEngineer'

    add_group_to_team_uri = '/cli/teamsecurity/groups?group=%s&team=%s&type=%s' % (
        group_name, team_name, role_name)
    r = ucd.put(uri=add_group_to_team_uri)
    '''
  PUT https://{hostname}:{port}
  /cli/application/teams?{parameters}
  '''

    type_name = 'Standard Application'
    add_team_to_app = '/cli/application/teams?application=%s&team=%s&type=%s' % (
        app_name, team_name, type_name)

    r = ucd.put(uri=add_team_to_app)
    print("Add Team to Application response: %s %s" % (r.status_code, r.text))
    '''
  Add a team to an Environment

  PUT https://{hostname}:{port}
  /cli/environment/teams?{parameters}

  '''
    env_name = 'DEV'

    add_team_to_env_uri = '/cli/environment/teams?application=%s&environment=%s&team=%s&type=' % (
        app_name, env_name, team_name)
    r = ucd.put(uri=add_team_to_env_uri)
    print("Add Team to Environment response: %s %s" % (r.status_code, r.text))
    '''
   Add Team to Resource

   PUT https://{hostname}:{port}
  /cli/resource/teams?{parameters}
  '''

    resource_path = '/Application1/DEV'
    team_id = '9e9c7267-4e08-455c-b8a7-4b64038553b2'

    add_team_to_resource_uri = '/cli/resource/teams?resource=%s&team=%s&type=' % (
        resource_path, team_id)
    r = ucd.put(uri=add_team_to_resource_uri)
    print("Add Team to Resource response: %s %s" % (r.status_code, r.text))
예제 #10
0
def __main__():

    global debug, user, password, base_url

    mode = ''
    fname = ''

    try:
        opts, args = getopt.getopt(
            sys.argv[1:], "hs:u:p:m:f:v",
            ['help', 'server=', 'user='******'password='******'mode=', 'file='])
    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 ('-m', '--mode'):
            mode = a
        elif o in ('-f', '--file'):
            fname = a
        else:
            assert False, "unhandled option"
            usage()
            sys.exit()

    if not base_url or not password or not mode or not fname:
        print('Missing required arguments')
        usage()
        sys.exit()

    ucr = ucclient(base_url, user, password, 0)

    if mode == 'export':
        # Pull the events and cleanup the data before writing it out
        events = ucr.get_json('/events')
        events_start = copy.deepcopy(events)
        #pprint( events_obj )

        write_csv(events_start, fname)

    elif mode == 'import':

        # Now lets' read it back out
        event_types = ucr.get_json('/eventTypes')

        events_readin = read_csv(event_types, fname=fname)

        for event in events_readin:
            # pprint( event )

            if 'id' in event:
                # looks like an existing event, try and update
                r = ucr.put(uri='/events/%s' % (event['id']),
                            data=json.dumps(event))
                if r.status_code in [200, 201]:
                    print('Successfully updated event: %s ' %
                          (r.json()['name']))
                else:
                    ucr.debug_response(r)
                    print('Failed to update event: %s \nserver returned: %s' %
                          (event, r.text))
            else:
                r = ucr.post(uri='/events/', data=json.dumps(event))
                if r.status_code in [200, 201]:
                    print('Sucessfully created new event: %s ' %
                          (r.json()['name']))
                else:
                    ucr.debug_response(r)
                    print('Failed to submit event: %s \nserver returned: %s' %
                          (event, r.text))

    # elif mode == 'test':
    #
    #   events_readin = read_csv( event_types, fname=fname )
    #
    #   ###
    #   ### Failing on dataCreated which is actually using the ms part of the epoch...
    #   ###
    #   if events_start == events_readin:
    #     print( 'yey!')
    #   else:
    #     print( 'boo, they ain\'t match')
    #     pprint( events_start[0] )
    #     pprint( events_readin[0] )

    else:
        print('Invalid mode: %s' % (mode))
        usage()
        sys.exit()
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:]

  ucr = ucclient( base_url, user, password , debug )


  start_time_ms = 1438401600000
  end_time_ms = 1441080000000

  c_start = time.gmtime( start_time_ms / 1000 )
  c_end = time.gmtime( end_time_ms / 1000 )

  print "Times: "
  print ts_tostr( c_start )
  print ts_tostr( c_end )

  query_uri = '?'
  # After
  attribute_name = 'scheduledDate'
  attribute_class = 'Long'

  query_uri += 'filterFields=%(name)s&filterType_%(name)s=%(type)s&filterClass_%(name)s=%(class)s&filterValue_%(name)s=%(value)d' % { 'name': attribute_name, 'type': 'ge', 'class': attribute_class, 'value' : start_time_ms }
  #query_uri += 'filterFields=%(name)s&filterType_%(name)s=%(type)s&filterClass_%(name)s=%(class)s&filterValue_%(name)s=%(value)d' % { 'name': attribute_name, 'type': 'ge', 'class': attribute_class, 'value' : time.mktime( c_start ) }

  # Before
  #attribute_name = 'endTimeOverride' # Only works if the value has been overriden for completed deployments that this is not explicity set this filter fails
  attribute_name = 'scheduledDate'
  attribute_class = 'Long'

  query_uri += '&'
  query_uri += 'filterFields=%(name)s&filterType_%(name)s=%(type)s&filterClass_%(name)s=%(class)s&filterValue_%(name)s=%(value)d' % { 'name': attribute_name, 'type': 'lt', 'class': attribute_class, 'value' : end_time_ms }
  #query_uri += 'filterFields=%(name)s&filterType_%(name)s=%(type)s&filterClass_%(name)s=%(class)s&filterValue_%(name)s=%(value)d' % { 'name': attribute_name, 'type': 'lt', 'class': attribute_class, 'value' : time.mktime( c_end ) }
  query_uri += '&orderField=%(name)s&sortType=asc' % { 'name' :attribute_name }

  #query_uri = ''

  query_uri = '/scheduledDeployments%s' %( query_uri)
  print "Getting scheduledDeployments calling %s " % ( query_uri )

  r = ucr.get( query_uri )
  if r.status_code == 200:
    sds = r.json()
  else:
    ucr.debug_response( r )
    sys.exit(1)

  print 'Filtered results (%s)' % ( r.headers['content-range'] )
  filtered_results = [ ts_tostr( time.gmtime(sd['scheduledDate']/1000) ) for sd in sds ]

  print_sds( sds )

  query_uri = ''
  query_uri = '/scheduledDeployments%s' %( query_uri)
  r = ucr.get( query_uri )
  if r.status_code == 200:
    sds = r.json()
  else:
    ucr.debug_response( r )


  print 'Unfiltered results (%s)' % ( r.headers['content-range'] )
  unfiltered_results = [ ts_tostr( time.gmtime(sd['scheduledDate']/1000) ) for sd in sds ]
  print_sds( sds )

  print '\nDiff'
  for sd in unfiltered_results:
    if sd not in filtered_results:
      print sd


  get_specific_deployment = '/scheduledDeployments/7a15c95e-ccbe-47e0-a6af-20b8e9b79433'
def __main__():

  # hard coded
  user = '******'
  password = '******'
  base_url = 'https://192.168.1.117'

  applications_uri = '/cli/deploy/application'
  ucd = ucclient( base_url, user, password , 0)

  '''
   Create a new Application
   http://www-01.ibm.com/support/knowledgecenter/SS4GSP_6.1.1/com.ibm.udeploy.api.doc/topics/rest_cli_application.html?lang=en
  '''
  app_name = 'Application'
  applications_uri = '/cli/application/create'
  print "Try and create %s " % ( app_name )
  new_app = {'name': app_name,'description':'','notificationSchemeId':'','enforceCompleteSnapshots':'false','teamMappings':[], }
  body = json.dumps( new_app )
  r = ucd.put(uri=applications_uri, data=body )
  print( "Create new application response: %s %s " % ( r.status_code, r.text ) )
  #ucd.debug_response( r )


  team_name = 'Team1'
  new_team_uri = '/cli/team/create?team=%s&description=%s' % ( team_name, 'description')

  r = ucd.put( uri=new_team_uri )
  print( "Create new team response: %s" % ( r.text ) )

  '''
   Add Group to team
   /cli/teamsecurity/groups?group=<name>&team=<name>&type=<name of type>
   http://www-01.ibm.com/support/knowledgecenter/SS4GSP_6.1.1/com.ibm.udeploy.api.doc/topics/rest_cli_teamsecurity_groups_put.html
  '''
  group_name = 'Team1Group'
  role_name = 'ConfigEngineer'

  add_group_to_team_uri = '/cli/teamsecurity/groups?group=%s&team=%s&type=%s' % ( group_name, team_name, role_name )
  r = ucd.put( uri=add_group_to_team_uri )


  '''
  PUT https://{hostname}:{port}
  /cli/application/teams?{parameters}
  '''

  type_name = 'Standard Application'
  add_team_to_app = '/cli/application/teams?application=%s&team=%s&type=%s' % ( app_name, team_name, type_name )

  r = ucd.put( uri=add_team_to_app )
  print( "Add Team to Application response: %s %s" % ( r.status_code, r.text ) )

  '''
  Add a team to an Environment

  PUT https://{hostname}:{port}
  /cli/environment/teams?{parameters}

  '''
  env_name = 'DEV'

  add_team_to_env_uri = '/cli/environment/teams?application=%s&environment=%s&team=%s&type=' % ( app_name, env_name, team_name )
  r = ucd.put( uri=add_team_to_env_uri )
  print( "Add Team to Environment response: %s %s" % ( r.status_code, r.text ) )

  '''
   Add Team to Resource

   PUT https://{hostname}:{port}
  /cli/resource/teams?{parameters}
  '''

  resource_path = '/Application1/DEV'
  team_id = '9e9c7267-4e08-455c-b8a7-4b64038553b2'

  add_team_to_resource_uri = '/cli/resource/teams?resource=%s&team=%s&type=' % ( resource_path, team_id )
  r = ucd.put( uri=add_team_to_resource_uri )
  print( "Add Team to Resource response: %s %s" % ( r.status_code, r.text ) )