class TestType(BASE):
     props = defs.Dict(properties={
         "foo": defs.String(),
         "bar": defs.Boolean()
     })
     fixed = defs.Dict(
         properties={
             "name": defs.String(min_length=2),
             "age": defs.Integer(min_value=0, max_value=99)
         })
 class TestType(BASE):
     simple = defs.Array()
     unique = defs.Array(unique=True)
     simple_with_allowed_values = defs.Array(
         defs.String(allowed_values=["Foo", "Bar"]))
     defaulted = defs.Array(defs.Boolean(), default=[True, False])
     constrained = defs.Array(item_type=defs.Numeric(min_value=0),
                              min_size=3,
                              max_size=5,
                              unique=True)
Esempio n. 3
0
class ImageAsAnArtifact(definitions.ArtifactType):
    __type_name__ = 'Image'
    __endpoint__ = 'images'

    file = definitions.BinaryObject(required=True)
    disk_format = definitions.String(allowed_values=['ami', 'ari', 'aki',
                                                     'vhd', 'vmdk', 'raw',
                                                     'qcow2', 'vdi', 'iso'],
                                     required=True,
                                     mutable=False)
    container_format = definitions.String(allowed_values=['ami', 'ari',
                                                          'aki', 'bare',
                                                          'ovf', 'ova',
                                                          'docker'],
                                          required=True,
                                          mutable=False)
    min_disk = definitions.Integer(min_value=0, default=0)
    min_ram = definitions.Integer(min_value=0, default=0)

    virtual_size = definitions.Integer(min_value=0)
Esempio n. 4
0
class BaseArtifact(definitions.ArtifactType):
    __type_version__ = "1.0"
    prop1 = definitions.String()
    prop2 = definitions.Integer()
    int_list = definitions.Array(item_type=definitions.Integer(max_value=10,
                                                               min_value=1))
    depends_on = definitions.ArtifactReference(type_name='MyArtifact')
    references = definitions.ArtifactReferenceList()

    image_file = definitions.BinaryObject()
    screenshots = definitions.BinaryObjectList()
Esempio n. 5
0
class ImageAsAnArtifact(v1_1.ImageAsAnArtifact):
    __type_version__ = '2.0'

    file = definitions.BinaryObject(required=False)
    legacy_image_id = definitions.String(required=False,
                                         mutable=False,
                                         pattern=R'[0-9a-f]{8}-[0-9a-f]{4}'
                                         R'-4[0-9a-f]{3}-[89ab]'
                                         R'[0-9a-f]{3}-[0-9a-f]{12}')

    def __pre_publish__(self, context, *args, **kwargs):
        super(ImageAsAnArtifact, self).__pre_publish__(*args, **kwargs)
        if self.file is None and self.legacy_image_id is None:
            raise exception.InvalidArtifactPropertyValue(
                message=_("Either a file or a legacy_image_id has to be "
                          "specified"))
        if self.file is not None and self.legacy_image_id is not None:
            raise exception.InvalidArtifactPropertyValue(
                message=_("Both file and legacy_image_id may not be "
                          "specified at the same time"))

        if self.legacy_image_id:
            glance_endpoint = next(service['endpoints'][0]['publicURL']
                                   for service in context.service_catalog
                                   if service['name'] == 'xmonitor')
            # Ensure glanceclient is imported correctly since we are catching
            # the ImportError on initialization
            if glanceclient == None:
                raise ImportError(_("Glance client not installed"))

            try:
                client = glanceclient.Client(version=2,
                                             endpoint=glance_endpoint,
                                             token=context.auth_token)
                legacy_image = client.images.get(self.legacy_image_id)
            except Exception:
                raise exception.InvalidArtifactPropertyValue(
                    message=_('Unable to get legacy image'))
            if legacy_image is not None:
                self.file = definitions.Blob(size=legacy_image.size,
                                             locations=[{
                                                 "status":
                                                 "active",
                                                 "value":
                                                 legacy_image.direct_url
                                             }],
                                             checksum=legacy_image.checksum,
                                             item_key=legacy_image.id)
            else:
                raise exception.InvalidArtifactPropertyValue(
                    message=_("Legacy image was not found"))
class SerTestType(defs.ArtifactType):
    some_string = defs.String()
    some_text = defs.Text()
    some_version = defs.SemVerString()
    some_int = defs.Integer()
    some_numeric = defs.Numeric()
    some_bool = defs.Boolean()
    some_array = defs.Array()
    another_array = defs.Array(
        item_type=[defs.Integer(
        ), defs.Numeric(), defs.Boolean()])
    some_dict = defs.Dict()
    another_dict = defs.Dict(properties={
        'foo': defs.Integer(),
        'bar': defs.Boolean()
    })
    some_ref = defs.ArtifactReference()
    some_ref_list = defs.ArtifactReferenceList()
    some_blob = defs.BinaryObject()
    some_blob_list = defs.BinaryObjectList()
 class TestType(defs.ArtifactType):
     foo = defs.String(default='Bar', mutable=False)
 class TestType(BASE):
     prop = defs.String(readonly=True)
     arr = defs.Array(readonly=True)
        class TestType(BASE):
            activated = defs.Boolean(required=True, default=False)
            name = defs.String(mutable=False)

            def __is_mutable__(self):
                return not self.activated
 class TestType(BASE):
     address = defs.Array(item_type=[
         defs.String(20),
         defs.Integer(min_value=1),
         defs.Boolean()
     ])
 class WrongType(BASE):
     prop = defs.String(min_length=4, allowed_values=['foo', 'bar'])
 class WrongType(BASE):
     prop = defs.String(min_length=4, default='foo')
 class TestType(BASE):
     simple = defs.String()
     with_length = defs.String(max_length=10, min_length=5)
     with_pattern = defs.String(pattern='^\\d+$', default='42')