Beispiel #1
0
    def test_min_number_size(self):
        # test min number size
        validator = validators.MinNumberSize(10)

        # allowed size - no exception
        validator(10)
        validator(10.0)

        # too small number - value error
        self.assertRaises(ValueError, validator, 9)
        self.assertRaises(ValueError, validator, 9.9)
        self.assertRaises(ValueError, validator, 0)
        self.assertRaises(ValueError, validator, 0)

        # only integers and floats can be applied as values
        self.assertEqual((fields.IntegerField, fields.FloatField),
                         validators.MinNumberSize.get_allowed_types())

        self.assertEqual({'minimum': 10}, validator.to_jsonschema())
Beispiel #2
0
class SampleArtifact(base_artifact.BaseArtifact):
    VERSION = '1.0'

    fields = {
        'blob':
        Blob(required_on_activate=False,
             mutable=True,
             filter_ops=[],
             description="I am Blob"),
        'small_blob':
        Blob(max_blob_size=10,
             required_on_activate=False,
             mutable=True,
             filter_ops=[]),
        'link1':
        Field(glare_fields.Link, required_on_activate=False, filter_ops=[]),
        'link2':
        Field(glare_fields.Link, required_on_activate=False, filter_ops=[]),
        'bool1':
        Field(fields.FlexibleBooleanField,
              required_on_activate=False,
              filter_ops=(attribute.FILTER_EQ, ),
              default=False),
        'bool2':
        Field(fields.FlexibleBooleanField,
              required_on_activate=False,
              filter_ops=(attribute.FILTER_EQ, ),
              default=False),
        'int1':
        Field(fields.IntegerField,
              required_on_activate=False,
              sortable=True,
              filter_ops=attribute.FILTERS),
        'int2':
        Field(fields.IntegerField,
              sortable=True,
              required_on_activate=False,
              filter_ops=attribute.FILTERS),
        'float1':
        Field(fields.FloatField,
              sortable=True,
              required_on_activate=False,
              filter_ops=attribute.FILTERS),
        'float2':
        Field(fields.FloatField,
              sortable=True,
              required_on_activate=False,
              filter_ops=attribute.FILTERS),
        'str1':
        Field(fields.StringField,
              sortable=True,
              required_on_activate=False,
              filter_ops=attribute.FILTERS),
        'list_of_str':
        List(fields.String,
             required_on_activate=False,
             filter_ops=(attribute.FILTER_EQ, )),
        'list_of_int':
        List(fields.Integer,
             required_on_activate=False,
             filter_ops=(attribute.FILTER_EQ, )),
        'dict_of_str':
        Dict(fields.String,
             required_on_activate=False,
             filter_ops=(attribute.FILTER_EQ, )),
        'dict_of_int':
        Dict(fields.Integer,
             required_on_activate=False,
             filter_ops=(attribute.FILTER_EQ, )),
        'dict_of_blobs':
        BlobDict(required_on_activate=False),
        'string_mutable':
        Field(fields.StringField,
              required_on_activate=False,
              mutable=True,
              filter_ops=attribute.FILTERS),
        'string_required':
        Field(fields.StringField,
              required_on_activate=True,
              filter_ops=attribute.FILTERS),
        'string_validators':
        Field(fields.StringField,
              required_on_activate=False,
              filter_ops=attribute.FILTERS,
              validators=[
                  validators.AllowedValues(['aa', 'bb', 'c' * 11]),
                  validators.MaxStrLen(10)
              ]),
        'int_validators':
        Field(fields.IntegerField,
              required_on_activate=False,
              filter_ops=attribute.FILTERS,
              validators=[
                  validators.MinNumberSize(10),
                  validators.MaxNumberSize(20)
              ]),
        'list_validators':
        List(fields.String,
             required_on_activate=False,
             filter_ops=[],
             max_size=3,
             validators=[validators.Unique()]),
        'dict_validators':
        Dict(fields.String,
             required_on_activate=False,
             default=None,
             filter_ops=[],
             validators=[
                 validators.AllowedDictKeys(['abc', 'def', 'ghi', 'jkl'])
             ],
             max_size=3),
        'system_attribute':
        Field(fields.StringField,
              system=True,
              sortable=True,
              default="default")
    }

    @classmethod
    def get_type_name(cls):
        return "sample_artifact"
Beispiel #3
0
class Secret(base_artifact.BaseArtifact):
    """The purpose this glare artifact, Secret, is to enable the user to store
    'secret' data such as: Private key, Certificate, Password, SSH keys Etc.
    """
    VERSION = '1.0'

    @classmethod
    def get_type_name(cls):
        return "secrets"

    @classmethod
    def get_display_type_name(cls):
        return "Secrets"

    fields = {
        'payload':
        Blob(  # The encrypted secret data
            description="The secret's data to be stored"),
        'payload_content_encoding':
        Field(fields.StringField,
              required_on_activate=False,
              default="base64",
              filter_ops=[],
              validators=[validators.AllowedValues(["base64"])],
              description="Required if payload is encoded. "
              "The encoding used for the payload to be"
              " able to include it in the JSON request "
              "(only base64 supported)"),
        'secret_type':
        Field(
            fields.StringField,
            required_on_activate=False,
            default="opaque",
            sortable=True,
            filter_ops=(wrappers.FILTER_EQ, ),
            validators=[
                validators.AllowedValues([
                    "symmetric", "public", "private", "passphrase",
                    "certificate", "opaque"
                ])
            ],
            description="Used to indicate the type of secret being stored",
        ),
        'algorithm':
        Field(fields.StringField,
              required_on_activate=False,
              filter_ops=(wrappers.FILTER_EQ, ),
              description="Metadata provided by a user or system for"
              " informational purposes"),
        'bit_length':
        Field(fields.IntegerField,
              required_on_activate=False,
              sortable=True,
              validators=[validators.MinNumberSize(1)],
              description="Metadata provided by a user or system"
              " for informational purposes."
              " Value must be greater than zero."),
        'mode':
        Field(fields.StringField,
              required_on_activate=False,
              filter_ops=(wrappers.FILTER_EQ, ),
              description="Metadata provided by a user or"
              " system for informational purposes."),
    }
Beispiel #4
0
class Image(base.BaseArtifact):

    fields = {
        'container_format':
        Field(fields.StringField,
              validators=[
                  validators.AllowedValues(
                      ['ami', 'ari', 'aki', 'bare', 'ovf', 'ova', 'docker'])
              ],
              description="Image container format."),
        'disk_format':
        Field(fields.StringField,
              validators=[
                  validators.AllowedValues([
                      'ami', 'ari', 'aki', 'vhd', 'vhdx', 'vmdk', 'raw',
                      'qcow2', 'vdi', 'iso'
                  ])
              ],
              description="Image disk format."),
        'min_ram':
        Field(fields.IntegerField,
              required_on_activate=False,
              validators=[validators.MinNumberSize(0)],
              description="Minimal RAM required to boot image."),
        'min_disk':
        Field(fields.IntegerField,
              required_on_activate=False,
              validators=[validators.MinNumberSize(0)],
              description="Minimal disk space "
              "required to boot image."),
        'image':
        Blob(max_blob_size=1073741824000,
             required_on_activate=False,
             description="Image binary."),
        'image_indirect_url':
        Field(fields.StringField,
              required_on_activate=False,
              description="URL where image is available "
              "for users by accepting EULA "
              "or some other form. It is "
              "used when it is not possible "
              "to upload image directly to "
              "Glare. F.e. some Windows "
              "cloud images requires EULA "
              "acceptance before download."),
        'cloud_user':
        Field(fields.StringField,
              required_on_activate=False,
              description="Default cloud user."),
        'kernel_id':
        Field(fields.StringField,
              required_on_activate=False,
              validators=[validators.UUID()],
              description="ID of image stored in Glare that "
              "should be used as the kernel when "
              "booting an AMI-style image."),
        'ramdisk_id':
        Field(fields.StringField,
              required_on_activate=False,
              validators=[validators.UUID()],
              description="ID of image stored in Glare that "
              "should be used as the ramdisk when "
              "booting an AMI-style image."),
        'instance_uuid':
        Field(fields.StringField,
              required_on_activate=False,
              description="Metadata which can be used to "
              "record which instance this image "
              "is associated with. "
              "(Informational only, does not "
              "create an instance snapshot.)"),
        'architecture':
        Field(fields.StringField,
              required_on_activate=False,
              description="Operating system architecture as "
              "specified in http://docs.openstack."
              "org/trunk/openstack-compute/admin/"
              "content/adding-images.html"),
        'os_distro':
        Field(fields.StringField,
              required_on_activate=False,
              description="Common name of operating system "
              "distribution as specified in "
              "http://docs.openstack.org/trunk/"
              "openstack-compute/admin/content/"
              "adding-images.html"),
        'os_version':
        Field(fields.StringField,
              required_on_activate=False,
              description="Operating system version as "
              "specified by the distributor"),
    }

    @classmethod
    def get_type_name(cls):
        return "images"

    @classmethod
    def validate_activate(cls, context, af, values=None):
        blob_status = None
        if af.image:
            blob_status = af.image['status']
        if (blob_status != glare_fields.BlobFieldType.ACTIVE
                and not af.image_indirect_url):
            raise ValueError("Either image or image_indirect_url must be "
                             "specified for Binary Image.")
Beispiel #5
0
class Image(base.BaseArtifact):

    fields = {
        'container_format':
        Field(fields.StringField,
              validators=[
                  validators.AllowedValues(
                      ['ami', 'ari', 'aki', 'bare', 'ovf', 'ova', 'docker'])
              ],
              description="Image container format."),
        'disk_format':
        Field(fields.StringField,
              validators=[
                  validators.AllowedValues([
                      'ami', 'ari', 'aki', 'vhd', 'vhdx', 'vmdk', 'raw',
                      'qcow2', 'vdi', 'iso'
                  ])
              ],
              description="Image disk format."),
        'min_ram':
        Field(fields.IntegerField,
              required_on_activate=False,
              validators=[validators.MinNumberSize(0)],
              description="Minimal RAM required to boot image."),
        'min_disk':
        Field(fields.IntegerField,
              required_on_activate=False,
              validators=[validators.MinNumberSize(0)],
              description="Minimal disk space "
              "required to boot image."),
        'image':
        Blob(max_blob_size=1073741824000,
             required_on_activate=False,
             description="Image binary."),
        'kernel_id':
        Field(fields.StringField,
              required_on_activate=False,
              validators=[validators.UUID()],
              description="ID of image stored in Glare that "
              "should be used as the kernel when "
              "booting an AMI-style image."),
        'ramdisk_id':
        Field(fields.StringField,
              required_on_activate=False,
              validators=[validators.UUID()],
              description="ID of image stored in Glare that "
              "should be used as the ramdisk when "
              "booting an AMI-style image."),
        'instance_uuid':
        Field(fields.StringField,
              required_on_activate=False,
              description="Metadata which can be used to "
              "record which instance this image "
              "is associated with. "
              "(Informational only, does not "
              "create an instance snapshot.)"),
        'architecture':
        Field(fields.StringField,
              required_on_activate=False,
              description="Operating system architecture as "
              "specified in http://docs.openstack."
              "org/trunk/openstack-compute/admin/"
              "content/adding-images.html"),
        'os_distro':
        Field(fields.StringField,
              required_on_activate=False,
              description="Common name of operating system "
              "distribution as specified in "
              "http://docs.openstack.org/trunk/"
              "openstack-compute/admin/content/"
              "adding-images.html"),
        'os_version':
        Field(fields.StringField,
              required_on_activate=False,
              description="Operating system version as "
              "specified by the distributor"),
    }

    @classmethod
    def get_type_name(cls):
        return "images"

    @classmethod
    def get_display_type_name(cls):
        return "Images"