Permalink
Browse files

Some cleanup including parameter new-object gotcha

  • Loading branch information...
1 parent 92a15ac commit 909b1db006c00ab3f15f72c37a2aaab4ced3a07c @timf timf committed Jan 30, 2011
Showing with 17 additions and 15 deletions.
  1. +17 −15 cloudminer/cloudminer.py
View
@@ -1,16 +1,12 @@
-import datetime
-import uuid
-import simplejson as json
import sqlalchemy
from sqlalchemy import ForeignKey
-from sqlalchemy.orm import relation, backref
+from sqlalchemy.orm import relation
from sqlalchemy.orm import mapper
from sqlalchemy.orm import sessionmaker
from sqlalchemy import Table
from sqlalchemy import Integer
from sqlalchemy import String, MetaData, Sequence
from sqlalchemy import Column
-import cloudyvents.cyvents as cyvents
from sqlalchemy import and_
class _CYventExtra(object):
@@ -32,10 +28,13 @@ def __init__(self, source, name, key, timestamp, extra):
class _CYVM(object):
- def __init__(self, runname, iaasid, hostname, service_type, runlogdir, vmlogdir, events=[]):
+ def __init__(self, runname, iaasid, hostname, service_type, runlogdir, vmlogdir, events=None):
self.runname = runname
self.iaasid = iaasid
- self.events = events
+ if events:
+ self.events = events
+ else:
+ self.events = []
self.hostname = hostname
self.service_type = service_type
self.vmlogdir = vmlogdir
@@ -82,38 +81,41 @@ def add_event(self, e):
class CloudMiner(object):
def __init__(self, dburl, module=None):
- if module == None:
- self.engine = sqlalchemy.create_engine(dburl)
- else:
+ if module:
self.engine = sqlalchemy.create_engine(dburl, module=module)
- metadata.create_all(self.engine)
+ else:
+ self.engine = sqlalchemy.create_engine(dburl)
+ metadata.create_all(self.engine)
self.Session = sessionmaker(bind=self.engine)
self.session = self.Session()
def add_cloudyvent_vm(self, runname, iaasid, hostname, service_type, runlogdir, vmlogdir):
+ """Add VM to db
+ Return True if this is new.
+ """
cyvm = self.get_by_iaasid(iaasid)
- if cyvm == None:
+ if not cyvm:
cyvm = _CYVM(runname, iaasid, hostname, service_type, runlogdir, vmlogdir)
self.session.add(cyvm)
return True
else:
cyvm.hostname = hostname
cyvm.service_type = service_type
- return False
+ return False
def add_cloudyvent(self, runname, iaasid, hostname, service_type, runlogdir, vmlogdir, cyv):
# first see if we already have this iaasid. if not create it
cyvm = self.get_by_iaasid(iaasid)
- if cyvm == None:
+ if not cyvm:
cyvm = _CYVM(runname, iaasid, hostname, service_type, runlogdir, vmlogdir)
self.session.add(cyvm)
cyvm.hostname = hostname
cyvm.service_type = service_type
xtras_list = []
- if cyv.extra != None:
+ if cyv.extra is not None:
for k in cyv.extra.keys():
va = cyv.extra[k]
if type(va) != type([]):

0 comments on commit 909b1db

Please sign in to comment.