Beispiel #1
0
# Import megalib
import megalib
import getpass

# Authenticate user credentials using the megalib.login function
auth = megalib.login(input('username: '******'tfa (leave blank if not enabled): '))

# Check if logging was successful by observing the HTTP Status Code
if auth.status_code == 200:
    print('login successful')

    g_key = input('google key: ')

    # lookup google key using the megalib.google_lookup
    key = megalib.google_lookup(auth.header, g_key)

    # order VXC
    vxc = megalib.google(auth.header,
                         input('mcr uid: '),
                         key.uid,
                         'megaLib google demo',
                         key.bandwidths[0],
                         g_key,
                         mcr_connect=True)

    # Print response if call successful
    if vxc.status_code == 200:
        print('Great Success!')

    # Advise user if failed
Beispiel #2
0
# Import megalib & getpass
import megalib
import getpass

# Authenticate user credentials using the megalib.login function
auth = megalib.login(input('Username: '******'TFA (Optional): '), prod=False)

# Observe the HTTP Status Code and advise user if login was successful
if auth.status_code == 200:
    print('Login Successful')

    # Input the Azure Expressroute Key
    expressroute_key = input('Azure Expressroute Key: ')

    # Lookup the Azure Expressroute Key using the megalib.azure_lookup function
    key = megalib.azure_lookup(auth.header, expressroute_key, prod=False)

    # Observe the HTTP Status Code and advise user if azure lookup was successful
    if key.status_code == 200:
        print('Azure Expressroute Key Lookup Successful')

        # Order VXC to Azure using the megalib.azure function
        # Azure Expressroute Keys have two targets (primary and secondary), this example uses the primary target
        azure = megalib.azure(auth.header, input('Port UID: '), key.uid[0], input('VXC Name: '),
                              input('Speed (Rate Limit): '), expressroute_key, prod=False)

        # Advise user if order was successful
        if azure.status_code == 200:
            print('Azure VXC Ordered Successfully')

        # Advise user if order failed, print the status code & JSON
# This demo requires schedule - https://pypi.org/project/schedule/ & time
# Import schedule, time & getpass
import schedule
import time
import getpass

# Import megalib
import megalib

# Service UID
my_uid = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'

# Authenticate user credentials using the megalib.login function
auth = megalib.login(input('Username: '******'TFA (Leave blank if not enabled): '))


def speed_change(header, uid, speed):
    print(megalib.update_vxc(header, uid, speed=speed).status_code)


# Define the schedule
# This example configures 1000Mbps between 23:50 & 04:00. 200Mbps at all other times.
schedule.every().monday.at('04:00').do(speed_change, auth.header, my_uid, 200)
schedule.every().monday.at('23:50').do(speed_change, auth.header, my_uid, 1000)
schedule.every().tuesday.at('04:00').do(speed_change, auth.header, my_uid, 200)
schedule.every().tuesday.at('23:50').do(speed_change, auth.header, my_uid,
                                        1000)
schedule.every().wednesday.at('04:00').do(speed_change, auth.header, my_uid,
                                          200)
schedule.every().wednesday.at('23:50').do(speed_change, auth.header, my_uid,