예제 #1
0
def dump_chains(*args):
    """
    dump-volume-chains
    Query VDSM about the existing structure of image volumes and prints
    them in an ordered fashion with optional additional info per volume.
    Alternatively, dumps the volumes information in json format without
    analysis.
    """
    parsed_args = _parse_args(args)
    cli = client.connect(parsed_args.host, parsed_args.port,
                         use_tls=parsed_args.use_ssl)
    with utils.closing(cli):
        volumes_info = _get_volumes_info(cli, parsed_args.sd_uuid)
        if parsed_args.output == 'text':
            # perform analysis and print in human readable format
            image_chains = _get_volumes_chains(volumes_info)
            _print_volume_chains(image_chains, volumes_info)
        elif parsed_args.output == 'json':
            # no analysis, dump chains in json format
            json.dump(volumes_info, sys.stdout, indent=2)
        elif parsed_args.output == 'sqlite':
            # no analysis, dump chains in sql format
            _dump_sql(volumes_info, parsed_args.sqlite_file)
        else:
            raise ValueError('unknown output format %s' % parsed_args.output)
예제 #2
0
def dump_chains(*args):
    """
    dump-volume-chains
    Query VDSM about the existing structure of image volumes and prints
    them in an ordered fashion with optional additional info per volume.
    Alternatively, dumps the volumes information in json format without
    analysis.
    """
    parsed_args = _parse_args(args)
    cli = client.connect(parsed_args.host, parsed_args.port,
                         use_tls=parsed_args.use_ssl)
    with utils.closing(cli):
        volumes_info = _get_volumes_info(cli, parsed_args.sd_uuid)
        if parsed_args.output == 'text':
            # perform analysis and print in human readable format
            image_chains = _get_volumes_chains(volumes_info)
            _print_volume_chains(image_chains, volumes_info)
        elif parsed_args.output == 'json':
            # no analysis, dump chains in json format
            json.dump(volumes_info, sys.stdout, indent=2)
        elif parsed_args.output == 'sqlite':
            # no analysis, dump chains in sql format
            _dump_sql(volumes_info, parsed_args.sqlite_file)
        else:
            raise ValueError('unknown output format %s' % parsed_args.output)
예제 #3
0
def main(*args):
    """
    This tool is used to check and optionally repair broken volume leases.
    """
    parsed_args = _parse_args(args)

    if not parsed_args.repair and not _confirm_check_leases():
        return

    cli = client.connect(parsed_args.host, parsed_args.port,
                         use_tls=parsed_args.use_ssl)
    with utils.closing(cli):
        print()
        print("Checking active storage domains. This can take several "
              "minutes, please wait.")
        broken_leases = _get_leases_to_repair(cli)
        if not broken_leases:
            print()
            print("There are no leases to repair.")
            return

    print()
    _print_broken_leases(broken_leases)
    if not parsed_args.repair and not _confirm_repair_leases():
        return

    _repair(broken_leases)
예제 #4
0
파일: client.py 프로젝트: EdDev/vdsm
def main(args=None):
    schema = find_schema()
    namespaces = create_namespaces(schema)
    parser = option_parser(namespaces)
    args = parser.parse_args(args)
    try:
        if args.method_args and args.file is not None:
            raise UsageError("Conflicting command line parameters: %r and "
                             "file option: %r" % (args.method_args, args.file))

        namespace = args.namespace
        method = args.method

        if args.file:
            request_params = parse_file(args.file)
        else:
            request_params = parse_params(args.method_args)

        cli = client.connect(args.host, port=args.port, use_tls=args.use_tls,
                             timeout=args.timeout,
                             gluster_enabled=args.gluster_enabled)

        with utils.closing(cli):
            command = getattr(getattr(cli, namespace), method)
            result = command(**request_params)
            print(json.dumps(result, indent=4))
    except UsageError as e:
        parser.error(str(e))
    except Exception as e:
        fail(e)
예제 #5
0
def __vdsm_json_rpc_connect(logger=None, timeout=envconst.VDSCLI_SSL_TIMEOUT):
    global _vdsm_json_rpc

    retry = 0
    while retry < VDSM_MAX_RETRY:
        try:
            _vdsm_json_rpc = client.connect(host="localhost", timeout=timeout)
            # we still have to validate the connection, also if fresh,
            # because the auto re-connect logic will not work
            # when vdsm certs got renewed at setup time by
            # host-deploy
            #
            # make sure we do not multiply the timeout by waiting
            # both here and in the check method
            retry += __vdsm_json_rpc_check(logger, VDSM_MAX_RETRY - retry)
            if _vdsm_json_rpc is not None:
                break
        except client.ConnectionError:
            retry += 1
            __log_debug(logger, 'Waiting for VDSM to connect')

        time.sleep(VDSM_DELAY)

    if _vdsm_json_rpc is None:
        raise RuntimeError(
            "Couldn't  connect to VDSM within {timeout} seconds".format(
                timeout=VDSM_MAX_RETRY * VDSM_DELAY))
예제 #6
0
파일: client.py 프로젝트: gobindadas/vdsm
def main(args=None):
    schema = find_schema()
    namespaces = create_namespaces(schema)
    parser = option_parser(namespaces)
    args = parser.parse_args(args)
    try:
        if args.method_args and args.file is not None:
            raise UsageError("Conflicting command line parameters: %r and "
                             "file option: %r" % (args.method_args, args.file))

        namespace = args.namespace
        method = args.method

        if args.file:
            request_params = parse_file(args.file)
        else:
            request_params = parse_params(args.method_args)

        cli = client.connect(args.host,
                             port=args.port,
                             use_tls=args.use_tls,
                             timeout=args.timeout,
                             gluster_enabled=args.gluster_enabled)

        with utils.closing(cli):
            command = getattr(getattr(cli, namespace), method)
            result = command(**request_params)
            print(json.dumps(result, indent=4))
    except UsageError as e:
        parser.error(str(e))
    except Exception as e:
        fail(e)
예제 #7
0
def __vdsm_json_rpc_connect(logger=None,
                            timeout=envconst.VDSCLI_SSL_TIMEOUT):
    global _vdsm_json_rpc

    retry = 0
    while retry < VDSM_MAX_RETRY:
        try:
            _vdsm_json_rpc = client.connect(host="localhost",
                                            timeout=timeout)
            # we still have to validate the connection, also if fresh,
            # because the auto re-connect logic will not work
            # when vdsm certs got renewed at setup time by
            # host-deploy
            #
            # make sure we do not multiply the timeout by waiting
            # both here and in the check method
            retry += __vdsm_json_rpc_check(logger, VDSM_MAX_RETRY - retry)
            if _vdsm_json_rpc is not None:
                break
        except client.ConnectionError:
            retry += 1
            __log_debug(logger, 'Waiting for VDSM to connect')

        time.sleep(VDSM_DELAY)

    if _vdsm_json_rpc is None:
        raise RuntimeError(
            "Couldn't  connect to VDSM within {timeout} seconds".format(
                timeout=VDSM_MAX_RETRY * VDSM_DELAY
            )
        )
예제 #8
0
def main(*args):
    """
    This tool is used to check and optionally repair broken volume leases.
    """
    parsed_args = _parse_args(args)

    if not parsed_args.repair and not _confirm_check_leases():
        return

    cli = client.connect(parsed_args.host,
                         parsed_args.port,
                         use_tls=parsed_args.use_ssl)
    with utils.closing(cli):
        print()
        print("Checking active storage domains. This can take several "
              "minutes, please wait.")
        broken_leases = _get_leases_to_repair(cli)
        if not broken_leases:
            print()
            print("There are no leases to repair.")
            return

    print()
    _print_broken_leases(broken_leases)
    if not parsed_args.repair and not _confirm_repair_leases():
        return

    _repair(broken_leases)
예제 #9
0
def resume_paused_vm(vm_id):
    unpause_file = MARK_FOR_UNPAUSE_PATH % vm_id
    if os.path.isfile(unpause_file):
        use_tls = config.getboolean('vars', 'ssl')
        cli = client.connect('localhost', use_tls=use_tls)
        with utils.closing(cli):
            cli.VM.cont(vmID=vm_id)
        os.remove(unpause_file)
예제 #10
0
def resume_paused_vm(vm_id):
    unpause_file = MARK_FOR_UNPAUSE_PATH % vm_id
    if os.path.isfile(unpause_file):
        use_tls = config.getboolean('vars', 'ssl')
        cli = client.connect('localhost', use_tls=use_tls)
        with utils.closing(cli):
            cli.VM.cont(vmID=vm_id)
        os.remove(unpause_file)
예제 #11
0
def dump_chains(*args):
    """
    dump-volume-chains
    Query VDSM about the existing structure of image volumes and prints
    them in an ordered fashion with optional additional info per volume.
    """
    parsed_args = _parse_args(args)
    cli = client.connect(parsed_args.host, parsed_args.port,
                         use_tls=parsed_args.use_ssl)
    with utils.closing(cli):
        image_chains, volumes_info = _get_volumes_chains(
            cli, parsed_args.sd_uuid)
        _print_volume_chains(image_chains, volumes_info)
예제 #12
0
def dump_chains(*args):
    """
    dump-volume-chains
    Query VDSM about the existing structure of image volumes and prints
    them in an ordered fashion with optional additional info per volume.
    """
    parsed_args = _parse_args(args)
    cli = client.connect(parsed_args.host,
                         parsed_args.port,
                         use_tls=parsed_args.use_ssl)
    with utils.closing(cli):
        image_chains, volumes_info = _get_volumes_chains(
            cli, parsed_args.sd_uuid)
        _print_volume_chains(image_chains, volumes_info)
예제 #13
0
    def __init__(self):
        super(JsonRpcVdsmClientInterface, self).__init__()

        try:
            use_tls = vdsmconfig.getboolean('vars', 'ssl')
        except Exception as e:
            self._logger.warn(
                "Failed to read VDSM config file, using SSL connection. %s", e)
            use_tls = True

        try:
            self._vdsm_api = client.connect(host="localhost", use_tls=use_tls)
        except client.ConnectionError as e:
            raise ConnectionError(str(e))

        self.checked_call(self._vdsm_api.Host.ping2)
예제 #14
0
def main(args=None):
    preliminary_parser = argparse.ArgumentParser(add_help=False)
    preliminary_parser.add_argument('--gluster-enabled',
                                    dest="gluster_enabled",
                                    action="store_true",
                                    help="gluster enabled")
    preliminary_parser.set_defaults(gluster_enabled=False)
    known_args, extra = preliminary_parser.parse_known_args()
    schema = find_schema(known_args.gluster_enabled)
    namespaces = create_namespaces(schema)

    parser = option_parser(namespaces)
    args = parser.parse_args(extra)
    try:
        if args.method_args and args.file is not None:
            raise UsageError("Conflicting command line parameters: %r and "
                             "file option: %r" % (args.method_args, args.file))

        namespace = args.namespace
        method = args.method

        if args.file:
            request_params = parse_file(args.file)
        else:
            request_params = parse_params(args.method_args)

        cli = client.connect(args.host,
                             port=args.port,
                             use_tls=args.use_tls,
                             timeout=args.timeout,
                             gluster_enabled=known_args.gluster_enabled)

        with utils.closing(cli):
            command = getattr(getattr(cli, namespace), method)
            result = command(**request_params)
            print(json.dumps(result, indent=4))
    except UsageError as e:
        parser.error(str(e))
    except Exception as e:
        fail(e)
예제 #15
0
파일: client.py 프로젝트: oVirt/vdsm
def main(args=None):
    preliminary_parser = argparse.ArgumentParser(add_help=False)
    preliminary_parser.add_argument('--gluster-enabled',
                                    dest="gluster_enabled",
                                    action="store_true",
                                    help="gluster enabled")
    preliminary_parser.set_defaults(gluster_enabled=False)
    known_args, extra = preliminary_parser.parse_known_args()
    schema = find_schema(known_args.gluster_enabled)
    namespaces = create_namespaces(schema)

    parser = option_parser(namespaces)
    args = parser.parse_args(extra)
    try:
        if args.method_args and args.file is not None:
            raise UsageError("Conflicting command line parameters: %r and "
                             "file option: %r" % (args.method_args, args.file))

        namespace = args.namespace
        method = args.method

        if args.file:
            request_params = parse_file(args.file)
        else:
            request_params = parse_params(args.method_args)

        cli = client.connect(args.host, port=args.port, use_tls=args.use_tls,
                             timeout=args.timeout,
                             gluster_enabled=known_args.gluster_enabled)

        with utils.closing(cli):
            with cli.flow(args.flow_id):
                command = getattr(getattr(cli, namespace), method)
                result = command(**request_params)
                print(json.dumps(result, indent=4, sort_keys=True))
    except UsageError as e:
        parser.error(str(e))
    except Exception as e:
        fail(e)
예제 #16
0
def main():
    args = parse_args()
    logging.basicConfig(
        level=logging.DEBUG,
        format="%(asctime)s %(levelname)-7s (%(threadName)s) %(message)s")
    old_master = args.old_master
    new_master = args.new_master

    cli = client.connect("localhost", 54321)
    with closing(cli):
        if args.master_version:
            master_ver = args.master_version
        else:
            pool_info = cli.StoragePool.getInfo(storagepoolID=args.pool_id)
            master_ver = int(pool_info['info']['master_ver']) + 1

        for i in range(1, args.iterations + 1):
            log.info("Cycle %s/%s, switching master from %s to %s version %s",
                     i, args.iterations, old_master, new_master, master_ver)
            task_id = cli.StoragePool.switchMaster(storagepoolID=args.pool_id,
                                                   oldMasterUUID=old_master,
                                                   newMasterUUID=new_master,
                                                   masterVersion=master_ver)
            log.info("Task id: %s", task_id)

            # Example Task.getStatus response:
            # {'taskID': '5e7b6cd0-d9d7-4e48-b525-7f1f0a612ff7',
            # 'taskState': 'running', 'taskResult': '', 'code': 0,
            # 'message': 'running job 1 of 1'}
            while True:
                time.sleep(5)
                status = cli.Task.getStatus(taskID=task_id)
                log.debug("Task status: %s", status)
                if status["taskState"] != "running":
                    break

            log.debug("Clearing task %s", task_id)
            cli.Task.clear(taskID=task_id)

            if status["code"] != 0:
                raise RuntimeError("Task failed: %s", status["message"])

            pool_info = cli.StoragePool.getInfo(storagepoolID=args.pool_id)
            if pool_info['info']['master_ver'] != master_ver:
                raise RuntimeError(
                    "Unexpected master_ver value: expecting: {} actual: {}".
                    format(master_ver, pool_info['info']['master_ver']))

            if pool_info['info']['master_uuid'] != new_master:
                raise RuntimeError(
                    "Unexpected master_uuid value: expecting: {} actual: {}".
                    format(new_master, pool_info['info']['master_uuid']))

            new_master_info = cli.StorageDomain.getInfo(
                storagedomainID=new_master)
            if new_master_info['role'] != "Master":
                raise RuntimeError(
                    "Role for new master domain didn't change to Master")

            old_master_info = cli.StorageDomain.getInfo(
                storagedomainID=old_master)
            if old_master_info['role'] != "Regular":
                raise RuntimeError(
                    "Role for old master domain didn't change to Regular")

            log.info("Master switched successfully")
            new_master, old_master = old_master, new_master
            master_ver += 1
 def __init__(self):
     super(JsonRpcVdsmClientInterface, self).__init__()
     self._vdsm_api = client.connect(host="localhost")
     self.checked_call(self._vdsm_api.Host.ping2)
예제 #18
0
def _vdscli():
    return client.connect('localhost')
예제 #19
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Refer to the README and COPYING files for full details of the license
#

import os
import subprocess
import hooking

from vdsm import client
from vdsm.config import config
from vdsm import utils


if hooking.tobool(os.environ.get('sap_agent', False)):
    use_tls = config.getboolean('vars', 'ssl')

    cli = client.connect('localhost', use_tls=use_tls)
    with utils.closing(cli):
        res = cli.Host.getVMFullList()
        if not [v for v in res
                if v.get('vmId') != os.environ.get('vmId') and
                hooking.tobool(v.get('custom', {}).get('sap_agent', False))]:
            subprocess.call(['/usr/bin/sudo', '-n', '/sbin/service', 'vhostmd',
                             'stop'])
예제 #20
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Refer to the README and COPYING files for full details of the license
#

import os
import subprocess
import hooking

from vdsm import client
from vdsm.config import config
from vdsm import utils


use_tls = config.getboolean('vars', 'ssl')

cli = client.connect('localhost', use_tls=use_tls)
with utils.closing(cli):
    res = cli.Host.getVMFullList()
    if not [v for v in res
            if v.get('vmId') != os.environ.get('vmId') and
            hooking.tobool(v.get('custom', {}).get('sap_agent', False))]:
        subprocess.call(['/usr/bin/sudo', '-n', '/sbin/service', 'vhostmd',
                         'stop'])
예제 #21
0
 def __init__(self):
     super(JsonRpcVdsmClientInterface, self).__init__()
     self._vdsm_api = client.connect(host="localhost")
     self.checked_call(self._vdsm_api.Host.ping2)
예제 #22
0
def reader(ctx, headers, errors):
    log.info("Reader started")

    name = threading.current_thread().name

    # We need vdsm client to clear tasks after downloads and report errors
    # since error handling in the http server is poor.
    vdsm = vdsm_client.connect("localhost", 54321)

    # We need http client to download image data.
    http = http_client.HTTPSConnection(HOST, PORT, context=ctx, timeout=10)

    with closing(vdsm), closing(http):
        for i in range(100):
            log.debug("Sending request %s", i)
            http.request("GET", "/", headers=headers)

            task_id = None
            r = http.getresponse()
            try:
                log.debug(
                    "Received response %s: status=%r reason=%r headers=%r",
                    i, r.status, r.reason, r.getheaders())

                task_id = r.getheader("Task-Id")

                # Did we fail to start the download?
                if r.status != http_client.PARTIAL_CONTENT:
                    error = r.read()[:200].decode("utf-8", errors="replace")
                    raise RuntimeError("Request failed: {}".format(error))

                # This may fail if the internal task failed, and we will just
                # time out waiting for the data.
                try:
                    r.read()
                except (http_client.HTTPException, OSError) as e:
                    log.error(
                        "Reading payload failed: %s, closing connection", e)
                    http.close()
            finally:
                if task_id:
                    log.debug("Waiting until task %s is finished", task_id)

                    # {'taskID': '5e7b6cd0-d9d7-4e48-b525-7f1f0a612ff7',
                    # 'taskState': 'running', 'taskResult': '', 'code': 0,
                    # 'message': 'running job 1 of 1'}
                    while True:
                        time.sleep(0.5)
                        status = vdsm.Task.getStatus(taskID=task_id)
                        log.debug("Task status: %s", status)
                        if status["taskState"] != "running":
                            break

                    if status["code"] != 0:
                        log.error("Task failed: %s", status["message"])
                        errors[name] += 1

                    log.debug("Clearing task %s", task_id)
                    vdsm.Task.clear(taskID=task_id)

    log.info("Reader finished")