Beispiel #1
0
 def _create_body(self,
                  name,
                  size=None,
                  volume_type=None,
                  description=None,
                  metadata=None,
                  snapshot_id=None,
                  availability_zone=None):
     """
     Used to create the dict required to create a new volume
     """
     if not isinstance(size,
                       (int, long)) or not (MIN_SIZE <= size <= MAX_SIZE):
         raise exc.InvalidSize("Volume sizes must be integers between "
                               "%s and %s." % (MIN_SIZE, MAX_SIZE))
     if volume_type is None:
         volume_type = "SATA"
     if description is None:
         description = ""
     if metadata is None:
         metadata = {}
     body = {
         "volume": {
             "size": size,
             "snapshot_id": snapshot_id,
             "display_name": name,
             "display_description": description,
             "volume_type": volume_type,
             "metadata": metadata,
             "availability_zone": availability_zone,
         }
     }
     return body
Beispiel #2
0
 def create(self, name="", size=None, volume_type=None, description=None,
          metadata=None, snapshot_id=None, availability_zone=None):
     """
     Makes sure that the size is passed and is within allowed values.
     """
     if not isinstance(size, (int, long)) or not (
             MIN_SIZE <= size <= MAX_SIZE):
         raise exc.InvalidSize("Volume sizes must be integers between "
                 "%s and %s." % (MIN_SIZE, MAX_SIZE))
     return super(CloudBlockStorageClient, self).create(name, size=size,
             volume_type=volume_type, description=description,
             metadata=metadata, snapshot_id=snapshot_id,
             availability_zone=availability_zone)
Beispiel #3
0
 def _create_body(self,
                  name,
                  size=None,
                  volume_type=None,
                  description=None,
                  metadata=None,
                  snapshot_id=None,
                  availability_zone=None,
                  volume=None,
                  force=False):
     """
     Used to create the dict required to create any of the following:
         A new volume
         A new snapshot
     """
     if size is not None:
         # Creating a volume
         if not isinstance(
                 size, (int, long)) or not (MIN_SIZE <= size <= MAX_SIZE):
             raise exc.InvalidSize("Volume sizes must be integers between "
                                   "%s and %s." % (MIN_SIZE, MAX_SIZE))
         if volume_type is None:
             volume_type = "SATA"
         if description is None:
             description = ""
         if metadata is None:
             metadata = {}
         body = {
             "volume": {
                 "size": size,
                 "snapshot_id": snapshot_id,
                 "display_name": name,
                 "display_description": description,
                 "volume_type": volume_type,
                 "metadata": metadata,
                 "availability_zone": availability_zone,
             }
         }
     else:
         # Creating a snapshot
         body = {
             "snapshot": {
                 "display_name": name,
                 "display_description": description,
                 "volume_id": volume.id,
                 "force": str(force).lower(),
             }
         }
     return body
Beispiel #4
0
    def _create_body(self,
                     name,
                     size=None,
                     volume_type=None,
                     description=None,
                     metadata=None,
                     snapshot_id=None,
                     clone_id=None,
                     availability_zone=None,
                     image=None):
        """
        Used to create the dict required to create a new volume
        """
        try:
            int(size)
        except:
            raise exc.InvalidSize("Volume sizes must be integers")

        if volume_type is None:
            volume_type = "SATA"
        if description is None:
            description = ""
        if metadata is None:
            metadata = {}
        if image is not None:
            image = utils.get_id(image)
        body = {
            "volume": {
                "size": size,
                "snapshot_id": snapshot_id,
                "source_volid": clone_id,
                "display_name": name,
                "display_description": description,
                "volume_type": volume_type,
                "metadata": metadata,
                "availability_zone": availability_zone,
                "imageRef": image,
            }
        }
        return body