Exemplo n.º 1
0
def command_status(parser, input_args):
    """Print current cluster status."""
    parser.parse_args(input_args)

    cluster = pvestats.buildcluster()
    cluster.freeze()
    print_state(cluster)
Exemplo n.º 2
0
def command_flush(parser, input_args):
    """Migrate all migrateable VMs off the given Node."""
    parser.add_argument(
        '-v',
        '--verbose',
        action=_VerbosityAction,
        help='increase verbosity level, can be used multiple times')
    parser.add_argument('-n',
                        '--noexec',
                        action='store_true',
                        help='only show, don\'t migrate')
    parser.add_argument('-c',
                        '--count',
                        type=int,
                        help='number of migrations to run')
    parser.add_argument('-o',
                        '--onlyha',
                        action='store_true',
                        help='only migrate HA managed VMs')
    parser.add_argument(
        '-i',
        '--ignore',
        type=lambda x: x.split(','),
        help='comma separated list of nodes to ignore as migration targets')
    parser.add_argument('-f',
                        '--nofail',
                        action='store_true',
                        help="do not fail if a migration's exit code is not 0")
    parser.add_argument('nodes',
                        nargs='+',
                        help='name of the nodes to migrate all VMs off')

    args = parser.parse_args(input_args)

    cluster = pvestats.buildcluster()
    cluster.freeze()

    options = {'onlyha': args.onlyha}
    if 'count' in args and args.count:
        options['maxmigrations'] = args.count
    if 'ignore' in args and args.ignore:
        options['ignorenodenames'] = args.ignore

    try:
        newcluster = pvecluster.planflush(args.nodes, cluster.clone(),
                                          **options)
        exec_migrate(cluster, newcluster, args)
    except Error as exc:
        print('{}: {} - Aborting'.format(exc.__class__.__name__, exc.message))
Exemplo n.º 3
0
def readstats():
    cluster = pvestats.buildcluster()
    hostname = socket.gethostname()
    node = cluster[hostname]

    for vm in node.vms(lambda c: c.status == 'running'):
        if vm.type == 'qemu':
            blockstat = pveqemumonitor.query_blockstats(vm.vmid)
            vm.diskrops = sum([d['stats']['rd_operations'] for d in blockstat])
            vm.diskwops = sum([d['stats']['wr_operations'] for d in blockstat])
        for plugin, metrics in plugin_metrics.items():
            for metric, attrs in metrics.items():
                try:
                    values = [getattr(vm, attr) for attr in attrs]
                except AttributeError:
                    continue
                instance = "VM_%s" % vm.vmid
                dispatch(plugin, instance, metric, None, values)
Exemplo n.º 4
0
def command_balance(parser, input_args):
    """Migrate VMs in order to achieve a memeory balanced state."""
    parser.add_argument(
        '-v',
        '--verbose',
        action=_VerbosityAction,
        help='increase verbosity level, can be used multiple times')
    parser.add_argument('-n',
                        '--noexec',
                        action='store_true',
                        help='only show, don\'t migrate')
    parser.add_argument('-c',
                        '--count',
                        type=int,
                        help='number of migrations to run')
    parser.add_argument(
        '-i',
        '--ignore',
        type=lambda x: x.split(','),
        help='comma separated list of nodes to ignore as migration targets')
    parser.add_argument('-f',
                        '--nofail',
                        action='store_true',
                        help="do not fail if a migration's exit code is not 0")

    args = parser.parse_args(input_args)

    cluster = pvestats.buildcluster()
    cluster.freeze()

    options = {}
    if 'count' in args and args.count:
        options['iterations'] = args.count
    if 'ignore' in args and args.ignore:
        options['ignorenodenames'] = args.ignore

    try:
        newcluster = pvecluster.planbalance(cluster.clone(), **options)
        exec_migrate(cluster, newcluster, args)
    except Error as exc:
        print('{}: {} - Aborting'.format(exc.__class__.__name__, exc.message))