cloudmesh_client.db package

Submodules

cloudmesh_client.db.CloudmeshDatabase module

class cloudmesh_client.db.CloudmeshDatabase.CloudmeshDatabase[source]

Bases: object

def __init__(self, user=None):

self.__dict__ = self.__shared_state

if self.initialized is None:

self.user = ConfigDict(“cloudmesh.yaml”)[“cloudmesh.profile.user”] self.filename = Config.path_expand(os.path.join(“~”, “.cloudmesh”, “cloudmesh.db”)) self.engine = create_engine(‘sqlite:///{}’.format(self.filename), echo=False) self.data = {“filename”: self.filename}

if user is None:
self.user = ConfigDict(“cloudmesh.yaml”)[“cloudmesh.profile.user”]
else:
self.user = user

CloudmeshDatabase.create() CloudmeshDatabase.create_tables() CloudmeshDatabase.start()

# # MODEL # @classmethod def create(cls):

# cls.clean() filename = Config.path_expand(os.path.join(“~”, “.cloudmesh”, “cloudmesh.db”)) if not os.path.isfile(filename):

cls.create_model()
class Base(**kwargs)

Bases: object

The most base type

metadata = MetaData(bind=None)
classmethod add(d, replace=True)[source]

o dotdict

if o is a dict an object of that type is created. It is checked if another object in the db already exists, if so the attributes of the object will be overwritten with the once in the database

provider, kind, category, name must be set to identify the object

o is in CloudmeshDatabase.Base

this is an object of a table has been created and is to be added. It is checked if another object in the db already exists. If so the attributes of the existing object will be updated.
classmethod add_new(d, replace=True)[source]

o dotdict

if o is a dict an object of that type is created. It is checked if another object in the db already exists, if so the attributes of the object will be overwritten with the once in the database

provider, kind, category, name must be set to identify the object

o is in CloudmeshDatabase.Base

this is an object of a table has been created and is to be added. It is checked if another object in the db already exists. If so the attributes of the existing object will be updated.
classmethod add_obj(objects)[source]
classmethod all(provider='general', category=None, kind=None, table=None)[source]
classmethod clean()[source]
classmethod clear(kind, category, user=None)[source]

This method deletes all ‘kind’ entries from the cloudmesh database :param category: the category name

classmethod create()[source]
classmethod create_model()[source]
classmethod create_tables()[source]
Returns:the list of tables in model
data = {'filename': '/Users/fuwang/.cloudmesh/cloudmesh.db'}
classmethod delete(**kwargs)[source]
Parameters:kind
Returns:
classmethod delete_(table, **filter_args)[source]

Delete rows in the table matching filter_args

Parameters:table (type) – the model class
engine = Engine(sqlite:////Users/fuwang/.cloudmesh/cloudmesh.db)
classmethod filter_by(**kwargs)[source]

This method returns either a) an array of objects from the database in dict format, that match a particular kind.

If the kind is not specified vm is used. one of the arguments must be scope=”all”
  1. a single entry that matches the first occurance of the query specified by kwargs, such as name=”vm_001”
Parameters:kwargs – the arguments to be matched, scope defines if all or just the first value is returned. first is default.
Returns:a list of objects, if scope is first a single object in dotdict format is returned
classmethod find(**kwargs)[source]

This method returns either a) an array of objects from the database in dict format, that match a particular kind.

If the kind is not specified vm is used. one of the arguments must be scope=”all”
  1. a single entry that matches the first occurance of the query specified by kwargs, such as name=”vm_001”

To select a value from a specific table: 1) identify the table of interest with table()

>>> t = db.table(name='default')
  1. specify the ‘table’ keywork: >>> db.find(table=t, cm_id=42)
Parameters:kwargs – the arguments to be matched, scope defines if all or just the first value is returned. first is default.
Returns:a list of objects, if scope is first a single object in dotdict format is returned
find_new(**kwargs)[source]

This method returns either a) an array of objects from the database in dict format, that match a particular kind.

If the kind is not specified vm is used. one of the arguments must be scope=”all”
  1. a single entry that matches the first occurance of the query specified by kwargs, such as name=”vm_001”
Parameters:kwargs – the arguments to be matched, scope defines if all or just the first value is returned. first is default.
Returns:a list of objects, if scope is first a single object in dotdict format is returned
classmethod get_table_from_kind(kind)[source]
classmethod info(kind=None)[source]
initialized = None
classmethod insert(obj)[source]

Insert a row into the database

Parameters:obj – the object model to insert
Returns:
Return type:
classmethod refresh(kind, name, **kwargs)[source]

This method refreshes the local database with the live cloud details :param kind: :param name: :param kwargs: :return:

classmethod refresh_new(kind, name, **kwargs)[source]

This method refreshes the local database with the live cloud details :param kind: :param name: :param kwargs: :return:

classmethod save()[source]
classmethod select(table, **filter_args)[source]

Return rows of the table matching filter args.

This is a proxy for sqlalchemy’s session.query(table).filter(**kwargs)

Parameters:table (type) – the model class
Returns:all rows in the table matching **filter_args
session = <sqlalchemy.orm.session.Session object>
classmethod set(name, attribute, value, provider=None, kind=None, scope='all')[source]
classmethod start()[source]
classmethod table(provider=None, kind=None, name=None)[source]
Parameters:
  • category
  • kind
Returns:

the table class based on a given table name. In case the table does not exist an exception is thrown

tables = [<class 'cloudmesh_client.db.general.model.SPECIFICATION'>, <class 'cloudmesh_client.db.general.model.WORKFLOW'>, <class 'cloudmesh_client.db.general.model.DEFAULT'>, <class 'cloudmesh_client.db.general.model.VAR'>, <class 'cloudmesh_client.db.general.model.LAUNCHER'>, <class 'cloudmesh_client.db.general.model.KEY'>, <class 'cloudmesh_client.db.general.model.GROUP'>, <class 'cloudmesh_client.db.general.model.RESERVATION'>, <class 'cloudmesh_client.db.general.model.SECGROUPRULE'>, <class 'cloudmesh_client.db.general.model.BATCHJOB'>, <class 'cloudmesh_client.db.general.model.CLUSTER'>, <class 'cloudmesh_client.db.openstack.model.IMAGE_OPENSTACK'>, <class 'cloudmesh_client.db.openstack.model.FLAVOR_OPENSTACK'>, <class 'cloudmesh_client.db.openstack.model.VM_OPENSTACK'>, <class 'cloudmesh_client.db.azure.model.IMAGE_AZURE'>, <class 'cloudmesh_client.db.azure.model.FLAVOR_AZURE'>, <class 'cloudmesh_client.db.azure.model.VM_AZURE'>, <class 'cloudmesh_client.db.azure.model.KEY_AZURE'>, <class 'cloudmesh_client.db.libcloud.model.IMAGE_LIBCLOUD'>, <class 'cloudmesh_client.db.libcloud.model.FLAVOR_LIBCLOUD'>, <class 'cloudmesh_client.db.libcloud.model.VM_LIBCLOUD'>]
classmethod to_dict(obj, key='name')[source]

convert the object to dict

Parameters:obj
Returns:
classmethod to_list(obj)[source]

convert the object to dict

Parameters:obj
Returns:
classmethod update(**kwargs)[source]
Parameters:
  • kind
  • kwargs
Returns:

classmethod updateObj(obj)[source]
classmethod update_(table, where=None, values=None)[source]

Updates a subset of rows in the table, filtered by where, setting to values.

Parameters:
  • table (type) – the table class
  • where (dict) – match rows where all these properties hold
  • values (dict) – set the columns to these values
user = None
classmethod vm_table_from_provider(provider)[source]
class cloudmesh_client.db.CloudmeshDatabase.CloudmeshMixin[source]

Bases: object

category = Column(None, String(), table=None)
cm_id = Column(None, Integer(), table=None, primary_key=True, nullable=False)
created_at = Column(None, String(), table=None, default=ColumnDefault('2017-07-09 14:07:50'))
kind = Column(None, String(), table=None)
label = Column(None, String(), table=None)
name = Column(None, String(), table=None)
project = Column(None, String(), table=None)
provider = Column(None, String(), table=None)
set_defaults(**kwargs)[source]
set_user()[source]
type = Column(None, String(), table=None)
updated_at = Column(None, String(), table=None, onupdate=ColumnDefault('2017-07-09 14:07:50'), default=ColumnDefault('2017-07-09 14:07:50'))
user = Column(None, String(), table=None)
class cloudmesh_client.db.CloudmeshDatabase.CloudmeshVMMixin[source]

Bases: object

cluster = Column(None, String(), table=None)
set_defaults(**kwargs)[source]

Module contents