def __init__(self, url): self.log = logging.getLogger('%s.%s' % (__name__, self.__class__.__name__)) self._managedObjects = {} self.session = None # create a connection and connect to qpidd # TODO: (redmine 277) - Make this use actual amqp:// urls... currently, only host works self.connection = cqpid.Connection(url, "{reconnect:True}") self.connection.open() # Create, configure, and open a QMFv2 agent session using the connection. self.session = AgentSession(self.connection) self.session.setVendor("redhat.com") self.session.setProduct("imagefactory") self.session.open() # Initialize the parent class with the session. AgentHandler.__init__(self, self.session) # Register our schemata with the agent session. self.session.registerSchema(ImageFactory.qmf_schema) self.session.registerSchema(BuildAdaptor.qmf_schema) self.session.registerSchema(BuildAdaptor.qmf_event_schema_status) self.session.registerSchema(BuildAdaptor.qmf_event_schema_percentage) self.session.registerSchema(BuildAdaptor.qmf_event_schema_build_failed) # Now add the image factory object self.image_factory = ImageFactory() self.image_factory.agent = self self.image_factory_addr = self.session.addData( self.image_factory.qmf_object, "image_factory") self.log.info("image_factory has qmf/qpid address: %s", self.image_factory_addr)
def __init__(self): self.cpe_obj = None self.dpe_obj = None self.conn = cqpid.Connection('localhost:49000') self.conn.open() self.session = qmf2.ConsoleSession(self.conn) self.session.setAgentFilter('[]') self.session.open() self.l = logging.getLogger() time.sleep(3) agents = self.session.getAgents() for a in agents: self.l.debug('agent: %s' % str(a)) if 'cloudpolicyengine.org' in a.getVendor(): result = a.query( "{class:cpe, package:'org.cloudpolicyengine'}") if len(result) >= 1: self.cpe_obj = result[0] if self.cpe_obj is None: print '' print 'No cpe agent!, aaarrggg' print '' sys.exit(3)
def __init__(self, logger): self.cpe_obj = None self.conn = cqpid.Connection('localhost:49000') self.conn.open() self.session = qmf2.ConsoleSession(self.conn) self.session.setAgentFilter('[]') self.session.open() self.l = logger attempts = 0 while self.cpe_obj is None: agents = self.session.getAgents() for a in agents: self.l.debug('agent: %s' % str(a)) if 'pacemakercloud.org' in a.getVendor(): result = a.query( "{class:cpe, package:'org.pacemakercloud'}") if len(result) >= 1: self.cpe_obj = result[0] if self.cpe_obj is None: attempts = attempts + 1 if attempts > 50: print '*** Could not find cped agent...' sys.exit(3) else: time.sleep(0.1)
def __init__(self): threading.Thread.__init__(self) self.connection = cqpid.Connection('localhost:49000', '') self.connection.open() self.session = qmf2.ConsoleSession(self.connection) self.session.open() self.session.setAgentFilter( "[eq, _vendor, [quote, 'pacemakercloud.org']]") self.receiver = eventreceiver.EventReceiver(self.session)
def setUp(self): logging.basicConfig( level=logging.NOTSET, format= '%(asctime)s %(levelname)s %(name)s pid(%(process)d) Message: %(message)s', filename='/tmp/imagefactory-unittests.log') self.expected_state_transitions = (("NEW", "INITIALIZING"), ("INITIALIZING", "PENDING"), ("PENDING", "FINISHING"), ("FINISHING", "COMPLETED")) self.if_agent = ImageFactoryAgent("localhost") self.if_agent.start() self.connection = cqpid.Connection("localhost") self.connection.open() self.console_session = ConsoleSession(self.connection) self.console_session.setAgentFilter( "[and, [eq, _vendor, [quote, 'redhat.com']], [eq, _product, [quote, 'imagefactory']]]" ) self.console_session.open() self.console = MockConsole(self.console_session, self.if_agent.image_factory_addr) self.console.start() time.sleep(5) # Give the agent some time to show up.
def _connectToBroker(self, hostname, port): self.connection = cqpid.Connection(hostname + ":" + port) self.connection.open() self.session = ConsoleSession(self.connection) self.session.open()
from host import HostTest, HostLib, HostImpl from network import NetworkTest, NetworkLib, NetworkImpl from services import ServicesTest, ServicesLib, ServicesImpl MATAHARI_PACKAGE = 'matahariproject.org' if len(sys.argv) < 2: broker = "localhost:49000" else: broker = sys.argv[1] ### QMF connection print "Creating session...", sys.stdout.flush() connection = cqpid.Connection(broker) connection.open() session = qmf2.ConsoleSession(connection) session.open() session.setAgentFilter("[]") print " DONE" ### DBus def getDBus(obj, path, iface): try: return DBus(bus.get_object(obj, path), iface) except Exception as e: print "Unable to create DBus object (%s). DBus tests of object %s will be disabled." % ( e.message, obj)
def connectToBroker(hostname, port): connection = cqpid.Connection(hostname + ":" + port) connection.open() session = ConsoleSession(connection) session.open() return [connection, session]
def agentAdded(self, agent): print "Agent Added: %r" % agent def agentDeleted(self, agent, reason): print "Agent Deleted: %r reason: %s" % (agent, reason) def agentRestarted(self, agent): print "Agent Restarted: %r" % agent def agentSchemaUpdated(self, agent): print "Agent Schema Updated: %r" % agent def eventRaised(self, agent, data, timestamp, severity): print "Event: data=%r time=%d sev=%d" % (data.getProperties(), timestamp, severity) url = "localhost" options = "" connection = cqpid.Connection(url, options) connection.open() session = qmf2.ConsoleSession(connection) session.open() session.setAgentFilter("[]") main = FindAgents(session) main.run()