def api_query(self, query, results=False): """ Description: Run a query on the PGSQL connection. By default, no results are returned. If results are desired/needed then be sure to call as: api_query(query, results=True) """ try: if self.connection.closed: import psycopg2 self.connection = psycopg2.connect(database=self.dbname, user=self.uname, password=self.passwd, host=self.host, port=self.port) cursor = self.connection.cursor() #initialize our session in the database so we can use Impulse's #create/remove functions, and let Impulse deal with who's an RTP, etc cursor.execute("SELECT api.initialize('%s');" % get_username()) #Finally actually run our query cursor.execute(query) if results: ret = cursor.fetchall() cursor.close() #commit the changes we made self.connection.commit() self.connection.close() except Exception, error: raise error
def __init__(self, name=None, sys_type=None, osname=None, comment=None): """ Description: The constructor for System. Passing in parameters is allowed, but not required. Properties are only required when System.put() is used, as that is when the object is stored in the Impulse database """ self.system_name = name self.type = sys_type self.os_name = osname self.comment = comment self.owner = get_username() self.constraints ImpulseObject.__init__(self) if name and self.type and osname: self.create()