コード例 #1
0
ファイル: changecontexturl.py プロジェクト: UPCnet/maxscripts
def main(maxinf, username, password, client, origin_url, target_url):
    if maxinf not in ['MAXUPC', 'MAXEXTERNS']:
        return
    maxinf = globals()[maxinf]
    conn = get_connection(maxinf['servers'], cluster=maxinf['cluster_name'])
    db = get_database(conn, 'max_' + client, username=username, password=password, authdb='admin')

    # Find contexts with the origin_url
    origin_contexts = db.contexts.find({'url': {'$regex': origin_url}}, {'url': 1})
    origin_contexts = [a['url'] for a in origin_contexts]

    print('Changing {} contexts:'.format(len(origin_contexts)))
    for url in origin_contexts:
        print('{} -> {}'.format(url, url.replace(origin_url, target_url)))
    really_want_it = query_yes_no('Are you sure to make this changes?')

    if really_want_it:
        maxclient = MaxClient(maxinf['maxserver'], oauth_server=maxinf['oauth_server'], debug=True)
        maxclient.login()

        for url in origin_contexts:
            maxclient.contexts[url].put(url=url.replace(origin_url, target_url))
コード例 #2
0
ファイル: clients.py プロジェクト: UPCnet/maxscripts
def maxcli():
    arguments = docopt(__maxcli__doc__, version='MAX Client terminal utility')
    domain = arguments.get('<domain>')
    maxserver = arguments.get('--maxserver')
    username = arguments.get('--username')
    password = arguments.get('--password')

    hubserver = arguments.get('--hubserver')
    oauthserver = arguments.get('--oauthserver')
    debug = arguments.get('--debug')

    if domain is not None:
        # Authenticate using domain
        client = MaxClient.from_hub_domain(domain, hub=hubserver, debug=debug)
    else:
        # or directlly use a maxserver
        client = MaxClient(maxserver, oauth_server=oauthserver, debug=debug)

    print
    print '  Connecting to {}'.format(client.url)
    print '-' * 60
    print

    succesfull_login = False
    while not succesfull_login:
        try:
            client.login(username, password)
        except BadUsernameOrPasswordError as error:
            print "Bad username or password, try again"
            # After getting the username once, use it while the user is trying
            # non empty passwords. On an empty password, ask for the user again
            username = error.username if error.password else None
        else:
            succesfull_login = True

    print MOTD
    ipdb.set_trace()
コード例 #3
0
ファイル: _max.py プロジェクト: UPCnet/gummanager.libs
 def get_client(self, instance_name, username='', password=''):
     instance_info = self.get_instance(instance_name)
     client = MaxClient(instance_info['server']['dns'])
     if username and password:
         client.login(username=username, password=password)
     return client