From b7aec89493febdc3321ee67b86e95f7451437794 Mon Sep 17 00:00:00 2001 From: Alexander Tivelkov Date: Mon, 28 Apr 2014 17:33:37 +0400 Subject: [PATCH] Added MuranoPL infrastructure for advanced networking scenarios Base class 'Network' (io.murano.resources.Network) was added to core package. This class is an abstract class for network interaction, to be inherited by engine-specific implementations. 'Environment' class got a 'defaultNetworks' input parameter, containing two different instances of Network class for two initially supported networking use-cases: 'environment' for a topology when each environment has an isolated network 'flat' for a single network per multiple environments 'Instance' class got a 'networks' input parameter with a default value. This is a composite parameter indicating which networks the instance should join If 'useEnvironmentNetwork' is set to 'true' the instance should join an isolated network of current environment if 'useFlatNetwork' is set to 'true' the instance should join a single shared network Both values may be enabled, so the instance will join both networks. 'customNetworks' field of the same data structure may be used to specify custom network resources to join Same commit includes a temporary workaround for bug #1313694 The workaround is needed to properly use default of 'networks' field The actual implementation of io.murano.resources.Network class should be done in a separate package, which should be added to app-incubator repo Change-Id: If2ae332a61900b0dd94cec94c1c140c54079441f Partial-Bug: #1308921 --- meta/io.murano/Classes/Environment.yaml | 7 +++++ .../io.murano/Classes/resources/Instance.yaml | 28 +++++++++++++++++-- meta/io.murano/Classes/resources/Network.yaml | 10 +++++++ meta/io.murano/manifest.yaml | 3 +- muranoapi/dsl/type_scheme.py | 7 +++++ 5 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 meta/io.murano/Classes/resources/Network.yaml diff --git a/meta/io.murano/Classes/Environment.yaml b/meta/io.murano/Classes/Environment.yaml index 20ed52ca9..fd6527a0a 100644 --- a/meta/io.murano/Classes/Environment.yaml +++ b/meta/io.murano/Classes/Environment.yaml @@ -1,5 +1,6 @@ Namespaces: =: io.murano + res: io.murano.resources sys: io.murano.system Name: Environment @@ -23,6 +24,12 @@ Properties: Contract: $.class(sys:InstanceNotifier) Usage: Runtime + defaultNetworks: + Contract: + environment: $.class(res:Network) + flat: $.class(res:Network) + Usage: In + Workflow: initialize: Body: diff --git a/meta/io.murano/Classes/resources/Instance.yaml b/meta/io.murano/Classes/resources/Instance.yaml index 037718d1b..761b99d44 100644 --- a/meta/io.murano/Classes/resources/Instance.yaml +++ b/meta/io.murano/Classes/resources/Instance.yaml @@ -20,6 +20,15 @@ Properties: ipAddresses: Contract: [$.string()] Usage: Out + networks: + Contract: + useEnvironmentNetwork: $.bool().notNull() + useFlatNetwork: $.bool().notNull() + customNetworks: [$.class(Network).notNull()] + Default: + useEnvironmentNetwork: true + useFlatNetwork: false + customNetworks: [] Workflow: initialize: @@ -30,6 +39,14 @@ Workflow: deploy: Body: + - If: $.networks.useEnvironmentNetwork + Then: + $.joinNet($.environment.defaultNetworks.environment) + - If: $.networks.useFlatNetwork + Then: + $.joinNet($.environment.defaultNetworks.flat) + - $.networks.customNetworks.select($this.joinNet($)) + - $userData: $.prepareUserData() - $template: Resources: @@ -43,15 +60,22 @@ Workflow: format('{0}-PublicIp', $.name): Value: - Fn::GetAtt: [$.name, PublicIp] - - $.environment.stack.updateTemplate($template) - $.environment.stack.push() - - $outputs: $.environment.stack.output() - $.ipAddresses: $outputs.get(format('{0}-PublicIp', $this.name)) - $.environment.instanceNotifier.trackApplication($this) + joinNet: + Arguments: + - net: + Contract: $.class(Network) + Body: + - If: $net != null + Then: + $net.addHostToNetwork($) + destroy: Body: - $template: $.environment.stack.current() diff --git a/meta/io.murano/Classes/resources/Network.yaml b/meta/io.murano/Classes/resources/Network.yaml new file mode 100644 index 000000000..674719f84 --- /dev/null +++ b/meta/io.murano/Classes/resources/Network.yaml @@ -0,0 +1,10 @@ +Namespaces: + =: io.murano.resources + +Name: Network + +Workflow: + addHostToNetwork: + Arguments: + - instance: + Contract: $.class(Instance).notNull() diff --git a/meta/io.murano/manifest.yaml b/meta/io.murano/manifest.yaml index 11b771e7d..1895218b6 100644 --- a/meta/io.murano/manifest.yaml +++ b/meta/io.murano/manifest.yaml @@ -18,4 +18,5 @@ Classes: io.murano.Environment: Environment.yaml io.murano.Application: Application.yaml - io.murano.resources.Instance: resources/Instance.yaml \ No newline at end of file + io.murano.resources.Network: resources/Network.yaml + io.murano.resources.Instance: resources/Instance.yaml diff --git a/muranoapi/dsl/type_scheme.py b/muranoapi/dsl/type_scheme.py index 95d618206..eaac9cbeb 100644 --- a/muranoapi/dsl/type_scheme.py +++ b/muranoapi/dsl/type_scheme.py @@ -262,6 +262,13 @@ class TypeScheme(object): def __call__(self, data, context, this, object_store, namespace_resolver, default): + # TODO(ativelkov, slagun): temporary fix, need a better way of handling + # composite defaults + # A bug (#1313694) has been filed + + if data is NoValue: + data = default + context = self.prepare_context( context, this, object_store, namespace_resolver, default)