Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 41 additions & 185 deletions build/openapi-generator/model.mustache
Original file line number Diff line number Diff line change
@@ -1,202 +1,58 @@
# coding: utf-8
{{> partial_header }}

{{>partial_header}}

import pprint
import re # noqa: F401

import sys # noqa: F401
import six

from {{packageName}}.configuration import Configuration


from {{packageName}}.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
ModelNormal,
ModelSimple,
cached_property,
change_keys_js_to_python,
convert_js_args_to_python_args,
date,
datetime,
file_type,
none_type,
validate_get_composed_info,
)
{{#models}}
{{#model}}
class {{classname}}(object):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

Do not edit the class manually.
"""{{#allowableValues}}

"""
allowed enum values
"""
{{#enumVars}}
{{name}} = {{{value}}}{{^-last}}
{{/-last}}
{{/enumVars}}{{/allowableValues}}

{{#allowableValues}}
allowable_values = [{{#enumVars}}{{name}}{{^-last}}, {{/-last}}{{/enumVars}}] # noqa: E501

{{/allowableValues}}
"""
Attributes:
openapi_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
openapi_types = {
{{#vars}}
'{{name}}': '{{{dataType}}}'{{#hasMore}},{{/hasMore}}
{{/vars}}
}

attribute_map = {
{{#vars}}
'{{name}}': '{{baseName}}'{{#hasMore}},{{/hasMore}}
{{/vars}}
}
{{#discriminator}}
{{#imports}}
{{#-first}}

discriminator_value_class_map = {
{{#children}}
'{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}': '{{{classname}}}'{{^-last}},{{/-last}}
{{/children}}
}
{{/discriminator}}

def __init__(self{{#vars}}, {{name}}={{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{/vars}}, local_vars_configuration=None): # noqa: E501
"""{{classname}} - a model defined in OpenAPI""" # noqa: E501
if local_vars_configuration is None:
local_vars_configuration = Configuration()
self.local_vars_configuration = local_vars_configuration
{{#vars}}{{#-first}}
{{/-first}}
self._{{name}} = None
{{/vars}}
self.discriminator = {{#discriminator}}'{{{discriminatorName}}}'{{/discriminator}}{{^discriminator}}None{{/discriminator}}
{{#vars}}{{#-first}}
def lazy_import():
{{/-first}}
{{#required}}
self.{{name}} = {{name}}
{{/required}}
{{^required}}
{{#isNullable}}
self.{{name}} = {{name}}
{{/isNullable}}
{{^isNullable}}
if {{name}} is not None:
self.{{name}} = {{name}}
{{/isNullable}}
{{/required}}
{{/vars}}

{{#vars}}
@property
def {{name}}(self):
"""Gets the {{name}} of this {{classname}}. # noqa: E501

{{#description}}
{{{description}}} # noqa: E501
{{/description}}

:return: The {{name}} of this {{classname}}. # noqa: E501
:rtype: {{dataType}}
"""
return self._{{name}}
{{{.}}}
{{/imports}}

@{{name}}.setter
def {{name}}(self, {{name}}):
"""Sets the {{name}} of this {{classname}}.

{{#description}}
{{{description}}} # noqa: E501
{{/description}}

:param {{name}}: The {{name}} of this {{classname}}. # noqa: E501
:type {{name}}: {{dataType}}
"""
{{^isNullable}}
{{#required}}
if self.local_vars_configuration.client_side_validation and {{name}} is None: # noqa: E501
raise ValueError("Invalid value for `{{name}}`, must not be `None`") # noqa: E501
{{/required}}
{{/isNullable}}
{{^interfaces}}
{{#isArray}}
{{> model_templates/model_simple }}
{{/isArray}}
{{#isEnum}}
{{#isContainer}}
allowed_values = [{{#isNullable}}None,{{/isNullable}}{{#allowableValues}}{{#values}}{{#items.isString}}"{{/items.isString}}{{{this}}}{{#items.isString}}"{{/items.isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501
{{#isListContainer}}
if (self.local_vars_configuration.client_side_validation and
not set({{{name}}}).issubset(set(allowed_values))): # noqa: E501
raise ValueError(
"Invalid values for `{{{name}}}` [{0}], must be a subset of [{1}]" # noqa: E501
.format(", ".join(map(str, set({{{name}}}) - set(allowed_values))), # noqa: E501
", ".join(map(str, allowed_values)))
)
{{/isListContainer}}
{{#isMapContainer}}
if (self.local_vars_configuration.client_side_validation and
not set({{{name}}}.keys()).issubset(set(allowed_values))): # noqa: E501
raise ValueError(
"Invalid keys in `{{{name}}}` [{0}], must be a subset of [{1}]" # noqa: E501
.format(", ".join(map(str, set({{{name}}}.keys()) - set(allowed_values))), # noqa: E501
", ".join(map(str, allowed_values)))
)
{{/isMapContainer}}
{{/isContainer}}
{{^isContainer}}
allowed_values = [{{#isNullable}}None,{{/isNullable}}{{#allowableValues}}{{#values}}{{#isString}}"{{/isString}}{{{this}}}{{#isString}}"{{/isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501
if self.local_vars_configuration.client_side_validation and {{{name}}} not in allowed_values: # noqa: E501
raise ValueError(
"Invalid value for `{{{name}}}` ({0}), must be one of {1}" # noqa: E501
.format({{{name}}}, allowed_values)
)
{{/isContainer}}
{{> model_templates/model_simple }}
{{/isEnum}}
{{#isAlias}}
{{> model_templates/model_simple }}
{{/isAlias}}
{{^isArray}}
{{^isEnum}}
{{#hasValidation}}
{{#maxLength}}
if (self.local_vars_configuration.client_side_validation and
{{name}} is not None and len({{name}}) > {{maxLength}}):
raise ValueError("Invalid value for `{{name}}`, length must be less than or equal to `{{maxLength}}`") # noqa: E501
{{/maxLength}}
{{#minLength}}
if (self.local_vars_configuration.client_side_validation and
{{name}} is not None and len({{name}}) < {{minLength}}):
raise ValueError("Invalid value for `{{name}}`, length must be greater than or equal to `{{minLength}}`") # noqa: E501
{{/minLength}}
{{#maximum}}
if (self.local_vars_configuration.client_side_validation and
{{name}} is not None and {{name}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}): # noqa: E501
raise ValueError("Invalid value for `{{name}}`, must be a value less than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}`{{maximum}}`") # noqa: E501
{{/maximum}}
{{#minimum}}
if (self.local_vars_configuration.client_side_validation and
{{name}} is not None and {{name}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}): # noqa: E501
raise ValueError("Invalid value for `{{name}}`, must be a value greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}`{{minimum}}`") # noqa: E501
{{/minimum}}
{{#pattern}}
if (self.local_vars_configuration.client_side_validation and
{{name}} is not None and not re.search(r'{{{vendorExtensions.x-regex}}}', {{name}}{{#vendorExtensions.x-modifiers}}{{#-first}}, flags={{/-first}}re.{{.}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}})): # noqa: E501
raise ValueError(r"Invalid value for `{{name}}`, must be a follow pattern or equal to `{{{pattern}}}`") # noqa: E501
{{/pattern}}
{{#maxItems}}
if (self.local_vars_configuration.client_side_validation and
{{name}} is not None and len({{name}}) > {{maxItems}}):
raise ValueError("Invalid value for `{{name}}`, number of items must be less than or equal to `{{maxItems}}`") # noqa: E501
{{/maxItems}}
{{#minItems}}
if (self.local_vars_configuration.client_side_validation and
{{name}} is not None and len({{name}}) < {{minItems}}):
raise ValueError("Invalid value for `{{name}}`, number of items must be greater than or equal to `{{minItems}}`") # noqa: E501
{{/minItems}}
{{/hasValidation}}
{{^isAlias}}
{{> model_templates/model_normal }}
{{/isAlias}}
{{/isEnum}}
{{/isArray}}
{{/interfaces}}
{{#interfaces}}
{{#-last}}
{{> model_templates/model_composed }}
{{/-last}}
{{/interfaces}}

self._{{name}} = {{name}}

{{/vars}}
{{#discriminator}}
def get_real_child_model(self, data):
"""Returns the real base class specified by the discriminator"""
discriminator_key = self.attribute_map[self.discriminator]
discriminator_value = data[discriminator_key]
return self.discriminator_value_class_map.get(discriminator_value)

{{/discriminator}}
def to_dict(self):
"""Returns the model properties as a dict"""
result = {}
Expand Down Expand Up @@ -241,4 +97,4 @@ class {{classname}}(object):

return self.to_dict() != other.to_dict()
{{/model}}
{{/models}}
{{/models}}
59 changes: 46 additions & 13 deletions stackl/cli/commands/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import click
import stackl_client
import yaml
from urllib3.exceptions import NewConnectionError, MaxRetryError
from stackl_client.exceptions import ApiException, ApiValueError
from commands.autocomplete import show_progress_bar
from context import StacklContext
from mergedeep import merge
Expand All @@ -24,14 +26,25 @@
@click.argument('instance-name', required=False)
def apply(directory, config_file, params, tags, secrets, service_params,
service_secrets, replicas, services, instance_name, show_progress):
stackl_context = StacklContext()
if instance_name is None:
upload_files(directory, stackl_context)
else:
apply_stack_instance(config_file, params, tags, secrets,
service_params, service_secrets, replicas,
services, stackl_context, instance_name,
show_progress)
try:
stackl_context = StacklContext()
if instance_name is None:
upload_files(directory, stackl_context)
else:
apply_stack_instance(config_file, params, tags, secrets,
service_params, service_secrets, replicas,
services, stackl_context, instance_name,
show_progress)
except ApiException as e:
click.echo(e.body)
exit(1)
except ApiValueError as e:
click.echo(e.body)
exit(1)
except (NewConnectionError, MaxRetryError) as e:
click.echo("Unable to connect to Stackl host")
click.echo(e)
exit(1)


def apply_stack_instance(config_file, params, tags, secrets, service_params,
Expand Down Expand Up @@ -62,7 +75,7 @@ def apply_stack_instance(config_file, params, tags, secrets, service_params,
services = config_doc['services']
if "stages" in config_doc:
stages = config_doc['stages']
invocation = stackl_client.StackInstanceInvocation(
invocation = stackl_client.models.StackInstanceInvocation(
stack_instance_name=instance_name,
stack_infrastructure_template=config_doc[
"stack_infrastructure_template"],
Expand All @@ -78,9 +91,22 @@ def apply_stack_instance(config_file, params, tags, secrets, service_params,
try:
stackl_context.stack_instances_api.get_stack_instance(instance_name)
res = stackl_context.stack_instances_api.put_stack_instance(invocation)
except stackl_client.exceptions.ApiException:
res = stackl_context.stack_instances_api.post_stack_instance(
invocation)
except stackl_client.exceptions.NotFoundException as e:
try:
res = stackl_context.stack_instances_api.post_stack_instance(invocation)
except ApiException as e:
click.echo(e)
exit(1)
except ApiException as e:
click.echo(e.body)
exit(1)
except ApiValueError as e:
click.echo(e.body)
exit(1)
except (NewConnectionError, MaxRetryError) as e:
click.echo("Unable to connect to Stackl host")
click.echo(e)
exit(1)

click.echo(res)

Expand Down Expand Up @@ -114,11 +140,18 @@ def upload_file(stackl_doc, stackl_context, path):
click.echo(
f"Succesfully applied {stackl_doc['name']} with type {stackl_doc['type']}"
)
except stackl_client.exceptions.ApiException as e:
except ApiException as e:
click.echo(
f"Failed to apply {stackl_doc['name']} with type {stackl_doc['type']}: {e.body}"
)
exit(1)
except ApiValueError as e:
click.echo(e.body)
exit(1)
except (NewConnectionError, MaxRetryError) as e:
click.echo("Unable to connect to Stackl host")
click.echo(e)
exit(1)


def upload_files(directory, stackl_context):
Expand Down
21 changes: 11 additions & 10 deletions stackl/cli/commands/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
@click.command()
@click.argument('host', required=True)
def connect(host):
homedir = str(Path.home())
if len(homedir) == 0:
homedir = os.getcwd()
if not os.path.exists(homedir + os.sep + '.stackl'):
os.makedirs(homedir + os.sep + '.stackl')
with open(get_config_path(), 'w+') as stackl_config:
stackl_config.write(host)



try:
homedir = str(Path.home())
if len(homedir) == 0:
homedir = os.getcwd()
if not os.path.exists(homedir + os.sep + '.stackl'):
os.makedirs(homedir + os.sep + '.stackl')
with open(get_config_path(), 'w+') as stackl_config:
stackl_config.write(host)
except PermissionError as e:
click.echo(e)
exit(1)
Loading