Example #1
0
 def __init__(
     self, data: dict, svc: ExternalServices = ExternalServices()) -> None:
     super().__init__(data=data, svc=svc)
     self.config_schema.update({
         "type": "object",
         "required": ["project_id", "bindings"],
         "additionalProperties": False,
         "properties": {
             "project_id": {
                 "type": "string",
                 "pattern": "^[a-z]([-a-z0-9]*[a-z0-9])$"
             },
             "bindings": {
                 "type": "array",
                 "items": {
                     "type": "object",
                     "additionalProperties": False,
                     "properties": {
                         "role": {
                             "type": "string"
                         },
                         "members": {
                             "type": "array",
                             "minLength": 1,
                             "items": {
                                 "type": "string"
                             }
                         }
                     }
                 }
             }
         }
     })
 def __init__(self, data: dict, svc: ExternalServices = ExternalServices()) -> None:
     super().__init__(data=data, svc=svc)
     self.config_schema.update({
         "required": ["project_id", "name"],
         "additionalProperties": False,
         "properties": {
             "project_id": {"type": "string"},
             "region": {"type": "string"},
             "name": {"type": "string"}
         }
     })
Example #3
0
 def __init__(self, data: dict, svc: ExternalServices = ExternalServices()) -> None:
     super().__init__(data=data, svc=svc)
     self.config_schema.update({
         "type": "object",
         "required": ["project_id", "email"],
         "additionalProperties": False,
         "properties": {
             "project_id": {"type": "string", "pattern": "^[a-z]([-a-z0-9]*[a-z0-9])$"},
             "email": {"type": "string"},
             "display_name": {"type": "string", "minLength": 1}
         }
     })
Example #4
0
 def __init__(self, data: dict, svc: ExternalServices = ExternalServices()) -> None:
     super().__init__(data=data, svc=svc)
     self.add_plug(name='kube', container_path='/root/.kube', optional=False, writable=False)
     self.config_schema.update({
         "required": ["manifest"],
         "additionalProperties": True,
         "properties": {
             "timeout_ms": {
                 "description": "How long to wait for the resource to become available after creation/updates? "
                                "(seconds)",
                 "type": "integer",
                 "minValue": 1000
             },
             "timeout_interval_ms": {
                 "description": "Sleep intervals progressing towards the timeout, in milli-seconds.",
                 "type": "integer",
                 "minValue": 100
             },
             "manifest": {
                 "type": "object",
                 "required": ["metadata"],
                 "additionalProperties": True,
                 "properties": {
                     "apiVersion": {"type": "string", "minLength": 1},
                     "kind": {"type": "string", "minLength": 1},
                     "metadata": {
                         "type": "object",
                         "required": ["name"],
                         "additionalProperties": True,
                         "properties": {
                             "name": {"type": "string", "minLength": 1},
                             "namespace": {"type": "string", "minLength": 1},
                             "annotations": {
                                 "type": "object",
                                 "additionalProperties": True
                             },
                             "labels": {
                                 "type": "object",
                                 "additionalProperties": True
                             }
                         }
                     }
                 }
             }
         }
     })
Example #5
0
 def __init__(self, data: dict, svc: ExternalServices = ExternalServices()) -> None:
     super().__init__(data=data, svc=svc)
     self.add_plug(name='kube', container_path='/root/.kube', optional=False, writable=True)
     self.config_schema.update({
         "type": "object",
         "required": ["project_id", "zone", "name", "description", "version", "node_pools"],
         "additionalProperties": False,
         "properties": {
             "project_id": {"type": "string"},
             "zone": {"type": "string"},
             "name": {"type": "string"},
             "description": {"type": "string"},
             "version": {"type": "string"},
             "node_pools": {
                 "type": "array",
                 "minItems": 1,
                 "items": {
                     "type": "object",
                     "required": ["name"],
                     "properties": {
                         "name": {"type": "string"},
                         "min_size": {"type": "integer", "minValue": 1},
                         "max_size": {"type": "integer", "minValue": 1},
                         "service_account": {"type": "string"},
                         "oauth_scopes": {
                             "type": "array",
                             "items": {"type": "string", "uniqueItems": True}
                         },
                         "preemptible": {"type": "boolean"},
                         "machine_type": {"type": "string"},
                         "disk_size_gb": {"type": "integer"},
                         "tags": {
                             "type": "array",
                             "items": {"type": "string", "uniqueItems": True}
                         },
                         "metadata": {"type": "object"},
                         "labels": {"type": "object"}
                     }
                 }
             }
         }
     })
Example #6
0
 def __init__(
     self, data: dict, svc: ExternalServices = ExternalServices()) -> None:
     super().__init__(data=data, svc=svc)
     self.config_schema.update({
         "type": "object",
         "required": ["project_id"],
         "additionalProperties": False,
         "properties": {
             "project_id": {
                 "type": "string",
                 "pattern": "^[a-z]([-a-z0-9]*[a-z0-9])$"
             },
             "organization_id": {
                 "type": "integer"
             },
             "billing_account_id": {
                 "type": "string"
             },
             "apis": {
                 "type": "object",
                 "additionalProperties": False,
                 "properties": {
                     "enabled": {
                         "type": "array",
                         "items": {
                             "type": "string",
                             "uniqueItems": True
                         }
                     },
                     "disabled": {
                         "type": "array",
                         "items": {
                             "type": "string",
                             "uniqueItems": True
                         }
                     }
                 }
             }
         }
     })
Example #7
0
    def __init__(self,
                 svc: ExternalServices,
                 project_id: str,
                 instance_name: str,
                 root_password: str,
                 zone: str,
                 scripts_data: Sequence[dict],
                 context: Mapping[str, Any]) -> None:
        super().__init__()
        self._sql_executor: SqlExecutor = \
            svc.create_gcp_sql_executor(project_id=project_id,
                                        instance=instance_name,
                                        password=root_password,
                                        region=region_from_zone(zone=zone))

        condition_factory: ConditionFactory = ConditionFactory()
        self._scripts: Sequence[Script] = \
            [Script(name=data['name'],
                    paths=data['paths'],
                    conditions=condition_factory.create_conditions(data['when']),
                    context=context)
             for data in scripts_data]
Example #8
0
 def __init__(self, data: dict, svc: ExternalServices = ExternalServices()) -> None:
     super().__init__(data=data, svc=svc)
Example #9
0
    def __init__(self, data: dict, svc: ExternalServices = ExternalServices()) -> None:
        super().__init__(data=data, svc=svc)

        # build definitions for condition types
        condition_definitions = {}
        for alias, factory in CONDITION_TYPES.items():
            condition_definitions[alias] = factory.config_schema()
        condition_definitions['CONDITION'] = {
            "oneOf": [{"$ref": f"#/definitions/{alias}"} for alias in condition_definitions.keys()]
        }

        # build full list of all definitions
        definitions = {}
        definitions.update(condition_definitions)

        # create the configuration schema
        self.config_schema.update({
            "type": "object",
            "required": ["zone", "name", "machine-type", "root-password"],
            "additionalProperties": False,
            "definitions": definitions,
            "properties": {
                "project_id": {"type": "string"},
                "zone": {"type": "string"},
                "name": {"type": "string"},
                "machine-type": {"type": "string"},
                "backup": {
                    "type": "object",
                    "additionalProperties": False,
                    "required": ["enabled"],
                    "properties": {
                        "enabled": {"type": "boolean"},
                        "time": {
                            "type": "string",
                            "pattern": "^[0-9]{2}:[0-9]{2}$"
                        }
                    }
                },
                "data-disk-size-gb": {
                    "type": "integer",
                    "minimum": 10
                },
                "data-disk-type": {
                    "type": "string",
                    "enum": ["PD_SSD", "PD_HDD"]
                },
                "flags": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "additionalProperties": False,
                        "required": ["name"],
                        "properties": {
                            "name": {"type": "string"},
                            "value": {"type": "string"}
                        }
                    }
                },
                "require-ssl": {"type": "boolean"},
                "authorized-networks": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "additionalProperties": False,
                        "required": ["name", "value"],
                        "properties": {
                            "expirationTime": {"type": "string"},  # RFC 3339 format (eg.for 2012-11-15T16:19:00.094Z)
                            "name": {"type": "string"},
                            "value": {"type": "string"}
                        }
                    }
                },
                "maintenance": {
                    "oneOf": [
                        {"type": "null"},
                        {
                            "type": "object",
                            "additionalProperties": False,
                            "required": ["day", "hour"],
                            "properties": {
                                "day": {
                                    "oneOf": [
                                        {
                                            "type": "string",
                                            "enum": ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
                                                     "Saturday"]
                                        },
                                        {
                                            "type": "integer",
                                            "minimum": 1,
                                            "maximum": 7,
                                            "exclusiveMaximum": False
                                        }
                                    ]
                                },
                                "hour": {
                                    "type": "integer",
                                    "minimum": 0,
                                    "maximum": 23,
                                    "exclusiveMaximum": False
                                }
                            }
                        }
                    ]
                },
                "storage-auto-resize": {
                    "type": "object",
                    "additionalProperties": False,
                    "required": ["enabled"],
                    "properties": {
                        "enabled": {"type": "boolean"},
                        "limit": {
                            "type": "integer",
                            "minimum": 0
                        }
                    }
                },
                "labels": {
                    "type": "object",
                    "additionalProperties": False,
                    "patternProperties": {
                        ".+": {"type": "string"}
                    }
                },
                "root-password": {
                    "type": "string",
                    "pattern": ".+"
                },
                "users": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                        "type": "object",
                        "additionalProperties": False,
                        "properties": {
                            "name": {"type": "string", "minLength": 1},
                            "password": {"type": "string", "minLength": 5}
                        }
                    }
                },
                "scripts_ctx": {"type": "object"},
                "scripts": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "additionalProperties": False,
                        "required": ["name", "paths", "when"],
                        "properties": {
                            "name": {"type": "string"},
                            "paths": {
                                "type": "array",
                                "minItems": 1,
                                "uniqueItems": True,
                                "items": {
                                    "oneOf": [
                                        {"type": "string"},
                                        {
                                            "type": "object",
                                            "required": ["path"],
                                            "additionalProperties": False,
                                            "properties": {
                                                "path": {"type": "string"},
                                                "post_process": {"type": "boolean"}
                                            }
                                        }
                                    ]
                                }
                            },
                            "when": {
                                "type": "array",
                                "items": {"$ref": "#/definitions/CONDITION"}
                            }
                        }
                    }
                }
            }
        })

        # translate maintenance window name to number
        if self.info.has_config:
            cfg: dict = self.info.config
            if "maintenance" in cfg and cfg["maintenance"] is not None:
                if 'day' in cfg["maintenance"] and type(cfg["maintenance"]['day']) == str:
                    cfg["maintenance"]['day'] = _translate_day_name_to_number(cfg["maintenance"]['day'])