Ejemplo n.º 1
0
def update_schedule(schedule_id, data):
    """
    Update a schedule.
    """
    schedule = db.session.query(Schedule).filter(
        Schedule.id == schedule_id).one()

    pool_id = data.get('pool_id')
    schedule.pool = db.session.query(Pool).filter(Pool.id == pool_id).one()

    datastore_id = data.get('datastore_id')
    schedule.datastore = db.session.query(Datastore).filter(
        Datastore.id == datastore_id).one()

    schedule.name = data.get('name')
    schedule.minute = data.get('minute')
    schedule.hour = data.get('hour')
    schedule.day = data.get('day')
    schedule.month = data.get('month')
    schedule.week = data.get('week')
    schedule.uuid = data.get('uuid')

    db.session.add(schedule)
    db.session.commit()

    Flow.instance().schedule_edit(schedule.id)
Ejemplo n.º 2
0
def create_schedule(data):
    """
    Create a schedule. Id is ignored.
    """
    name = data.get('name')
    minute = data.get('minute')
    hour = data.get('hour')
    day = data.get('day')
    month = data.get('month')
    week = data.get('week')
    uuid = data.get('uuid')
    advanced = data.get('advanced')

    pool_id = data.get('pool_id')
    pool = db.session.query(Pool).filter(Pool.id == pool_id).one()

    datastore_id = data.get('datastore_id')
    datastore = db.session.query(Datastore).filter(
        Datastore.id == datastore_id).one()

    schedule = Schedule(name=name,
                        minute=minute,
                        hour=hour,
                        day=day,
                        month=month,
                        week=week,
                        uuid=uuid,
                        pool=pool,
                        datastore=datastore,
                        advanced=advanced)

    db.session.add(schedule)
    db.session.commit()

    Flow.instance().schedule_add(schedule.id)
Ejemplo n.º 3
0
def delete_schedule(schedule_id):
    """
    Delete a schedule.
    """
    schedule = db.session.query(Schedule).filter(
        Schedule.id == schedule_id).one()
    db.session.delete(schedule)
    db.session.commit()

    Flow.instance().schedule_delete(schedule.id)
Ejemplo n.º 4
0
    def get(self, pool_id):
        """
        Returns list of vms with full info.
        """
        env = Flow.instance().get_environment(pool_id)

        wrapped = []
        if env['vms'] == None:
            return wrapped

        for e in env['vms']:
            vm = e[1]

            # finding resident
            hostlabel = ''
            for host in env["hosts"]:
                if vm["power_state"].lower() == 'running':
                    if vm["resident_on"] == host[0]:
                        hostlabel = host[1]["hostname"] + ' (' + host[1]["address"] + ')'
                else:
                    # suspended or paused
                    if vm["affinity"] == host[0]:
                        hostlabel = host[1]["hostname"] + ' (' + host[1]["address"] + ')'

            

            disks = env['disks'][vm["uuid"]]
            disk_used = 0
            disk_virtual = 0
            for disk in disks:
                disk_used = disk_used + int(disk['physical_utilisation'])
                disk_virtual = disk_virtual + int(disk['virtual_size'])

            # exceptional case; can't find the host
            if hostlabel == '':
                if len(disks) > 0:
                    host = Flow.instance().get_host_by_sr(pool_id, disks[0]['SR'])
                    if host != None:
                        hostlabel = host["hostname"] + ' (' + host["address"] + ')'

            # create object
            obj = type('',(object,),{"name": vm["name_label"], 
                                     "uuid": vm["uuid"],
                                     "status": vm["power_state"].lower(),
                                     "resident": hostlabel,
                                     "cpu": vm['VCPUs_at_startup'],
                                     "mem": vm["memory_static_max"],
                                     "disk_used": str(disk_used),
                                     "disk_virtual": str(disk_virtual),
                                    })()
           
            wrapped.append(obj)
        return wrapped
Ejemplo n.º 5
0
def initialize_app():
    """
    Initialize the application
    """
    log.info('Initializing application...')

    # check database version and mirate if needed
    database.check_version(app, admin)

    # cleanup
    Flow.instance().cleanup_start()

    # initialize the scheduler
    Flow.instance().initialize_scheduler()
Ejemplo n.º 6
0
def test_host(data):
    """
    Test a host
    """
    username = data.get('username')
    password = data.get('password')
    server = data.get('address')

    if Flow.instance().test_host(server, username, password) == True:
        return 200
    return 204
Ejemplo n.º 7
0
def test_datastore(data):
    """
    Test the datastore
    """

    username = data.get('username')
    password = data.get('password')
    server = data.get('host')

    if Flow.instance().test_datastore(server, username, password) == True:
        return 200
    return 204
Ejemplo n.º 8
0
    def get(self):
        """
        Returns Messages.
        """

        tasks = Flow.instance().messages

        # Gather all tasks
        uitasks = []
        uimessages = []
        uinotifications = []
        for task in tasks:
            if task[1] == MessageType.TASK:
                uitask = type('', (object, ), {
                    "title": task[2],
                    "percent": task[3],
                })()

                uitasks.append(uitask)
            if task[1] == MessageType.MESSAGE:
                uimessage = type('', (object, ), {
                    "from": task[2],
                    "time": task[4],
                    "message": task[3],
                })()

                uimessages.append(uimessage)
            if task[1] == MessageType.NOTIFICATION:
                uinotification = type(
                    '', (object, ), {
                        "icon": "fa fa-" + task[2] + " text" + task[3],
                        "message": task[4],
                    })()

                uinotifications.append(uinotification)

        obj = type(
            '', (object, ), {
                "messages": len(uimessages),
                "notifications": len(uinotifications),
                "tasks": len(uitasks),
                "messages_items": uimessages,
                "notifications_items": uinotifications,
                "tasks_items": uitasks,
            })()

        return obj
Ejemplo n.º 9
0
def validate_restore_task(data):
    backupname = data.get('backupname')
    backup_id = data.get('backup_id')
    backup = db.session.query(Backup).filter(Backup.id == backup_id).one()
    host_id = data.get('host_id')

    # validate
    #if Flow.instance()

    vms = Flow.instance().get_vms(host_id)

    errors = []

    for vm in vms:
        if vm[1]["name_label"] == backupname:
            errors.append("vmname_duplicate")

    return errors
Ejemplo n.º 10
0
    def get(self, pool_id):
        """
        Returns list of vms with short info.
        """
        env = Flow.instance().get_vms(pool_id)

        wrapped = []
        if len(env) == 0:
            return wrapped

        for e in env:
            vm = e[1]
            # create object
            obj = type('',(object,),{"name": vm["name_label"], 
                                     "uuid": vm["uuid"],
                                     "status": vm["power_state"].lower(),
                                    })()
           
            wrapped.append(obj)
        return wrapped
Ejemplo n.º 11
0
    def get(self, pool_id, host_id):
        """
        Gets all SR available for a host (based on host id).
        """

        host = db.session.query(Host).filter(Host.id == host_id).one()
        srs = Flow.instance().get_sr(pool_id, host.address)

        wrapped = []
        if srs == None:
            return wrapped

        for sr in srs:
            # create object
            obj = type('', (object, ), {
                "name": sr[1]["name_label"],
                "sr": sr[0].split(':')[1],
            })()

            wrapped.append(obj)
        return wrapped