示例#1
0

@attributes(["address"])
class IPv6Address(object):
    """
    An IPv6 address for a server.
    """

    def json(self):
        """
        A JSON-serializable representation of this address.
        """
        return {"addr": self.address, "version": 6}


server_creation = EventDescription()


@server_creation.declare_criterion("server_name")
def server_name_criterion(value):
    """
    Return a Criterion which matches the given regular expression string
    against the ``"server_name"`` attribute.
    """
    return Criterion(name='server_name', predicate=regexp_predicate(value))


@server_creation.declare_criterion("metadata")
def metadata_criterion(value):
    """
    Return a Criterion which matches against metadata.
示例#2
0
from mimic.model.identity_objects import (bad_request, conflict,
                                          EndpointTemplateStore,
                                          ExternalApiStore, not_found)
from mimic.rest.decorators import require_auth_token
from mimic.rest.mimicapp import MimicApp
from mimic.session import NonMatchingTenantError
from mimic.util.helper import (
    invalid_resource,
    seconds_to_timestamp,
    json_from_request,
)

from mimic.model.behaviors import (BehaviorRegistryCollection, Criterion,
                                   EventDescription, regexp_predicate)

authentication = EventDescription()
"""
Event refers to authenticating against Identity using a username/password,
username/api-key, token, or getting an impersonation token.
"""


@authentication.declare_criterion("username")
def username_criterion(value):
    """
    Return a Criterion which matches the given regular expression string
    against the ``"username"`` attribute.
    """
    return Criterion(name='username', predicate=regexp_predicate(value))

示例#3
0
        collection.stacks.append(stack)
        return stack

    def creation_response_json(self, absolutize_url):
        """
        Returns the response associated with the stack's creation.
        """
        return {
            "stack": {
                "id": self.stack_id,
                "links": self.links_json(absolutize_url)
            }
        }


stack_creation = EventDescription()
stack_check = EventDescription()
stack_update = EventDescription()
stack_deletion = EventDescription()


@stack_creation.declare_default_behavior
def default_create_behavior(collection, request, body, absolutize_url):
    """
    Successfully create a stack.
    """
    new_stack = Stack.from_creation_request_json(collection, body)
    response = new_stack.creation_response_json(absolutize_url)
    request.setResponseCode(201)
    return json.dumps(response)