# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. Namespaces: =: com.example std: io.murano res: io.murano.resources conf: io.murano.configuration netsfc: org.openstack.networkingSfc sys: io.murano.system Name: SfcDemoApp Extends: std:Application Properties: network: Contract: $.class(res:Network).notNull() flavor: Contract: $.string().notNull() image: Contract: $.string().notNull() keyname: Contract: $.string() Default: null sfcInstance: Usage: InOut Contract: instance: $.class(netsfc:Instance) port: $.class(netsfc:NeutronPort) leftInstance: Usage: InOut Contract: instance: $.class(netsfc:Instance) port: $.class(netsfc:NeutronPort) rightInstance: Usage: InOut Contract: instance: $.class(netsfc:Instance) port: $.class(netsfc:NeutronPort) portPairGroup: Contract: $.class(netsfc:PortPairGroup) Usage: InOut flowClassifier: Contract: $.class(netsfc:FlowClassifier) Usage: InOut portChain: Contract: $.class(netsfc:PortChain) Usage: InOut Methods: .init: Body: - $._env: $.find(std:Environment).require() deploy: Body: - If: not $.getAttr(deployed, false) Then: - $._log: $._env.reporter - $._log.report($this, 'Deploying SFC network...') - $.network.deploy() - $._log.report($this, 'Deploying left instance...') - $.leftInstance: $.deployEndpoint('left-endpoint') - $._log.report($this, 'Deploying right instance...') - $.rightInstance: $.deployEndpoint('right-endpoint') - $._log.report($this, 'Deploying SFC instance...') - $.deploySfcInstance() - $._log.report($this, 'Creating port chain...') - $.createSfcChain() - $.deploySoftware('left-endpoint', $.leftInstance.instance) - $.deploySoftware('right-endpoint', $.rightInstance.instance) - $.deploySoftware('sfc-app', $.sfcInstance.instance) - $host: $.sfcInstance.instance.ipAddresses[0] - $.setAttr(deployed, true) - $._log.report($this, format('Ntop is available at http://{0} admin/r00tme', $host)) deploySoftware: Arguments: - deployType: Contract: $.string().notNull() - instance: Contract: $.class(netsfc:Instance).notNull() Body: - $resources: new(sys:Resources) - $template: $resources.yaml('SFCDemo.template').bind(dict( deployType => $deployType, sourceIp => $.leftInstance.instance.ipAddresses[0], destinationIp => $.rightInstance.instance.ipAddresses[0])) - $instance.agent.call($template, $resources) - $._log.report($this, $name) deploySfcInstance: Body: - $.sfcInstance.port: new(netsfc:NeutronPort, $this, network => $.network) - $._log.report($this, '$.sfcInstance.port.deploy()') - $.sfcInstance.port.deploy() - $networks: useEnvironmentNetwork: false useFlatNetwork: false - $.sfcInstance.instance: new( netsfc:Instance, $this, name => "sfc-instance", flavor => $.flavor, image => $.image, keyname => $.keyname, ports => [$.sfcInstance.port], networks => $networks) - $._log.report($this, '$.sfcInstance.instance.deploy()') - $.sfcInstance.instance.deploy() - conf:Linux.runCommand( $.sfcInstance.instance.agent, "sudo sysctl -w net.ipv4.ip_forward=1") - $portPair: new( netsfc:PortPair, $this, ingress => $.sfcInstance.port, egress => $.sfcInstance.port) - $._log.report($this, '$portPair.deploy()') - $portPair.deploy() - $.portPairGroup: new( netsfc:PortPairGroup, $this, portPairs => [$portPair]) - $._log.report($this, '$.portPairGroup.deploy()') - $.portPairGroup.deploy() deployEndpoint: Arguments: name: Contract: $.string().notNull() Body: - $instance: {} - $instance.port: new(netsfc:NeutronPort, $this, network => $.network) - $._log.report($this, '$instance.port.deploy()') - $instance.port.deploy() - $networks: useEnvironmentNetwork: false useFlatNetwork: false - $instance.instance: new( netsfc:Instance, $this, name => $name, flavor => $.flavor, image => $.image, keyname => $.keyname, ports => [$instance.port], networks => $networks) - $._log.report($this, '$instance.instance.deploy()') - $instance.instance.deploy() - Return: $instance createSfcChain: Body: - $._log.report($this, format('{0}, {1}', $.leftInstance.port, $.rightInstance.port)) - $.flowClassifier: new( netsfc:FlowClassifier, $this, protocol => 'TCP', destinationPortMin => 8000, destinationPortMax => 8080, logicalSourcePort => $.leftInstance.port, logicalDestinationPort => $.rightInstance.port) - $._log.report($this, '$.flowClassifier.deploy()') - $.flowClassifier.deploy() - $.portChain: new( netsfc:PortChain, $this, portPairGroups => [$.portPairGroup], flowClassifiers => [$.flowClassifier]) - $._log.report($this, '$.portChain.deploy()') - $.portChain.deploy()