def discover(self, firstSuccessful=1):
     for ip, contextsByCredentialsMap in self.contextsMap.items():
         logger.debug("Connecting by IP %s" % ip)
         for contextList in contextsByCredentialsMap.values():
             for context in contextList:
                 try:
                     client = self._connectByContext(context)
                     try:
                         context.client = client
                         self.connectionHandler.onConnection(context)
                         if firstSuccessful:
                             return
                     finally:
                         if client:
                             client.close()
                 except JException, ex:
                     msg = ex.getMessage()
                     logger.debug(msg)
                     errormessages.resolveAndAddToCollections(msg, VcloudProtocol.DISPLAY, context.warnings, context.errors)
                     self.connectionHandler.onFailure(context)
                 except Exception, ex:
                     msg = str(ex)
                     logger.debugException(msg)
                     errormessages.resolveAndAddToCollections(msg, VcloudProtocol.DISPLAY, context.warnings, context.errors)
                     self.connectionHandler.onFailure(context)
Exemple #2
0
 def discover(self, firstSuccessful=1):
     for ip, contextsByCredentialsMap in self.contextsMap.items():
         logger.debug("Connecting by IP %s" % ip)
         for contextList in contextsByCredentialsMap.values():
             for context in contextList:
                 try:
                     client = self._connectByContext(context)
                     try:
                         context.client = client
                         self.connectionHandler.onConnection(context)
                         if firstSuccessful:
                             return
                     finally:
                         if client:
                             client.close()
                 except JException, ex:
                     msg = ex.getMessage()
                     logger.debug(msg)
                     errormessages.resolveAndAddToCollections(
                         msg, VcloudProtocol.DISPLAY, context.warnings,
                         context.errors)
                     self.connectionHandler.onFailure(context)
                 except Exception, ex:
                     msg = str(ex)
                     logger.debugException(msg)
                     errormessages.resolveAndAddToCollections(
                         msg, VcloudProtocol.DISPLAY, context.warnings,
                         context.errors)
                     self.connectionHandler.onFailure(context)
Exemple #3
0
    def discover(self, firstSuccessful=1):
        
        if not self.contextsMap:
            raise ValueError("No connection configurations were found")
        
        for contextsByCredentialsMap in self.contextsMap.values():
            
            for contextList in contextsByCredentialsMap.values():
                
                for context in contextList:
                    try:
                        
                        client = self._connectByContext(context)
                        try:
                            
                            self._fillInSuccessContext(client, context)
                            
                            logger.debug("Connected to VMware server, type %s, version %s, client type %s" % (context.apiType, context.apiVersion, context.clientType))
                            
                            self.connectionHandler.onConnection(context)

                            if firstSuccessful:
                                return
                        finally:
                            if client:
                                client.close()
                                
                    except AxisFault, axisFault:
                        faultType = _vmware_vim_base.getFaultType(axisFault)
                        if faultType == AxisFaultType.INVALID_LOGIN:
                            msg = errormessages.makeErrorMessage(_vmware_vim_base.VimProtocol.DISPLAY, None, errormessages.ERROR_INVALID_USERNAME_PASSWORD)
                            logger.debug(msg)
                            context.errors.append(msg)
                        
                        else:
                            msg = None
                            if faultType == AxisFaultType.NO_PERMISSION:
                                priviledgeId = axisFault.getPrivilegeId()
                                msg = "User does not have required '%s' permission" % priviledgeId
                                logger.debug(msg)
                            else:
                                msg = axisFault.getFaultString()
                                dump = axisFault.dumpToString()
                                logger.debug(dump)

                            errormessages.resolveAndAddToCollections(msg, _vmware_vim_base.VimProtocol.DISPLAY, context.warnings, context.errors)
                        
                        self.connectionHandler.onFailure(context)
                            
                    except JavaException, ex:
                        msg = ex.getMessage()
                        logger.debug(msg)
                        errormessages.resolveAndAddToCollections(msg, _vmware_vim_base.VimProtocol.DISPLAY, context.warnings, context.errors)
                        self.connectionHandler.onFailure(context)
                    except:
                        msg = logger.prepareJythonStackTrace('')
def _connectToGateway(ip, port, credentialsId, matchers, Framework, errors, warnings):
	client = None
	try:
		client = siebel_common.createClient(Framework, ip, matchers, credentialsId, port)
		return client
	except JException, ex:
		strException = ex.getMessage()
		errormessages.resolveAndAddToCollections(strException, PROTOCOL_NAME, warnings, errors)
		logger.debugException('')
		if client:
			client.close()
Exemple #5
0
def _connectToGateway(ip, port, credentialsId, matchers, Framework, errors,
                      warnings):
    client = None
    try:
        client = siebel_common.createClient(Framework, ip, matchers,
                                            credentialsId, port)
        return client
    except JException, ex:
        strException = ex.getMessage()
        errormessages.resolveAndAddToCollections(strException, PROTOCOL_NAME,
                                                 warnings, errors)
        logger.debugException('')
        if client:
            client.close()
    def discover(self, firstSuccessful=True):
        '''
        bool -> None
        @raise ValueError in case no connection configurations were initialized
        Perform discovery of connections
        '''

        if not self.contextsMap:
            raise NoConnectionConfigurationsException(
                "No connection configurations were found")

        vmwareNamespaces = [ns for ns in self.vmwareCategory.getNamespaces()]
        vmwareNamespacesCount = len(vmwareNamespaces)

        for contextsByCredentialsMap in self.contextsMap.itervalues():

            for contextList in contextsByCredentialsMap.itervalues():

                for context in contextList:

                    successfulNamespaces = []
                    for namespace in vmwareNamespaces:

                        try:
                            cim_discover.testConnectionWithNamespace(
                                self.framework, context.ipAddress,
                                context.credentialId, namespace)
                            # no exception, connection successful
                            successfulNamespaces.append(namespace)

                        except JException, ex:
                            msg = ex.getMessage()
                            msg = cim_discover.translateErrorMessage(msg)
                            logger.debug(msg)
                            errormessages.resolveAndAddToCollections(
                                msg, cim.Protocol.DISPLAY, context.warnings,
                                context.errors)
                            self.connectionHandler.onFailure(context)
                            break

                        except:
                            msg = logger.prepareJythonStackTrace('')
                            logger.debug(msg)
                            errormessages.resolveAndAddToCollections(
                                msg, cim.Protocol.DISPLAY, context.warnings,
                                context.errors)
                            self.connectionHandler.onFailure(context)
                            break
    def discover(self, firstSuccessful=True):
        '''
        bool -> None
        @raise ValueError in case no connection configurations were initialized
        Perform discovery of connections
        '''
        
        if not self.contextsMap:
            raise NoConnectionConfigurationsException("No connection configurations were found")
        
        vmwareNamespaces = [ns for ns in self.vmwareCategory.getNamespaces()]
        vmwareNamespacesCount = len(vmwareNamespaces)
        
        for contextsByCredentialsMap in self.contextsMap.itervalues():
            
            for contextList in contextsByCredentialsMap.itervalues():
                
                for context in contextList:

                    successfulNamespaces = []
                    for namespace in vmwareNamespaces:
                    
                        try:
                            cim_discover.testConnectionWithNamespace(self.framework, context.ipAddress, context.credentialId, namespace)
                            # no exception, connection successful
                            successfulNamespaces.append(namespace)
                            
                        except JException, ex:
                            msg = ex.getMessage()
                            msg = cim_discover.translateErrorMessage(msg)
                            logger.debug(msg)
                            errormessages.resolveAndAddToCollections(msg, cim.Protocol.DISPLAY, context.warnings, context.errors)
                            self.connectionHandler.onFailure(context)
                            break
                        
                        except:
                            msg = logger.prepareJythonStackTrace('')
                            logger.debug(msg)
                            errormessages.resolveAndAddToCollections(msg, cim.Protocol.DISPLAY, context.warnings, context.errors)
                            self.connectionHandler.onFailure(context)
                            break
Exemple #8
0
                      warnings):
    client = None
    try:
        client = siebel_common.createClient(Framework, ip, matchers,
                                            credentialsId, port)
        return client
    except JException, ex:
        strException = ex.getMessage()
        errormessages.resolveAndAddToCollections(strException, PROTOCOL_NAME,
                                                 warnings, errors)
        logger.debugException('')
        if client:
            client.close()
    except:
        excInfo = str(sys.exc_info()[1])
        errormessages.resolveAndAddToCollections(excInfo, PROTOCOL_NAME,
                                                 warnings, errors)
        logger.debugException('')
        if client:
            client.close()


def discoverGatewayConnection(ip, ports, credentialIds, matchers, Framework,
                              errors, warnings):
    for port in ports:
        for credentialsId in credentialIds:
            client = _connectToGateway(ip, port, credentialsId, matchers,
                                       Framework, errors, warnings)
            if client is not None:
                return GatewayConnection(client, credentialsId, port)

Exemple #9
0
class ConnectionDiscoverer:
    '''
    Class discovers connection to VMware Server
    Url for connection is provided by UrlGenerator
    IP addresses are expected to be set
    '''
    def __init__(self, framework):
        self.framework = framework
        
        self.urlGenerator = None
        
        self.ips = []
        
        self.credentialId = None
        
        # map(ip, map(credentialsId, list(context)))
        self.contextsMap = {}
        
        self.connectionHandler = None
    
    def setUrlGenerator(self, generator):
        self.urlGenerator = generator
        
    def setConnectionHandler(self, connectionHandler):
        self.connectionHandler = connectionHandler
    
    def setCredentialId(self, credentialId):
        self.credentialId = credentialId
    
    def setIps(self, ips):
        self.ips = ips
    
    def addIp(self, ip):
        self.ips.append(ip)
        
    def initConnectionConfigurations(self):
        contextsMap = {}
        for ip in self.ips:
            
            credentialsIdList = []
            if self.credentialId:
                #credentials is specified, only use this one
                credentialsIdList.append(self.credentialId)
                
            else:
                credentialsIdList = self.framework.getAvailableProtocols(ip, _vmware_vim_base.VimProtocol.SHORT)
                if not credentialsIdList:
                    logger.warn("No credentials for IP %s found" % ip)
                    msg = errormessages.makeErrorMessage(_vmware_vim_base.VimProtocol.DISPLAY, None, errormessages.ERROR_NO_CREDENTIALS)
                    connectionContext = ConnectionContext()
                    connectionContext.ipAddress = ip
                    connectionContext.warnings.append(msg)
                    self.connectionHandler.onFailure(connectionContext)
                    continue
            
            contextsByCredentialsId = {}
            for credentialsId in credentialsIdList:
                
                connectionContext = ConnectionContext()
                connectionContext.ipAddress = ip
                connectionContext.credentialsId = credentialsId
                
                contexts = []
                self.urlGenerator.generate(connectionContext)
                for url in self.urlGenerator:
                    connectionContextWithUrl = copy.copy(connectionContext)
                    connectionContextWithUrl.urlString = url
                    contexts.append(connectionContextWithUrl)
                
                if contexts:
                    contextsByCredentialsId[credentialsId] = contexts
            
            if contextsByCredentialsId:
                contextsMap[ip] = contextsByCredentialsId
        
        self.contextsMap = contextsMap
    
    def discover(self, firstSuccessful=1):
        
        if not self.contextsMap:
            raise ValueError("No connection configurations were found")
        
        for contextsByCredentialsMap in self.contextsMap.values():
            
            for contextList in contextsByCredentialsMap.values():
                
                for context in contextList:
                    try:
                        
                        client = self._connectByContext(context)
                        try:
                            
                            self._fillInSuccessContext(client, context)
                            
                            logger.debug("Connected to VMware server, type %s, version %s, client type %s" % (context.apiType, context.apiVersion, context.clientType))
                            
                            self.connectionHandler.onConnection(context)

                            if firstSuccessful:
                                return
                        finally:
                            if client:
                                client.close()
                                
                    except AxisFault, axisFault:
                        faultType = _vmware_vim_base.getFaultType(axisFault)
                        if faultType == AxisFaultType.INVALID_LOGIN:
                            msg = errormessages.makeErrorMessage(_vmware_vim_base.VimProtocol.DISPLAY, None, errormessages.ERROR_INVALID_USERNAME_PASSWORD)
                            logger.debug(msg)
                            context.errors.append(msg)
                        
                        else:
                            msg = None
                            if faultType == AxisFaultType.NO_PERMISSION:
                                priviledgeId = axisFault.getPrivilegeId()
                                msg = "User does not have required '%s' permission" % priviledgeId
                                logger.debug(msg)
                            else:
                                msg = axisFault.getFaultString()
                                dump = axisFault.dumpToString()
                                logger.debug(dump)

                            errormessages.resolveAndAddToCollections(msg, _vmware_vim_base.VimProtocol.DISPLAY, context.warnings, context.errors)
                        
                        self.connectionHandler.onFailure(context)
                            
                    except JavaException, ex:
                        msg = ex.getMessage()
                        logger.debug(msg)
                        errormessages.resolveAndAddToCollections(msg, _vmware_vim_base.VimProtocol.DISPLAY, context.warnings, context.errors)
                        self.connectionHandler.onFailure(context)
                    except:
                        msg = logger.prepareJythonStackTrace('')
                        logger.debug(msg)
                        errormessages.resolveAndAddToCollections(msg, _vmware_vim_base.VimProtocol.DISPLAY, context.warnings, context.errors)
                        self.connectionHandler.onFailure(context)                
		self.port = port

def _connectToGateway(ip, port, credentialsId, matchers, Framework, errors, warnings):
	client = None
	try:
		client = siebel_common.createClient(Framework, ip, matchers, credentialsId, port)
		return client
	except JException, ex:
		strException = ex.getMessage()
		errormessages.resolveAndAddToCollections(strException, PROTOCOL_NAME, warnings, errors)
		logger.debugException('')
		if client:
			client.close()
	except:
		excInfo = str(sys.exc_info()[1])
		errormessages.resolveAndAddToCollections(excInfo, PROTOCOL_NAME, warnings, errors)
		logger.debugException('')
		if client:
			client.close()


def discoverGatewayConnection(ip, ports, credentialIds, matchers, Framework, errors, warnings):
	for port in ports:
		for credentialsId in credentialIds:
			client = _connectToGateway(ip, port, credentialsId, matchers, Framework, errors, warnings)
			if client is not None:
				return GatewayConnection(client, credentialsId, port)
					
					
def DiscoveryMain(Framework):
	OSHVResult = ObjectStateHolderVector()