def _printList(self, parameter, fieldList, clouds): mesh = cloudmesh.mesh() x = PrettyTable() x.field_names = fieldList for field in fieldList: x.align[field] = "c" # center aligned try: for cloud in clouds: mesh.refresh(names=[cloud], types=[parameter]) if cloud in mesh.clouds and mesh.clouds[cloud]: params = mesh.clouds[cloud][parameter] if len(params) > 0: print "\nCloud: ", cloud, "\n" for key, value in params.iteritems(): # since value is a dictionary of multiple items, # we add to table only fields from the fieldList rowList = [] for field in fieldList: rowList.append(value[field]) x.add_row(rowList) print x.get_string(sortby=fieldList[0]) print "\n\n" return except: print "Unexpected error: ", sys.exc_info()[0], sys.exc_info()[1]
def createVM(N): username = cloudmesh.load().username() print username mesh = cloudmesh.mesh("mongo") mesh.activate(username) cloudmesh.shell("cloud on india") flavor = mesh.flavor('india', 'm1.large') image=mesh.image('india','futuregrid/ubuntu-14.04') #vm_ip=[] for i in range(0,N): result = mesh.start(cloud='india', cm_user_id=username, flavor=flavor, image=image) server = result['server']['id'] ip=mesh.assign_public_ip('india', server, username) print ip #vm_ip.append(ip) try: result = mesh.wait(ipaddr=ip, command="ls -al", interval=10, retry=5) cloudmesh.banner("INSTALLING MONGO TO THE VM "+str(ip)) result=mesh.ssh_execute(username='******',ipaddr=ip,command='ls -al',pkey=None) print result script ="scp filescript.sh ubuntu@"+ip+":/home/ubuntu/" print script os.system(script) result=mesh.ssh_execute(username='******',ipaddr=ip,command='bash -s < ./filescript.sh',pkey=None) print result result=mesh.ssh_execute(username='******',ipaddr=ip,command='ls -al',pkey=None) print result except: print "Authentication failed when connecting to %s" % ip sys.exit(1) print "All VMs Mongo Installed.. "
def _install_mongo(self): self.mesh = cloudmesh.mesh("mongo") username = cloudmesh.load().username() self.mesh.activate(username) print "Waiting for a minute to let VMs build and start" time.sleep(60) # Install mongoDB on all the servers print("=====Installing MongoDB on all the VMs =====") script = """ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list sudo apt-get update sudo apt-get install -y mongodb-org""" commands = script.split("\n")[1:] for ip in self.ip_list: result = self.mesh.wait(ipaddr=ip, interval=10, retry=10) print (result) for command in commands: print ('>execute', command) self.mesh.ssh_execute(ipaddr=ip, command=command)
# (11) docker service cloud delete : Deletes CLOUD from the docker service # # docker container attach NAME : This exists but currently there are some issues for login to the container # DOCKER CLOUD SERVER created for test: Ubuntu Amazon EC2 instances - (a) 54.148.243.157 (b) 54.149.122.57 # # HOW TO RUN: # (1) PULL OUT THE REPO IN CLOUDMESH # (2) COPY THE PLUGINS/CM_SHELL_DOCKER.PY TO CLOUMESH_CMD3/PLUGINS/ # (3) RUN THIS FILE (PYTHON DOCKER_TEST_PROCEDURE.PY) # ########################################################################## import cloudmesh from pprint import pprint mesh = cloudmesh.mesh("mongo") # Start docker service with CLOUD print("Starting Docker service.....................") print cloudmesh.shell("docker service start 54.148.243.157") # List clouds print("Listing clouds.........................") print cloudmesh.shell("docker service cloud list") # List images print("Listing available images......................") print cloudmesh.shell("docker images list") # Create container print(
import cloudmesh from pprint import pprint cloudmesh.logger(False) username = cloudmesh.load().username() cloudmesh.banner("INIT MONGO") mesh = cloudmesh.mesh("mongo") # # authentication as a user - username is requried # On webgui side, this is achieved by the framework, # and the username is obtined from g.user.id # # On CLI side, a global user object or username variable # should be maintained upon the start of the shell # The username could be obtained from yaml file. cloudmesh.banner("ACTIVATE") mesh.activate(username) cloudmesh.banner("GET FLAVOR") mesh.refresh(username, types=['flavors'], names=["india"]) data = mesh.flavors(cm_user_id=username, clouds=["india"]) pprint(data) cloudmesh.banner("GET IMAGE") mesh.refresh(username, types=['images'], names=["india"]) data = mesh.images(cm_user_id=username, clouds=["india"])
def deploy(cls, name, count = 3, ln = "ubuntu", cloud = "india", flavor = "m1.small", image = "futuresystems/ubuntu-14.04"): mesh = cloudmesh.mesh("mongo") username = cloudmesh.load().usernam() print username
def test_01_init(cls): HEADING() cls.mesh = cloudmesh.mesh("mongo")
def do_list(self, args, arguments): """ Usage: list flavors [CLOUD] list servers [CLOUD] list images [CLOUD] list Arguments: CLOUD the name of the cloud Options: -v verbose mode Description: missing This should be similar to the count command, e.g. multiple clouds could be specified. """ mesh = cloudmesh.mesh() mongo = cm_mongo() config = cm_config() user = config.username() dbDict = self.mongoClass.db_defaults.find_one({'cm_user_id': user}) # log.info(args) # pprint(arguments) # chk if no args provided, to output the list of clouds. print '\n\n' noArg = None for value in arguments.values(): if value: noArg = False break # log.info(arguments) all = False if not arguments["CLOUD"]: all = True if 'activeclouds' in dbDict and dbDict['activeclouds']: clouds = dbDict['activeclouds'] else: clouds = [config.default_cloud] else: clouds = [arguments["CLOUD"]] # no args provided, print the clouds. if not noArg: print 70*"-" print 'List of Clouds:' for cloud in clouds: print cloud print '\n' return if arguments["flavors"]: fieldList = ['id', 'name'] self._printList('flavors', fieldList, clouds) if arguments["servers"]: fieldList = ["id", "name", "status"] self._printList('server', fieldList, clouds) if arguments["images"]: fieldList = ["id", "name"] self._printList('image', fieldList, clouds)