Example #1
0
def create_config(uname, preferred_pass):
    mysalt = ''.join(
        random.choice(string.ascii_letters + string.digits) for i in range(16))
    hashed_pass = sha512_crypt.encrypt(preferred_pass,
                                       salt=mysalt,
                                       rounds=5000,
                                       implicit_rounds=True)

    # code to create password for jupyter notebook
    salt_len = 12
    algorithm = 'sha1'
    h = hashlib.new(algorithm)
    salt = ('%0' + str(salt_len) + 'x') % random.getrandbits(4 * salt_len)
    h.update(preferred_pass + salt)
    jupyter_pass = '******'.join((algorithm, salt, h.hexdigest()))

    print hashed_pass
    globalVars.init()

    fp = open('cfg.sh', 'w')
    fp.truncate()

    fp.write('#cloud-config\n')
    fp.write('users:\n')
    fp.write('  - name: ' + uname + '\n')
    fp.write('    ssh-authorized-keys:\n')
    fp.write('      - ' + globalVars.masterKey + '\n')
    fp.write('    groups: sudo\n')
    fp.write('    shell: /bin/bash\n')
    fp.write('    sudo: [\'ALL=(ALL) NOPASSWD:ALL\']\n')
    fp.write('    lock-passwd: False\n')
    fp.write('    passwd: ' + hashed_pass + '\n')
    fp.write('runcmd:\n')
    fp.write('  - touch /home/ryan/testfile.txt\n')
    fp.write('  - [ sudo, sed, -i, \'s/[#]*PasswordAuthentication no/'
             'PasswordAuthentication yes/g\', /etc/ssh/sshd_config ]\n')
    fp.write('  - sudo mv /home/' + uname + '/.ssh /home/' + uname +
             '/.ssh_temp\n')
    fp.write('  - sudo cp -r /home/cc/. /home/' + uname + '\n')
    fp.write('  - sudo rm -r /home/' + uname + '/.ssh\n')
    fp.write('  - sudo mv /home/' + uname + '/.ssh_temp /home/' + uname +
             '/.ssh\n')
    fp.write('  - sudo service ssh restart\n')
    fp.write(
        '  - sudo sed -i "s/c\.NotebookApp\.password.*/c\.NotebookApp\.password = u\\\''
        + jupyter_pass + '\\\'/g" /home/' + uname +
        '/.jupyter/jupyter_notebook_config.py\n')
    fp.write('  - sudo su - ' + uname + ' -c "sudo jupyter notebook &"\n')
    fp.close
Example #2
0
def query_vm(computeId, cloud):

    # Chameleon Cloud instance querying
    if (cloud == "chameleon"):
        globalVars.init()
        my_token_id = cloudAuth.auth()
        response = cloudCompute.query_vm(my_token_id, computeId)
        return response

    # Jetstream instance querying
    if (cloud == "jetstream"):
        globalVars.init()
        my_token_id = jetAuth.auth()
        response = jetCompute.query_vm(my_token_id, computeId)
        return response
Example #3
0
def emailRegistration(email):
    globalVars.init()
    msg = MIMEMultipart()
    msg['From'] = globalVars.emailUser
    msg['To'] = email
    msg['Subject'] = "eLab Registration Successful"

    body = "Your registration to eLab is now complete.  You are now eligible to be enrolled into the available courses."
    msg.attach(MIMEText(body, 'plain'))

    server = smtplib.SMTP(globalVars.emailServer, globalVars.emailPort)
    server.starttls()
    server.login(globalVars.emailUser, globalVars.emailPass)
    text = msg.as_string()
    try:
        server.sendmail(globalVars.emailUser, email, text)
        server.quit()
    except:
        pass
Example #4
0
def emailUnenroll(email, courseName):
    globalVars.init()
    msg = MIMEMultipart()
    msg['From'] = globalVars.emailUser
    msg['To'] = email
    msg['Subject'] = "eLab Unenrollment Notification"

    body = "You have been unenrolled from \"" + courseName + "\".  You no longer have access to the associated content."
    msg.attach(MIMEText(body, 'plain'))

    server = smtplib.SMTP(globalVars.emailServer, globalVars.emailPort)
    server.starttls()
    server.login(globalVars.emailUser, globalVars.emailPass)
    text = msg.as_string()
    try:
        server.sendmail(globalVars.emailUser, email, text)
        server.quit()
    except:
        pass
Example #5
0
def associate_floating_ip(computeId, floating_ip, cloud):

    # Chameleon Cloud floating ip association
    if (cloud == "chameleon"):
        globalVars.init()
        my_token_id = cloudAuth.auth()
        cloudCompute.associate_floating_ip(my_token_id, computeId, floating_ip)
        return

    # Jetstream floating ip association
    if (cloud == "jetstream"):
        globalVars.init()
        my_token_id = jetAuth.auth()
        jetCompute.associate_floating_ip(my_token_id, computeId, floating_ip)
        return

    # AWS Cloud floating ip association
    if (cloud == "aws"):
        # Using a dummy function as AWS associates floating IPs automatically
        return
Example #6
0
def updateCatalog():
    globalVars.init()

    #Update the catalog from Chameleon
    my_token_id = cloudAuth.auth()
    r = cloudImages.getImageList(my_token_id)
    print json.dumps(r.json(), indent=4)
    cloud = Cloud.objects.get(name='chameleon')
    for image in r.json()['images']:
        if image['owner'] == globalVars.tenantName:
            this_description = ""

            if 'description' in image:
                this_description = image['description']
            modelFunctions.get_or_create_image(cloud, image['id'],
                                               image['name'], this_description)

    #Update the catalog from AWS
    client = awsAuth.authClient(globalVars.awsAccess, globalVars.awsSecret,
                                globalVars.awsRegion)
    images = awsImages.getImageList(client)
    cloud = Cloud.objects.get(name='aws')
    for image in images:
        print image
        modelFunctions.get_or_create_image(cloud, image['ImageId'],
                                           image['Name'], image['Description'])

    #Update the catalog from JetStream
    my_token_id = jetAuth.auth()
    r = jetImages.getImageList(my_token_id)
    print r
    print json.dumps(r.json(), indent=4)
    cloud = Cloud.objects.get(name='jetstream')
    for image in r.json()['images']:
        if image['owner'] == globalVars.jetstreamTenantID:
            this_description = ""

            if 'description' in image:
                this_description = image['description']
            modelFunctions.get_or_create_image(cloud, image['id'],
                                               image['name'], this_description)
Example #7
0
def boot_vm(instance_name, cloudId, cloud):
    globalVars.init()

    # Chameleon Cloud instance booting
    if (cloud == "chameleon"):
        my_token_id = cloudAuth.auth()
        instanceId = cloudCompute.boot_vm(my_token_id, instance_name, cloudId)
        return instanceId

    # Jetstream instance booting
    if (cloud == "jetstream"):
        my_token_id = jetAuth.auth()
        instanceId = jetCompute.boot_vm(my_token_id, instance_name, cloudId)
        return instanceId

    # AWS instance booting
    if (cloud == "aws"):
        resource = awsAuth.authResource(globalVars.awsAccess,
                                        globalVars.awsSecret,
                                        globalVars.awsRegion)
        instanceId = awsCompute.boot_vm(resource, instance_name, cloudId)
        return instanceId
Example #8
0
def rebuild_vm(computeId, imageId, instanceName, cloud):

    # Chameleon Cloud rebuild VM
    if (cloud == "chameleon"):
        globalVars.init()
        my_token_id = cloudAuth.auth()
        response = cloudCompute.rebuild_vm(my_token_id, computeId, imageId,
                                           instanceName)
        return response

    # Jetstream rebuild VM
    if (cloud == "jetstream"):
        globalVars.init()
        my_token_id = jetAuth.auth()
        response = jetCompute.rebuild_vm(my_token_id, computeId, imageId,
                                         instanceName)
        return response

    # AWS Cloud rebuild VM
    # AWS Does not support direct rebuilding, using a dummy function
    if (cloud == "aws"):
        return status.HTTP_200_OK
Example #9
0
def get_unused_floating_ip(cloud, computeId):
    globalVars.init()

    # Chameleon Cloud floating ip retrieval
    if (cloud == "chameleon"):
        my_token_id = cloudAuth.auth()
        floatingIp = cloudCompute.get_unused_floating_ip(my_token_id)
        return floatingIp

    # Jetstream floating ip retrieval
    if (cloud == "jetstream"):
        my_token_id = jetAuth.auth()
        floatingIp = jetCompute.get_unused_floating_ip(my_token_id)
        return floatingIp

    # AWS Cloud floating ip retrieval
    if (cloud == "aws"):
        # AWS can assign floating IPs automatically, we simply return it
        resource = awsAuth.authResource(globalVars.awsAccess,
                                        globalVars.awsSecret,
                                        globalVars.awsRegion)
        floatIp = awsCompute.get_IP(resource, computeId)
        return floatIp
Example #10
0
def delete_vm(computeId, cloud):
    # Chameleon Cloud Termination
    if (cloud == "chameleon"):
        globalVars.init()
        my_token_id = cloudAuth.auth()
        cloudCompute.delete_vm(my_token_id, computeId)
        return status.HTTP_200_OK

    # Jetstream Termination
    if (cloud == "jetstream"):
        globalVars.init()
        my_token_id = jetAuth.auth()
        jetCompute.delete_vm(my_token_id, computeId)
        return status.HTTP_200_OK

    # AWS Cloud Termination
    if (cloud == "aws"):
        globalVars.init()
        resource = awsAuth.authResource(globalVars.awsAccess,
                                        globalVars.awsSecret,
                                        globalVars.awsRegion)
        awsCompute.delete_vm(resource, computeId)
        return
Example #11
0
def auth(uname, passwd):
    globalVars.init()
    if uname == globalVars.apiUserName:
        if passwd == globalVars.apiPassword:
            return True
    return False