コード例 #1
0
def task_migrate_vm(auth, vmid, live=False, destination=None):
    auth = Storage(loads(b64decode(auth)))
    conn = Baadal.Connection(_authurl, _tenant, auth.u, auth.p)
    if live:
        pass
    else:
        pass
コード例 #2
0
def task_restore_snapshot(auth, vmid, snapshot_id):
    auth = Storage(loads(b64decode(auth)))
    try:
        conn = Baadal.Connection(_authurl, _tenant, auth.u, auth.p)
        vm = conn.find_baadal_vm(id=vmid)
        vm.restore_snapshot(snapshot_id)
        logger.info('Snapshot restored: VMID %s, snapshot_id %s' % \
                (vmid, snapshot_id))
    except Exception as e:
        logger.exception(e)
コード例 #3
0
def task_delete_snapshot(auth, vmid, snapshot_id):
    auth = Storage(loads(b64decode(auth)))
    try:
        conn = Baadal.Connection(_authurl, _tenant, auth.u, auth.p)
        image = conn.find_image(id=snapshot_id)
        status = image.delete()
        logger.info('Snapshot deleted: VMID %s, snapshot_id %s' % \
                (vmid, snapshot_id))
    except Exception as e:
        logger.exception(e)
コード例 #4
0
ファイル: post_request.py プロジェクト: Aakash074/baadal
def new_vm():
    request_time = time.time()
    fields = validate_vm_request_form(request.vars)
    approver_mail_required = False
    mail2 = True
    if len(fields):
        raise HTTP(400, body=jsonify(status='fail', fields=fields))
    try:
        if (ldap.user_is_faculty(session.username)) or \
                (user_is_project_admin):
            owner_id = session.username
            vm_state = 1
        else:
            owner_id = request.vars.faculty
            approver_mail_required = True
            vm_state = 0

        public_ip_required = 1 if request.vars.public_ip == 'yes' else 0
        db.vm_requests.insert(vm_name=request.vars.vm_name,
                              flavor=request.vars.config,
                              sec_domain=request.vars.sec_domain,
                              image=request.vars.template,
                              owner=owner_id,
                              requester=session.username,
                              purpose=request.vars.purpose,
                              public_ip_required=public_ip_required,
                              extra_storage=request.vars.storage,
                              collaborators=request.vars.collaborators,
                              request_time=request_time,
                              state=vm_state)
        context = Storage()
        user_info = ldap.fetch_user_info(session.username)
        context.username = user_info['user_name']
        user_email = user_info['user_email']
        context.vm_name = request.vars.vm_name
        context.mail_support = mail_support

        mail1 = mailer.send(mailer.MailTypes.VMRequest, user_email, context)
        if approver_mail_required:
            user_info = ldap.fetch_user_info(request.vars.faculty)
            context.approver = user_info['user_name']
            user_email = user_info['user_email']
            context.request_type = 'New VM'
            context.request_time = seconds_to_localtime(request_time)
            mail2 = mailer.send(mailer.MailTypes.ApprovalReminder, user_email,
                                context)
        if mail1 and mail2:
            db.commit()
            return jsonify()
        else:
            db.rollback()
            raise Exception('Email sending failed')
    except Exception as e:
        logger.exception(e.message or str(e.__class__))
        return jsonify(status='fail', message=e.message or str(e.__class__))
コード例 #5
0
def validate_fdata(fdata, app_folder, must_exist=False):
    fdata = Storage(fdata)
    ret = Storage(md5_hash=None, error='', os_path=None)
    pth = fdata.path.strip()
    sanitize_pth_re = re.compile(r'\s*(\\|/)*([^\s]*)\s*$')
    pth = sanitize_pth_re.match(pth).groups()[1]
    ret.os_path = os_path = os.path.join(app_folder, pth)
    if must_exist and not os.path.exists(os_path):
        ret.error = 'it seems that path does not exist: %s' % os_path
    elif os.path.isdir(os_path):
        ret.error = 'path to a file was expected: %s [%s]' % (os_path,
                                                              fdata.path)
    elif os.path.isfile(os_path):
        if not fdata.md5_hash:
            ret.error = 'md5_hash is required'
        elif md5_hash(safe_read(os_path)) != fdata.md5_hash:
            ret.error = 'file was changed on disk'
    elif os.path.exists(os_path):
        ret.error = 'path exists but it`s to never : %s' % os_path
    return ret
コード例 #6
0
def task_clone_vm(auth, reqid):
    auth = Storage(loads(b64decode(auth)))
    req = db(db.clone_requests.id == reqid).select()[0]
    try:
        conn = Baadal.Connection(_authurl, _tenant, auth.u, auth.p)
        vm = conn.find_baadal_vm(id=req.vm_id)
        clone = vm.clone()
        logger.info('VM Cloned: VMID %s, clone_id %s' % (req.vm_id, clone))
        req.update_record(status=REQUEST_STATUS_APPROVED)
    except Exception as e:
        logger.exception(e)
        req.update_record(status=REQUEST_STATUS_POSTED)
コード例 #7
0
def task_resize_vm(auth, reqid):
    auth = Storage(loads(b64decode(auth)))
    logger.info('Resizing VM')
    try:
        req = db(db.resize_requests.id == reqid).select()[0]
        conn = Baadal.Connection(_authurl, _tenant, auth.u, auth.p)
        vm = conn.find_baadal_vm(id=req.vm_id)
        new_flavor = req.new_flavor
        vm.resize(new_flavor)
        req.update_record(status=REQUEST_STATUS_APPROVED)
        logger.info('VM Resized: VMID %s, old_flavor %s, new_flavor %s' % \
                    (req.vm_id, vm.server.flavor['id'], req.new_flavor))
    except Exception as e:
        logger.exception(e)
        req.update_record(status=REQUEST_STATUS_POSTED)
    finally:
        db.commit()
        conn.close()
コード例 #8
0
def task_create_vm(reqid, auth):
    logger.debug('inside scheduler')
    try:
        auth = Storage(loads(b64decode(auth)))
        req = db(db.vm_requests.id == reqid).select()[0]
        conn = Baadal.Connection(_authurl, _tenant, auth.u, auth.p)
        name = req.vm_name
        img = req.image
        owner = req.owner
        collaborators = req.collaborators
        requester = req.requester
        flavor = req.flavor
        nics = [{'net-id': req.sec_domain}]
        kp = default_keypair
        pub_ip = req.public_ip_required
        vdisk = req.extra_storage
        vm = conn.create_baadal_vm(name,
                                   img,
                                   flavor,
                                   nics,
                                   key_name=kp,
                                   requester=requester,
                                   owner=owner,
                                   collaborators=collaborators)
        status = vm.get_status()
        while status not in ('Running', 'Error'):
            logger.info('VM %s in creation, current status %s' % \
                        (name, status))
            sleep(5)
            status = vm.get_status()
        if status == 'Running':
            logger.info('VM created')
            try:
                req.update_record(state=REQUEST_STATUS_APPROVED)
                context = Storage()
                user_info = ldap.fetch_user_info(req.requester)
                context.username = user_info['user_name']
                context.user_email = user_info['user_email']
                context.vm_name = name
                context.mail_support = mail_support
                context.gateway_server = gateway_server
                context.request_time = seconds_to_localtime(req.request_time)
                logger.info('sending mail')
                mailer.send(mailer.MailTypes.VMCreated, context.user_email,
                            context)
                logger.info('mail sent')
                if pub_ip == 1 or vdisk:
                    if pub_ip:
                        vm.attach_floating_ip()

                    if vdisk:
                        disk = conn.create_volume(vdisk)
                        while disk.status != 'available':
                            disk = conn.get_disk_by_id(disk.id)
                        num_disks = vm.metadata().get('disks', 0)
                        disk_path = '/dev/vd' + chr(97 + num_disks)
                        vm.attach_disk(disk, disk_path)
                        vm.update(disks=num_disks + 1)
            except Exception as e:
                logger.exception(e)
        else:
            # VM state Error
            req.update_record(state=REQUEST_STATUS_POSTED)
            raise Exception('VM build failed')
    except Exception as e:
        req.update_record(state=REQUEST_STATUS_POSTED)
        logger.exception(e)
    finally:
        db.commit()
コード例 #9
0
#  along with this program.  If not, see <http://www.gnu.org/licenses/>
#
###########################################################
__author__ = "Thadeus Burgess <*****@*****.**>"
__copyright__ = "Copyright 2009-2010 Thadeus Burgess. GNU GPL v3."
__title__ = "Wordpress 2 Python"
__description__ = """
Turns a wordpress export xml file into a python dictionary
taking coffee for donations :)
"""
__version__ = "0.0.2"
###########################################################

from gluon.tools import Storage

plugin_wordpress2py = Storage()
plugin_wordpress2py.meta = {
    'title': 'Wordpress To Web2py',
    'author': 'Thadeus Burgess <*****@*****.**>',
    'keywords': 'database, migration, wordpress, blog',
    'description':
    'Converts wordpress exported xml+rss into a python dictionary and then imports into web2py DAL',
    'copyright': 'GPL v2',
}

#######################################
#### USAGE
########

# Retrieve a python dict that represents the wordpress database
## data = word2py(open('/path/to/wordpress.2009-11-30.xml', 'r'))