示例#1
0
文件: migration.py 项目: mykaul/vdsm
    def _setupVdsConnection(self):
        if self.hibernating:
            return

        hostPort = vdscli.cannonizeHostPort(
            self._dst,
            config.getint('addresses', 'management_port'))
        self.remoteHost, port = hostPort.rsplit(':', 1)

        try:
            client = self._createClient(port)
            requestQueues = config.get('addresses', 'request_queues')
            requestQueue = requestQueues.split(",")[0]
            self._destServer = jsonrpcvdscli.connect(requestQueue, client)
            self.log.debug('Initiating connection with destination')
            self._destServer.ping()

        except (JsonRpcBindingsError, JsonRpcNoResponseError):
            if config.getboolean('vars', 'ssl'):
                self._destServer = vdscli.connect(
                    hostPort,
                    useSSL=True,
                    TransportClass=kaxmlrpclib.TcpkeepSafeTransport)
            else:
                self._destServer = kaxmlrpclib.Server('http://' + hostPort)

        self.log.debug('Destination server is: ' + hostPort)
示例#2
0
    def _setupVdsConnection(self):
        if self.hibernating:
            return

        hostPort = vdscli.cannonizeHostPort(
            self._dst, config.getint('addresses', 'management_port'))
        self.remoteHost, port = hostPort.rsplit(':', 1)

        try:
            client = self._createClient(port)
            requestQueues = config.get('addresses', 'request_queues')
            requestQueue = requestQueues.split(",")[0]
            self._destServer = jsonrpcvdscli.connect(requestQueue, client)
            self.log.debug('Initiating connection with destination')
            self._destServer.ping()

        except (JsonRpcBindingsError, JsonRpcNoResponseError):
            if config.getboolean('vars', 'ssl'):
                self._destServer = vdscli.connect(
                    hostPort,
                    useSSL=True,
                    TransportClass=kaxmlrpclib.TcpkeepSafeTransport)
            else:
                self._destServer = kaxmlrpclib.Server('http://' + hostPort)

        self.log.debug('Destination server is: ' + hostPort)
示例#3
0
 def testAddressWithPortParameter(self):
     addr = '127.0.0.1'
     port = 65432
     res = vdscli.cannonizeHostPort(addr, port)
     self._assertIsIpAddressWithPort(res)
     # address must include the given port
     self.assertTrue(res.endswith(str(port)))
示例#4
0
文件: migration.py 项目: vinzenz/vdsm
    def _setupVdsConnection(self):
        if self._mode == 'file':
            return

        # FIXME: The port will depend on the binding being used.
        # This assumes xmlrpc
        hostPort = vdscli.cannonizeHostPort(
            self._dst, self._vm.cif.bindings['xmlrpc'].serverPort)
        self.remoteHost, self.remotePort = hostPort.rsplit(':', 1)

        if config.getboolean('vars', 'ssl'):
            self.destServer = vdscli.connect(
                hostPort,
                useSSL=True,
                TransportClass=kaxmlrpclib.TcpkeepSafeTransport)
        else:
            self.destServer = kaxmlrpclib.Server('http://' + hostPort)
        self.log.debug('Destination server is: ' + hostPort)
        try:
            self.log.debug('Initiating connection with destination')
            status = self.destServer.getVmStats(self._vm.id)
            if not status['status']['code']:
                self.log.error("Machine already exists on the destination")
                self.status = errCode['exist']
        except Exception:
            self.log.error("Error initiating connection", exc_info=True)
            self.status = errCode['noConPeer']
示例#5
0
    def _setupVdsConnection(self):
        if self.hibernating:
            return

        # FIXME: The port will depend on the binding being used.
        # This assumes xmlrpc
        hostPort = vdscli.cannonizeHostPort(
            self._dst,
            config.getint('addresses', 'management_port'))
        self.remoteHost, _ = hostPort.rsplit(':', 1)

        if config.getboolean('vars', 'ssl'):
            self._destServer = vdscli.connect(
                hostPort,
                useSSL=True,
                TransportClass=kaxmlrpclib.TcpkeepSafeTransport)
        else:
            self._destServer = kaxmlrpclib.Server('http://' + hostPort)
        self.log.debug('Destination server is: ' + hostPort)
        try:
            self.log.debug('Initiating connection with destination')
            status = self._destServer.getVmStats(self._vm.id)
            if not status['status']['code']:
                self.log.error("Machine already exists on the destination")
                self.status = errCode['exist']
        except Exception:
            self.log.exception("Error initiating connection")
            self.status = errCode['noConPeer']
示例#6
0
 def testAddressWithPortParameter(self):
     addr = '127.0.0.1'
     port = 65432
     res = vdscli.cannonizeHostPort(addr, port)
     self._assertIsIpAddressWithPort(res)
     # address must include the given port
     self.assertTrue(res.endswith(str(port)))
def run_vds_client_cmd(address, use_ssl, command, *args, **kwargs):
    """
    Run the passed in command name from the vdsClient library and either
    throw an exception with the error message or return the results.
    """
    # FIXME pass context to allow for shared or persistent vdsm connection
    log = logging.getLogger('SubmonitorUtil')
    log.debug("Connecting to vdsClient at %s with ssl=%r", address, use_ssl)
    vdsClient = util.loadModule(
        path=constants.VDS_CLIENT_DIR,
        name='vdsClient'
    )
    if vdsClient._glusterEnabled:
        serv = vdsClient.ge.GlusterService()
    else:
        serv = vdsClient.service()
    serv.useSSL = use_ssl

    if hasattr(vdscli, 'cannonizeAddrPort'):
        server, server_port = vdscli.cannonizeAddrPort(
            address
        ).split(':', 1)
        serv.do_connect(server, server_port)
    else:
        host_port = vdscli.cannonizeHostPort(address)
        serv.do_connect(host_port)

    log.debug("Connected, running %s, args %r, kwargs %r",
              command, args, kwargs)

    method = getattr(serv.s, command)
    retry = 0
    response = None
    new_args = list(args)
    # Add keyword args to argument list as a dict for vds api compatibility
    if kwargs:
        new_args.append(kwargs)
    while retry < constants.VDS_CLIENT_MAX_RETRY:
        try:
            response = method(*new_args)
            break
        except socket.error:
            log.debug("Error", exc_info=True)
            retry += 1
            time.sleep(1)

    log.debug("Response: %r", response)
    if retry >= constants.VDS_CLIENT_MAX_RETRY:
        raise Exception("VDSM initialization timeout")
    if response and response['status']['code'] != 0:
        raise DetailedError("Error {0} from {1}: {2}"
                            .format(response['status']['code'],
                                    command,
                                    response['status']['message']),
                            response['status']['message'])
    return response
示例#8
0
文件: migration.py 项目: txomon/vdsm
    def _setupVdsConnection(self):
        if self.hibernating:
            return

        # FIXME: The port will depend on the binding being used.
        # This assumes xmlrpc
        hostPort = vdscli.cannonizeHostPort(
            self._dst,
            config.getint('addresses', 'management_port'))
        self.remoteHost, _ = hostPort.rsplit(':', 1)

        if config.getboolean('vars', 'ssl'):
            self._destServer = vdscli.connect(
                hostPort,
                useSSL=True,
                TransportClass=kaxmlrpclib.TcpkeepSafeTransport)
        else:
            self._destServer = kaxmlrpclib.Server('http://' + hostPort)
        self.log.debug('Destination server is: ' + hostPort)
    def _connect(self):
        vdsClient = util.loadModule(
            path=ohostedcons.FileLocations.VDS_CLIENT_DIR,
            name='vdsClient'
        )
        serv = None
        if vdsClient._glusterEnabled:
            serv = vdsClient.ge.GlusterService()
        else:
            serv = vdsClient.service()
        serv.useSSL = self.environment[ohostedcons.VDSMEnv.USE_SSL]
        if hasattr(vdscli, 'cannonizeAddrPort'):
            server, serverPort = vdscli.cannonizeAddrPort(
                'localhost'
            ).split(':', 1)
            serv.do_connect(server, serverPort)
        else:
            hostPort = vdscli.cannonizeHostPort('localhost')
            serv.do_connect(hostPort)

        self.environment[ohostedcons.VDSMEnv.VDS_CLI] = serv
        vdsmReady = False
        retry = 0
        while not vdsmReady and retry < self.MAX_RETRY:
            retry += 1
            try:
                hwinfo = serv.s.getVdsHardwareInfo()
                self.logger.debug(str(hwinfo))
                if hwinfo['status']['code'] == 0:
                    vdsmReady = True
                else:
                    self.logger.info(_('Waiting for VDSM hardware info'))
                    time.sleep(1)
            except socket.error:
                self.logger.info(_('Waiting for VDSM hardware info'))
                time.sleep(1)
示例#10
0
 def testNoneArgument(self):
     self._assertIsIpAddressWithPort(vdscli.cannonizeHostPort(None))
示例#11
0
 def testAddressWithPort(self):
     address = "127.0.0.1:65432"
     self.assertEqual(address, vdscli.cannonizeHostPort(address))
示例#12
0
 def testAddressNoPort(self):
     self._assertIsIpAddressWithPort(
         vdscli.cannonizeHostPort('127.0.0.1'))
示例#13
0
 def testNoneArgumentAndPort(self):
     port = 65432
     res = vdscli.cannonizeHostPort(None, port)
     self._assertIsIpAddressWithPort(res)
     # address must include the given port
     self.assertTrue(res.endswith(str(port)))
示例#14
0
 def testNoneArgument(self):
     self._assertIsIpAddressWithPort(vdscli.cannonizeHostPort(None))
示例#15
0
 def testAddressNoPort(self):
     self._assertIsIpAddressWithPort(vdscli.cannonizeHostPort('127.0.0.1'))
示例#16
0
 def testAddressWithPort(self):
     address = "127.0.0.1:65432"
     self.assertEqual(address, vdscli.cannonizeHostPort(address))
示例#17
0
 def testNoneArgumentAndPort(self):
     port = 65432
     res = vdscli.cannonizeHostPort(None, port)
     self._assertIsIpAddressWithPort(res)
     # address must include the given port
     self.assertTrue(res.endswith(str(port)))