コード例 #1
0
class NginxEndpointConfig(Config):

    sticky_sessions = Config.boolean(
        label="Use Sticky Sessions",
        default=False,
        description="Enables nginx sticky sessions.")

    keepalive = Config.integer(label="Keepalive Connections", default=0,
        validate=lambda self: self.keepalive >= 0 or \
            Config.error("Keepalive must be non-negative."),
        description="Number of backend connections to keep alive.")

    ssl = Config.boolean(label="Use SSL",
                         default=False,
                         description="Configures nginx to handle SSL.")

    ssl_certificate = Config.text(
        label="SSL Certificate",
        default=None,
        description="An SSL certification in PEM format.")

    ssl_key = Config.text(label="SSL Key",
                          default=None,
                          description="An SSL key (not password protected).")

    redirect = Config.string(
        label="Redirect",
        default=None,
        description="A 301 redirect to use when no backends are available.")
コード例 #2
0
class BaseOsEndpointConfig(Config):

    # Cached client.
    _client = None

    def __init__(self, *args, **kwargs):
        super(BaseOsEndpointConfig, self).__init__(*args, **kwargs)

        # Last refresh for the cache.
        self._last_refresh = None

        # Initialize our list cache.
        self._list_cache = []

        # Initialize our floating IP cache.
        self._float_cache = {}

    # Common authentication elements.
    auth_url = Config.string(
        label="OpenStack Auth URL",
        default="http://localhost:5000/v2.0/",
        order=0,
        validate=lambda self: self.validate_connection_params(),
        alternates=["authurl"],
        description="The OpenStack authentication URL (OS_AUTH_URL).")

    username = Config.string(
        label="OpenStack User",
        default="admin",
        order=1,
        alternates=["user"],
        description="The user for authentication (OS_USERNAME).")

    password = Config.password(
        label="OpenStack Password",
        default="admin",
        order=2,
        alternates=["apikey"],
        description="The api key or password (OS_PASSWORD).")

    tenant_name = Config.string(
        "OpenStack Tenant/Project",
        default="admin",
        order=3,
        alternates=["project"],
        description="The project or tenant (OS_TENANT_NAME).")

    region_name = Config.string(label="Region Name",
                                order=4,
                                description="The region (OS_REGION_NAME).")

    list_rate_limit = Config.integer(label="Rate limit",
        default=120, order=1,
        validate=lambda self: self.list_rate_limit >= 0 or \
            Config.error("Rate limit must be non-negative."),
        description="Limit list requests to this often.")

    # Elements common to launching and booting.
    security_groups = Config.list(
        label="Security Groups",
        order=5,
        description="Security groups for new instances.")

    availability_zone = Config.string(
        label="Availability Zone",
        order=5,
        description="Availability zone for new instances.")

    user_data = Config.text(
        "User Data",
        order=6,
        description="Script or cloud-config for new instances.")

    filter_instances = Config.boolean(
        "Filter Instances",
        default=False,
        order=7,
        description="Use only instances that match image, flavor, etc.")

    floating_ips = Config.list(
        label="Floating IPs",
        order=7,
        validate=lambda self: self.validate_floating_ips(),
        description="Floating IPs to distribute.")

    def novaclient(self):
        from novaclient import shell
        from novaclient.v1_1.client import Client as NovaClient
        if self._client is None:
            extensions = shell.OpenStackComputeShell()._discover_extensions(
                "1.1")
            self._client = NovaClient(self.username,
                                      self.password,
                                      self.tenant_name,
                                      self.auth_url,
                                      region_name=self.region_name,
                                      service_type="compute",
                                      extensions=extensions)
        return self._client

    def validate_connection_params(self, throwerror=True):
        import novaclient.exceptions
        try:
            self.novaclient().authenticate()
        except Exception, e:
            if throwerror:
                # If we got an unathorized exception, propagate.
                if isinstance(e, novaclient.exceptions.Unauthorized):
                    Config.error(e.message)
                elif isinstance(e, novaclient.exceptions.EndpointNotFound):
                    Config.error(
                        "Problem connecting to cloud endpoint. Bad Region?")
                else:
                    Config.error(
                        "Could not connect to OpenStack cloud. Bad URL?")
            else:
                return False
        return True