cloudmesh.mongo.CmDatabase

Module Contents

Classes

CmDatabase

class cloudmesh.mongo.CmDatabase.CmDatabase(host=None, username=None, password=None, port=None)

Bases: object

__shared_state
connect(self)

connect to the database

collection(self, name)

returns the named collection :param name: the collection name :return: teh collection

close_client(self)

close the connection to the database

collections(self, name=None, regex=None)

the names of all collections

Parameters
  • name – if set, only look at these collections instead of all collections

  • regex – a regular expression on the names of the collections

Returns

list of names of all collections

Example:

collections = cm.collections(regex=”.*-vm”)

name_count(self, name)

counts the occurrence of the name used in the collections

Parameters

name – the name

Returns

find_group(self, name)

This function returns the entry with the given name from all collections in mongodb. The name must be unique across all collections

Parameters

name – the unique name of the entry

Returns

find_name(self, name, kind=None)

This function returns the entry with the given name from all collections in mongodb. The name must be unique across all collections

Parameters

name – the unique name of the entry

Returns

find_all_by_name(self, name, kind=None)

This function returns the entry with the given name from all collections in mongodb. The name must be unique across all collections

Parameters

name – the unique name of the entry

Returns

find_names(self, names)

Assuming names specified as parameters, it returns the entries with these names from all collections in mongodb. The names must be unique across all collections.

Parameters

names – the unique names in parameter format

Returns

names(self, collection=None, cloud=None, kind=None, regex=None)

finds all names in the specified collections. The parameters, collection, cloud, and kind can all be Parameters that get expanded to lists. All names from all collections are merged into the result.

With kwargs a search query on the names could be added.

Example:

cm = CmDatabase() for kind in [‘vm’, “image”, “flavor”]:

names = cm.names(cloud=”chameleon”, kind=kind)

print (names)

names = cm.names(cloud=”chameleon,azure”, kind=”vm”) names = cm.names(collection=”chameleon-image”, regex=”^CC-“) names = cm.names(collection=”chameleon-image”, regex=”.*Ubuntu.*”)

Parameters
  • collection – The collections

  • cloud – The clouds

  • kind – The kinds

  • regex – A query applied to name

Returns

find(self, collection=None, cloud=None, kind=None, query=None, attributes=None)

finds all names in the specified collections. The parameters, collection, cloud, and kind can all be Parameters that get expanded to lists. All names from all collections are merged into the result.

With kwargs a search query on the names could be added.

Example:

cm = CmDatabase()
for kind in ['vm', "image", "flavor"]:
    entries = cm.find(cloud="chameleon", kind=kind)
print (entries)


entries = cm.find(cloud="chameleon,azure", kind="vm")
query = {"name": {'$regex': ".*Ubuntu.*"}}
entries = cm.find(collection="chameleon-image", query=query)
Parameters
  • collection – The collections

  • cloud – The clouds

  • kind – The kinds

  • query – A query applied to name

Returns

find_ok(self, collection='cloudmesh', **kwargs)
static UPDATE(_entries, progress=True)
update(self, _entries, progress=True)
alter(self, entries)
exists(self, entries)

Check if entry exists in the database

Parameters

entries

Returns

insert(self, d, collection='cloudmesh')
update_old(self, entries, collection='cloudmesh', replace=False, **kwargs)
Parameters
  • entries – an array of dicts where one entry is called cmid. One must be careful as it does not erase previous attributes.

  • collection

  • replace

Returns

delete(self, collection='cloudmesh', **kwargs)
command(self, command)

issue command string via the mongoDB console :param command: interaction command string you want to send to mongodb console :return: command return

status(self)

test mongodb correspondent db connection :return:

clear(self, collection='cloudmesh')

drops the collection :return:

importAsFile(self, data, collection, db)
drop_database(self)

dropping cloudmesh database :return: