Beispiel #1
0
    def volume_refresh(self, print_objs):
        """
        List all the successfuly created
        volumes 
        :returns: volumes object
        :rtype: NoneType
        """
        driver = self._get_driver()
        volumes = driver.list_volumes()
        db_client = Evemongo_client()
        db_client.delete(VOLUME)
        e = {}
        n = 1
        for vol in volumes:
            #print(vol)
            data = {}
            data['id'] = vol.id
            data['name'] = vol.name
            data['size'] = vol.size
            data['driver'] = vol.driver.name
            e[n] = data
            n = n + 1
            db_client.post(VOLUME, data)

        if print_objs == True :
            Console.ok(str(Printer.dict_table(e, order=['id','name', 'size','driver'])))

        return volumes
Beispiel #2
0
 def location_refresh(self, print_location):
     """
     List all
     available locations
     :returns: location objects
     :rtype: NoneType
     """
     driver = self._get_driver()
     locations = driver.list_locations()
     db_client = Evemongo_client()
     db_client.delete(LOCATION)
     n = 1
     e = {}
     #<EC2NodeLocation: id=0, name=us-west-1a, country=USA, availability_zone=<ExEC2AvailabilityZone: name=us-west-1a, 
     # zone_state=available, region_name=us-west-1> driver=Amazon EC2>,
     for location in locations:
         data = {}
         data['id'] = location.id
         data['name'] = location.name
         data['country'] = location.country
         data['availability_zone'] = location.availability_zone.name
         data['zone_state'] = location.availability_zone.zone_state
         data['region_name'] = location.availability_zone.region_name
         #data['provider'] = location.driver.name    
         e[n] = data
         n = n + 1
         db_client.post(LOCATION, data)
     
     if print_location == True:
         Console.ok(str(Printer.dict_table(e, order=['id','name','country', 'availability_zone', 'zone_state','region_name','provider'])))
     
     return locations
Beispiel #3
0
    def keypair_refresh(self):
        """
        List all the available key pair
        associated with account
        
        :returns: None
        :rtype: NoneType
        """
        driver = self._get_driver()
        db_client = Evemongo_client()
        db_client.delete(KEYPAIR)

        key_pair_objs = driver.list_key_pairs()
        n =1
        e = {}
        for kp in key_pair_objs:
            data = {}
            data['name'] = kp.name
            data['fingerprint'] = kp.fingerprint
            e[n] = data
            n = n + 1
            db_client.post(KEYPAIR, data)        
            
        Console.ok(str(Printer.dict_table(e, order=['name', 'fingerprint'])))
       
        return
Beispiel #4
0
    def keypair_create(self, key_pair):
        """
        Creates the key pair 
        required for node object
        :returns: None
        :rtype: NoneType
        """
        driver = self._get_driver()
        
        key_pair_obj = driver.create_key_pair(key_pair)
        #print("keypair is created !",name)
        n = 0 ;
        e = {}
        # parse flavors
        data = {}
        data['name'] = str(key_pair_obj.name)
        data['fingerprint'] = str(key_pair_obj.fingerprint)
        e[n] = data
        n = n + 1
          
        Console.ok(str(Printer.dict_table(e, order=['name', 'fingerprint', 'driver'])))

        #Store the created keypair in db 
        db_client = Evemongo_client()
        db_client.post(KEYPAIR, data)
        
        return
Beispiel #5
0
    def node_create_by_imageId(self, vm_name, config):#image_id, keypair_name, security_group_names, flavor_id):
        """
        Created the node with
        specified image id, 
        keypair name should be AWS1
        rest of the parameter; security group
        and flavor id are take bydefault
        :returns: None
        :rtype: NoneType
        """
        # get driver
        driver = self._get_driver()
        db_client = Evemongo_client()
        if "image_id" not in config :
            image_id =  self.configd["default"]['image']#'ami-0183d861'
        else:
            image_id = config["image_id"]
        
        #print(image_id) 
        # Name of the existing keypair you want to use
        if "keypair_name" not in config:
            keypair_name = KEYPAIR_NAME_DEFAULT
        else:
            keypair_name = config["keypair_name"]

        # A list of security groups you want this node to be added to
        if "security_group_names" not in config:
            security_group_names = ['default']
        else:
            security_group_names = config["security_group_names"]

        if "flavor_id" not in config:
            flavor_id = self.configd["default"]['flavor']
        else:
            flavor_id = config["flavor_id"]

        sizes = driver.list_sizes()
        
        size = [s for s in sizes if s.id == flavor_id][0]
        image = driver.get_image(image_id)
        # create node
        node = driver.create_node(name=vm_name, size = size, image = image, ex_keyname = keypair_name, ex_securitygroup = security_group_names)
        #print("The Node is Created --------------- :: ",node)
        n = 0 ;
        e = {}
        data = {}
        data['uuid'] = str(node.uuid)
        data['name'] = str(node.name)
        data['state'] = str(node.state)
        data['public_ips'] = str(node.public_ips)
        data['private_ips'] = str(node.private_ips)
        data['provider'] = str(node.driver.name)
        e[n] = data
        n = n + 1
        Console.ok(str(Printer.dict_table(e, order=['uuid', 'name', 'state', 'public_ips', 'private_ips','provider'])))

        if bool(node) :
            #Push the created node in db
            db_client.post(NODE, data)
        return
Beispiel #6
0
    def node_refresh(self, show_list):
        """
        List the all instance
        of node
        :returns: nodes object
        :rtype: NoneType
        """
        # get driver
        driver = self._get_driver()
        #List the running vm's
        nodes = driver.list_nodes()

        db_client = Evemongo_client()
        db_client.delete(NODE)

        n = 0 ;
        e = {}
        for node in nodes:
            # parse flavors
            data = {}
            data['uuid'] = str(node.uuid)
            data['name'] = str(node.name)
            data['state'] = str(node.state)
            data['provider'] = str(node.driver.name)
            e[n] = data
            n = n + 1
            
            db_client.post(NODE, data)

        if show_list:
            Console.ok(str(Printer.dict_table(e, order=['uuid', 'name', 'state', 'provider'])))

        return nodes
Beispiel #7
0
    def volume_create(self, volume_size, volume_name):
        """
        Creates the volume with default 
        size of 1GB with specified volume name
        location for volume will be fetch from
        ../cloudmesh.yaml file
        :returns: None
        :rtype: NoneType
        """
        #Some test functionality
        db_client = Evemongo_client()
        #Some test functionality
        flavor_id = self.configd["default"]['flavor']
        location = self.configd["default"]['location']
        driver = self._get_driver()
        sizes = driver.list_sizes()
        size = [s for s in sizes if s.id == flavor_id][0]
        locations = self.location_refresh(False)
        if len(locations) == 0:
            print("Location not found!!")
        else:
            e = {}
            for loc in locations:
                if loc.availability_zone.region_name == location:
                    locObj = loc
                    #print(locObj)
                    storageVolume = driver.create_volume(volume_size, volume_name, location=locObj, snapshot=None)
                    #<StorageVolume id=vol-0e80356132e246a7b size=1 driver=Amazon EC2>
                    data = {}
                    data['id'] = storageVolume.id
                    data['name'] = volume_name
                    data['size'] = storageVolume.size
                    data['driver'] = storageVolume.driver.name
                    e[0] = data
                    # store it in mongodb
                    db_client.post(VOLUME, data)
                    Console.ok(str(Printer.dict_table(e, order=['id','name', 'size','driver'])))
                else:
                    print("Location list does not match with selected location:  ", location)

                break
       
        #print("======Created volume ========= :: ",storageVolume)

        return
Beispiel #8
0
    def image_refresh(self):
        """List of amazon images
        get store it in db
        :returns: None
        :rtype: NoneType

        """
        # get driver
        driver = self._get_driver()
        # get image list and print
        images = driver.list_images()
        db_client = Evemongo_client()
       
        if len(images) == 0:
            print("Error in fetching new list ...Showing existing images")
            self.image_list()
        else:
            #r = db_client.delete(IMAGE)
            #print(images)
            #print("storing in db")
            #db_client.perform_delete(IMAGE)
            n = 0 ;
            e = {}
            for image in images:
                # parse flavors
                data = {}
                data['id'] = str(image .id)
                data['name'] = str(image.name)
                data['driver'] = str(image.driver)
                # store it in mongodb
                db_client.post(IMAGE, data)
                e[n] = data
                n = n + 1
                
          
            Console.ok(str(Printer.dict_table(e, order=['id', 'name', 'driver'])))
            #print(images)

        return
Beispiel #9
0
    def flavor_refresh(self):
        """
        List all the flavor list
        available on Amazon EC2
        :returns: None
        :rtype: NoneType
        """
        #get driver
        driver = self._get_driver()

        # get flavor list and print
        sizes = driver.list_sizes()
        #print(sizes)
        n = 1   
        e = {}
        db_client = Evemongo_client()
        db_client.delete(FLAVOR)
        for size in sizes:
            # parse flavors
            data = {}
            data['id'] = size .id
            data['name'] = size.name
            data['ram'] = size.ram
            data['disk'] = size.disk
            data['price'] = size.price

            e[n] = data
            n = n + 1
            # store it in mongodb
            db_client.post(FLAVOR, data)
            #print(data)    
        
        Console.ok(str(Printer.dict_table(e, order=['id', 'name', 'ram', 'disk', 'bandwidth', 'price'])))

        #print("successfully stored in db", r)
        return