From 96f2f84b3062c4b8ccc017a8ca335a0cdb3aae02 Mon Sep 17 00:00:00 2001 From: beierl Date: Wed, 30 Oct 2019 15:50:13 -0400 Subject: [PATCH 1/2] Add NextEPC Example Adds the NextEPC VNFD, NSD, charms and a build script, Based of content from VNF Onboarding walkthrough. Signed-off-by: beierl --- .gitignore | 9 +- examples/NextEPC/build.sh | 30 ++ .../charm-sources/layers/hsscharm/README.ex | 65 ++++ .../layers/hsscharm/actions.yaml | 13 + .../layers/hsscharm/actions/configure-hss | 18 ++ .../layers/hsscharm/actions/restart-hss | 18 ++ .../charm-sources/layers/hsscharm/config.yaml | 14 + .../charm-sources/layers/hsscharm/icon.svg | 279 ++++++++++++++++++ .../charm-sources/layers/hsscharm/layer.yaml | 3 + .../layers/hsscharm/metadata.yaml | 11 + .../layers/hsscharm/reactive/hsscharm.py | 50 ++++ .../layers/hsscharm/tests/00-setup | 5 + .../layers/hsscharm/tests/10-deploy | 35 +++ .../charm-sources/layers/spgwcharm/README.ex | 65 ++++ .../layers/spgwcharm/actions.yaml | 24 ++ .../layers/spgwcharm/actions/add-route | 18 ++ .../layers/spgwcharm/actions/configure-spgw | 18 ++ .../layers/spgwcharm/actions/restart-spgw | 18 ++ .../layers/spgwcharm/config.yaml | 14 + .../charm-sources/layers/spgwcharm/icon.svg | 279 ++++++++++++++++++ .../charm-sources/layers/spgwcharm/layer.yaml | 3 + .../layers/spgwcharm/metadata.yaml | 11 + .../layers/spgwcharm/reactive/spgwcharm.py | 52 ++++ .../layers/spgwcharm/tests/00-setup | 5 + .../layers/spgwcharm/tests/10-deploy | 35 +++ examples/NextEPC/params.yaml | 16 + examples/NextEPC/vEPC_nsd/README | 2 + examples/NextEPC/vEPC_nsd/vEPC_nsd.yaml | 45 +++ examples/NextEPC/vEPC_vnfd/README | 2 + .../NextEPC/vEPC_vnfd/cloud_init/hss-init | 5 + .../NextEPC/vEPC_vnfd/cloud_init/spgwmme-init | 5 + examples/NextEPC/vEPC_vnfd/vEPC_vnfd.yaml | 184 ++++++++++++ 32 files changed, 1350 insertions(+), 1 deletion(-) create mode 100755 examples/NextEPC/build.sh create mode 100644 examples/NextEPC/charm-sources/layers/hsscharm/README.ex create mode 100644 examples/NextEPC/charm-sources/layers/hsscharm/actions.yaml create mode 100755 examples/NextEPC/charm-sources/layers/hsscharm/actions/configure-hss create mode 100755 examples/NextEPC/charm-sources/layers/hsscharm/actions/restart-hss create mode 100644 examples/NextEPC/charm-sources/layers/hsscharm/config.yaml create mode 100644 examples/NextEPC/charm-sources/layers/hsscharm/icon.svg create mode 100644 examples/NextEPC/charm-sources/layers/hsscharm/layer.yaml create mode 100644 examples/NextEPC/charm-sources/layers/hsscharm/metadata.yaml create mode 100644 examples/NextEPC/charm-sources/layers/hsscharm/reactive/hsscharm.py create mode 100755 examples/NextEPC/charm-sources/layers/hsscharm/tests/00-setup create mode 100755 examples/NextEPC/charm-sources/layers/hsscharm/tests/10-deploy create mode 100644 examples/NextEPC/charm-sources/layers/spgwcharm/README.ex create mode 100644 examples/NextEPC/charm-sources/layers/spgwcharm/actions.yaml create mode 100755 examples/NextEPC/charm-sources/layers/spgwcharm/actions/add-route create mode 100755 examples/NextEPC/charm-sources/layers/spgwcharm/actions/configure-spgw create mode 100755 examples/NextEPC/charm-sources/layers/spgwcharm/actions/restart-spgw create mode 100644 examples/NextEPC/charm-sources/layers/spgwcharm/config.yaml create mode 100644 examples/NextEPC/charm-sources/layers/spgwcharm/icon.svg create mode 100644 examples/NextEPC/charm-sources/layers/spgwcharm/layer.yaml create mode 100644 examples/NextEPC/charm-sources/layers/spgwcharm/metadata.yaml create mode 100644 examples/NextEPC/charm-sources/layers/spgwcharm/reactive/spgwcharm.py create mode 100755 examples/NextEPC/charm-sources/layers/spgwcharm/tests/00-setup create mode 100755 examples/NextEPC/charm-sources/layers/spgwcharm/tests/10-deploy create mode 100644 examples/NextEPC/params.yaml create mode 100644 examples/NextEPC/vEPC_nsd/README create mode 100644 examples/NextEPC/vEPC_nsd/vEPC_nsd.yaml create mode 100644 examples/NextEPC/vEPC_vnfd/README create mode 100644 examples/NextEPC/vEPC_vnfd/cloud_init/hss-init create mode 100644 examples/NextEPC/vEPC_vnfd/cloud_init/spgwmme-init create mode 100644 examples/NextEPC/vEPC_vnfd/vEPC_vnfd.yaml diff --git a/.gitignore b/.gitignore index b06dc10..484eb1a 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,11 @@ assets/.nosync # Web Server # ########################## -pythonweb.py \ No newline at end of file +pythonweb.py + +# IDEs +.project + +# Generated output from examples +charms/ +.tar.gz diff --git a/examples/NextEPC/build.sh b/examples/NextEPC/build.sh new file mode 100755 index 0000000..217c5a0 --- /dev/null +++ b/examples/NextEPC/build.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +export JUJU_REPOSITORY=`pwd`/charm-sources +export CHARM_LAYERS_DIR=$JUJU_REPOSITORY/layers +export CHARM_BUILD_DIR=`pwd`/vEPC_vnfd/charms + +rm -rf $CHARM_BUILD_DIR + +for charm in hsscharm spgwcharm; do + cd $CHARM_LAYERS_DIR/$charm + charm build & + cd - +done + +wait + +for file in vEPC_nsd vEPC_vnfd +do + rm ${file}.tar.gz + tar -czf ${file}.tar.gz ${file}/ +done + +osm nsd-delete vEPC_nsd +osm vnfd-delete vEPC_vnfd + +osm vnfd-create vEPC_vnfd.tar.gz || exit 1 +osm nsd-create vEPC_nsd.tar.gz || exit 1 + +osm ns-create --ns_name EPC1 --nsd_name vEPC_nsd --ssh_keys ~/.ssh/id_rsa.pub --config_file params.yaml --vim_account vnfob +ssh://git@osm.etsi.org:29419/beierl/vnf-onboarding-guidelines.git diff --git a/examples/NextEPC/charm-sources/layers/hsscharm/README.ex b/examples/NextEPC/charm-sources/layers/hsscharm/README.ex new file mode 100644 index 0000000..b6816b2 --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/hsscharm/README.ex @@ -0,0 +1,65 @@ +# Overview + +Describe the intended usage of this charm and anything unique about how this +charm relates to others here. + +This README will be displayed in the Charm Store, it should be either Markdown +or RST. Ideal READMEs include instructions on how to use the charm, expected +usage, and charm features that your audience might be interested in. For an +example of a well written README check out Hadoop: +http://jujucharms.com/charms/precise/hadoop + +Use this as a Markdown reference if you need help with the formatting of this +README: http://askubuntu.com/editing-help + +This charm provides [service][]. Add a description here of what the service +itself actually does. + +Also remember to check the [icon guidelines][] so that your charm looks good +in the Juju GUI. + +# Usage + +Step by step instructions on using the charm: + +juju deploy servicename + +and so on. If you're providing a web service or something that the end user +needs to go to, tell them here, especially if you're deploying a service that +might listen to a non-default port. + +You can then browse to http://ip-address to configure the service. + +## Scale out Usage + +If the charm has any recommendations for running at scale, outline them in +examples here. For example if you have a memcached relation that improves +performance, mention it here. + +## Known Limitations and Issues + +This not only helps users but gives people a place to start if they want to help +you add features to your charm. + +# Configuration + +The configuration options will be listed on the charm store, however If you're +making assumptions or opinionated decisions in the charm (like setting a default +administrator password), you should detail that here so the user knows how to +change it immediately, etc. + +# Contact Information + +Though this will be listed in the charm store itself don't assume a user will +know that, so include that information here: + +## Upstream Project Name + + - Upstream website + - Upstream bug tracker + - Upstream mailing list or contact information + - Feel free to add things if it's useful for users + + +[service]: http://example.com +[icon guidelines]: https://jujucharms.com/docs/stable/authors-charm-icon diff --git a/examples/NextEPC/charm-sources/layers/hsscharm/actions.yaml b/examples/NextEPC/charm-sources/layers/hsscharm/actions.yaml new file mode 100644 index 0000000..52fce31 --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/hsscharm/actions.yaml @@ -0,0 +1,13 @@ +configure-hss: + description: "Configures the HSS" + params: + hss-ip: + description: "HSS IP" + type: string + default: "0.0.0.0" + spgw-ip: + description: "SPGW IP" + type: string + default: "0.0.0.0" +restart-hss: + description: "Restarts the service of the VNF" diff --git a/examples/NextEPC/charm-sources/layers/hsscharm/actions/configure-hss b/examples/NextEPC/charm-sources/layers/hsscharm/actions/configure-hss new file mode 100755 index 0000000..7d02e2d --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/hsscharm/actions/configure-hss @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +import sys +sys.path.append('lib') + +from charms.reactive import main +from charms.reactive import set_state +from charmhelpers.core.hookenv import action_fail, action_name + +""" +`set_state` only works here because it's flushed to disk inside the `main()` +loop. remove_state will need to be called inside the action method. +""" +set_state('actions.{}'.format(action_name())) + +try: + main() +except Exception as e: + action_fail(repr(e)) diff --git a/examples/NextEPC/charm-sources/layers/hsscharm/actions/restart-hss b/examples/NextEPC/charm-sources/layers/hsscharm/actions/restart-hss new file mode 100755 index 0000000..7d02e2d --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/hsscharm/actions/restart-hss @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +import sys +sys.path.append('lib') + +from charms.reactive import main +from charms.reactive import set_state +from charmhelpers.core.hookenv import action_fail, action_name + +""" +`set_state` only works here because it's flushed to disk inside the `main()` +loop. remove_state will need to be called inside the action method. +""" +set_state('actions.{}'.format(action_name())) + +try: + main() +except Exception as e: + action_fail(repr(e)) diff --git a/examples/NextEPC/charm-sources/layers/hsscharm/config.yaml b/examples/NextEPC/charm-sources/layers/hsscharm/config.yaml new file mode 100644 index 0000000..51f2ce4 --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/hsscharm/config.yaml @@ -0,0 +1,14 @@ +options: + string-option: + type: string + default: "Default Value" + description: "A short description of the configuration option" + boolean-option: + type: boolean + default: False + description: "A short description of the configuration option" + int-option: + type: int + default: 9001 + description: "A short description of the configuration option" + diff --git a/examples/NextEPC/charm-sources/layers/hsscharm/icon.svg b/examples/NextEPC/charm-sources/layers/hsscharm/icon.svg new file mode 100644 index 0000000..96a5d0c --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/hsscharm/icon.svg @@ -0,0 +1,279 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/examples/NextEPC/charm-sources/layers/hsscharm/layer.yaml b/examples/NextEPC/charm-sources/layers/hsscharm/layer.yaml new file mode 100644 index 0000000..aa4dc07 --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/hsscharm/layer.yaml @@ -0,0 +1,3 @@ +includes: + - layer:basic + - layer:vnfproxy diff --git a/examples/NextEPC/charm-sources/layers/hsscharm/metadata.yaml b/examples/NextEPC/charm-sources/layers/hsscharm/metadata.yaml new file mode 100644 index 0000000..73ba0cf --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/hsscharm/metadata.yaml @@ -0,0 +1,11 @@ +name: hsscharm +summary: NextEPC HSS Charm +maintainer: Your name +description: | + This is an example of a proxy charm deployed by Open Source Mano. +tags: + - nfv +subordinate: false +series: + - trusty + - xenial diff --git a/examples/NextEPC/charm-sources/layers/hsscharm/reactive/hsscharm.py b/examples/NextEPC/charm-sources/layers/hsscharm/reactive/hsscharm.py new file mode 100644 index 0000000..5d47ec7 --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/hsscharm/reactive/hsscharm.py @@ -0,0 +1,50 @@ +from charms.reactive import when, when_not, set_flag + +from charmhelpers.core.hookenv import ( + action_get, + action_fail, + action_set, + config, + status_set, +) + +from charms.reactive import ( + remove_state as remove_flag, + set_state as set_flag, + when, when_not +) + +import charms.sshproxy + +@when_not('hsscharm.installed') +def install_hsscharm(): + # Do your setup here. + # + # If your charm has other dependencies before it can install, + # add those as @when() clauses above., or as additional @when() + # decorated handlers below + # + # See the following for information about reactive charms: + # + # * https://jujucharms.com/docs/devel/developer-getting-started + # * https://github.com/juju-solutions/layer-basic#overview + # + set_flag('hsscharm.installed') + +@when('actions.configure-hss') +def configure_hss(): + spgw_ip = action_get('spgw-ip') + hss_ip = action_get('hss-ip') + cmd1 = "sudo ip link set ens4 up && sudo dhclient ens4" + charms.sshproxy._run(cmd1) + cmd2= 'sudo sed -i "\'s/$hss_ip/{}/g\'" /etc/nextepc/freeDiameter/hss.conf'.format(hss_ip) + charms.sshproxy._run(cmd2) + cmd3= 'sudo sed -i "\'s/$spgw_ip/{}/g\'" /etc/nextepc/freeDiameter/hss.conf'.format(spgw_ip) + charms.sshproxy._run(cmd3) + remove_flag('actions.configure-hss') + +@when('actions.restart-hss') +def restart_hss(): + cmd = "sudo systemctl restart nextepc-hssd" + charms.sshproxy._run(cmd) + remove_flag('actions.restart-hss') diff --git a/examples/NextEPC/charm-sources/layers/hsscharm/tests/00-setup b/examples/NextEPC/charm-sources/layers/hsscharm/tests/00-setup new file mode 100755 index 0000000..f0616a5 --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/hsscharm/tests/00-setup @@ -0,0 +1,5 @@ +#!/bin/bash + +sudo add-apt-repository ppa:juju/stable -y +sudo apt-get update +sudo apt-get install amulet python-requests -y diff --git a/examples/NextEPC/charm-sources/layers/hsscharm/tests/10-deploy b/examples/NextEPC/charm-sources/layers/hsscharm/tests/10-deploy new file mode 100755 index 0000000..17515e3 --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/hsscharm/tests/10-deploy @@ -0,0 +1,35 @@ +#!/usr/bin/python3 + +import amulet +import requests +import unittest + + +class TestCharm(unittest.TestCase): + def setUp(self): + self.d = amulet.Deployment() + + self.d.add('hsscharm') + self.d.expose('hsscharm') + + self.d.setup(timeout=900) + self.d.sentry.wait() + + self.unit = self.d.sentry['hsscharm'][0] + + def test_service(self): + # test we can access over http + page = requests.get('http://{}'.format(self.unit.info['public-address'])) + self.assertEqual(page.status_code, 200) + # Now you can use self.d.sentry[SERVICE][UNIT] to address each of the units and perform + # more in-depth steps. Each self.d.sentry[SERVICE][UNIT] has the following methods: + # - .info - An array of the information of that unit from Juju + # - .file(PATH) - Get the details of a file on that unit + # - .file_contents(PATH) - Get plain text output of PATH file from that unit + # - .directory(PATH) - Get details of directory + # - .directory_contents(PATH) - List files and folders in PATH on that unit + # - .relation(relation, service:rel) - Get relation data from return service + + +if __name__ == '__main__': + unittest.main() diff --git a/examples/NextEPC/charm-sources/layers/spgwcharm/README.ex b/examples/NextEPC/charm-sources/layers/spgwcharm/README.ex new file mode 100644 index 0000000..b6816b2 --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/spgwcharm/README.ex @@ -0,0 +1,65 @@ +# Overview + +Describe the intended usage of this charm and anything unique about how this +charm relates to others here. + +This README will be displayed in the Charm Store, it should be either Markdown +or RST. Ideal READMEs include instructions on how to use the charm, expected +usage, and charm features that your audience might be interested in. For an +example of a well written README check out Hadoop: +http://jujucharms.com/charms/precise/hadoop + +Use this as a Markdown reference if you need help with the formatting of this +README: http://askubuntu.com/editing-help + +This charm provides [service][]. Add a description here of what the service +itself actually does. + +Also remember to check the [icon guidelines][] so that your charm looks good +in the Juju GUI. + +# Usage + +Step by step instructions on using the charm: + +juju deploy servicename + +and so on. If you're providing a web service or something that the end user +needs to go to, tell them here, especially if you're deploying a service that +might listen to a non-default port. + +You can then browse to http://ip-address to configure the service. + +## Scale out Usage + +If the charm has any recommendations for running at scale, outline them in +examples here. For example if you have a memcached relation that improves +performance, mention it here. + +## Known Limitations and Issues + +This not only helps users but gives people a place to start if they want to help +you add features to your charm. + +# Configuration + +The configuration options will be listed on the charm store, however If you're +making assumptions or opinionated decisions in the charm (like setting a default +administrator password), you should detail that here so the user knows how to +change it immediately, etc. + +# Contact Information + +Though this will be listed in the charm store itself don't assume a user will +know that, so include that information here: + +## Upstream Project Name + + - Upstream website + - Upstream bug tracker + - Upstream mailing list or contact information + - Feel free to add things if it's useful for users + + +[service]: http://example.com +[icon guidelines]: https://jujucharms.com/docs/stable/authors-charm-icon diff --git a/examples/NextEPC/charm-sources/layers/spgwcharm/actions.yaml b/examples/NextEPC/charm-sources/layers/spgwcharm/actions.yaml new file mode 100644 index 0000000..84ab273 --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/spgwcharm/actions.yaml @@ -0,0 +1,24 @@ +configure-spgw: + description: "Configures the SPGW" + params: + hss-ip: + description: "HSS IP" + type: string + default: "0.0.0.0" + spgw-ip: + description: "SPGW IP" + type: string + default: "0.0.0.0" +add-route: + description: "Adds a route to the SPGW" + params: + external-prefix: + description: "Destinaton prefix IP" + type: string + default: "8.8.8.8/32" + next-hop: + description: "SGI next hop" + type: string + default: "192.168.2.1" +restart-spgw: + description: "Restarts the service of the VNF" diff --git a/examples/NextEPC/charm-sources/layers/spgwcharm/actions/add-route b/examples/NextEPC/charm-sources/layers/spgwcharm/actions/add-route new file mode 100755 index 0000000..7d02e2d --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/spgwcharm/actions/add-route @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +import sys +sys.path.append('lib') + +from charms.reactive import main +from charms.reactive import set_state +from charmhelpers.core.hookenv import action_fail, action_name + +""" +`set_state` only works here because it's flushed to disk inside the `main()` +loop. remove_state will need to be called inside the action method. +""" +set_state('actions.{}'.format(action_name())) + +try: + main() +except Exception as e: + action_fail(repr(e)) diff --git a/examples/NextEPC/charm-sources/layers/spgwcharm/actions/configure-spgw b/examples/NextEPC/charm-sources/layers/spgwcharm/actions/configure-spgw new file mode 100755 index 0000000..7d02e2d --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/spgwcharm/actions/configure-spgw @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +import sys +sys.path.append('lib') + +from charms.reactive import main +from charms.reactive import set_state +from charmhelpers.core.hookenv import action_fail, action_name + +""" +`set_state` only works here because it's flushed to disk inside the `main()` +loop. remove_state will need to be called inside the action method. +""" +set_state('actions.{}'.format(action_name())) + +try: + main() +except Exception as e: + action_fail(repr(e)) diff --git a/examples/NextEPC/charm-sources/layers/spgwcharm/actions/restart-spgw b/examples/NextEPC/charm-sources/layers/spgwcharm/actions/restart-spgw new file mode 100755 index 0000000..7d02e2d --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/spgwcharm/actions/restart-spgw @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +import sys +sys.path.append('lib') + +from charms.reactive import main +from charms.reactive import set_state +from charmhelpers.core.hookenv import action_fail, action_name + +""" +`set_state` only works here because it's flushed to disk inside the `main()` +loop. remove_state will need to be called inside the action method. +""" +set_state('actions.{}'.format(action_name())) + +try: + main() +except Exception as e: + action_fail(repr(e)) diff --git a/examples/NextEPC/charm-sources/layers/spgwcharm/config.yaml b/examples/NextEPC/charm-sources/layers/spgwcharm/config.yaml new file mode 100644 index 0000000..51f2ce4 --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/spgwcharm/config.yaml @@ -0,0 +1,14 @@ +options: + string-option: + type: string + default: "Default Value" + description: "A short description of the configuration option" + boolean-option: + type: boolean + default: False + description: "A short description of the configuration option" + int-option: + type: int + default: 9001 + description: "A short description of the configuration option" + diff --git a/examples/NextEPC/charm-sources/layers/spgwcharm/icon.svg b/examples/NextEPC/charm-sources/layers/spgwcharm/icon.svg new file mode 100644 index 0000000..96a5d0c --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/spgwcharm/icon.svg @@ -0,0 +1,279 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/examples/NextEPC/charm-sources/layers/spgwcharm/layer.yaml b/examples/NextEPC/charm-sources/layers/spgwcharm/layer.yaml new file mode 100644 index 0000000..aa4dc07 --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/spgwcharm/layer.yaml @@ -0,0 +1,3 @@ +includes: + - layer:basic + - layer:vnfproxy diff --git a/examples/NextEPC/charm-sources/layers/spgwcharm/metadata.yaml b/examples/NextEPC/charm-sources/layers/spgwcharm/metadata.yaml new file mode 100644 index 0000000..ab6bda7 --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/spgwcharm/metadata.yaml @@ -0,0 +1,11 @@ +name: spgwcharm +summary: NextEPC SPGW Charm +maintainer: Your name +description: | + This is an example of a proxy charm deployed by Open Source Mano. +tags: + - nfv +subordinate: false +series: + - trusty + - xenial diff --git a/examples/NextEPC/charm-sources/layers/spgwcharm/reactive/spgwcharm.py b/examples/NextEPC/charm-sources/layers/spgwcharm/reactive/spgwcharm.py new file mode 100644 index 0000000..83d5b1b --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/spgwcharm/reactive/spgwcharm.py @@ -0,0 +1,52 @@ +from charms.reactive import when, when_not, set_flag + +from charmhelpers.core.hookenv import ( + action_get, + action_fail, + action_set, + config, + status_set, +) + +from charms.reactive import ( + remove_state as remove_flag, + set_state as set_flag, + when, when_not +) + +import charms.sshproxy + +@when('actions.configure-spgw') +def configure_spgw(): + hss_ip = action_get('hss-ip') + spgw_ip = action_get('spgw-ip') + cmd1 = "sudo ip link set ens4 up && sudo dhclient ens4" + charms.sshproxy._run(cmd1) + cmd2 = "sudo ip link set ens5 up && sudo dhclient ens5" + charms.sshproxy._run(cmd2) + cmd3 = "sudo ip link set ens6 up && sudo dhclient ens6" + charms.sshproxy._run(cmd3) + cmd3='sudo sed -i "\'s/$hss_ip/{}/g\'" /etc/nextepc/freeDiameter/mme.conf'.format(hss_ip) + charms.sshproxy._run(cmd3) + cmd4='sudo sed -i "\'s/$spgw_ip/{}/g\'" /etc/nextepc/freeDiameter/mme.conf'.format(spgw_ip) + charms.sshproxy._run(cmd4) + remove_flag('actions.configure-spgw') + +@when('actions.restart-spgw') +def restart_spgw(): + cmd = "sudo systemctl restart nextepc-mmed" + charms.sshproxy._run(cmd) + remove_flag('actions.restart-spgw') + +@when_not('spgwcharm.installed') +def install_spgwcharm(): + set_flag('spgwcharm.installed') + +@when('actions.add-route') +def add_route(): + prefix = action_get('external-prefix') + next_hop = action_get('next-hop') + cmd = "sudo route add -net " + prefix + " gw " + next_hop + charms.sshproxy._run(cmd) + remove_flag('actions.add-route') + diff --git a/examples/NextEPC/charm-sources/layers/spgwcharm/tests/00-setup b/examples/NextEPC/charm-sources/layers/spgwcharm/tests/00-setup new file mode 100755 index 0000000..f0616a5 --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/spgwcharm/tests/00-setup @@ -0,0 +1,5 @@ +#!/bin/bash + +sudo add-apt-repository ppa:juju/stable -y +sudo apt-get update +sudo apt-get install amulet python-requests -y diff --git a/examples/NextEPC/charm-sources/layers/spgwcharm/tests/10-deploy b/examples/NextEPC/charm-sources/layers/spgwcharm/tests/10-deploy new file mode 100755 index 0000000..a98ff4c --- /dev/null +++ b/examples/NextEPC/charm-sources/layers/spgwcharm/tests/10-deploy @@ -0,0 +1,35 @@ +#!/usr/bin/python3 + +import amulet +import requests +import unittest + + +class TestCharm(unittest.TestCase): + def setUp(self): + self.d = amulet.Deployment() + + self.d.add('spgwcharm') + self.d.expose('spgwcharm') + + self.d.setup(timeout=900) + self.d.sentry.wait() + + self.unit = self.d.sentry['spgwcharm'][0] + + def test_service(self): + # test we can access over http + page = requests.get('http://{}'.format(self.unit.info['public-address'])) + self.assertEqual(page.status_code, 200) + # Now you can use self.d.sentry[SERVICE][UNIT] to address each of the units and perform + # more in-depth steps. Each self.d.sentry[SERVICE][UNIT] has the following methods: + # - .info - An array of the information of that unit from Juju + # - .file(PATH) - Get the details of a file on that unit + # - .file_contents(PATH) - Get plain text output of PATH file from that unit + # - .directory(PATH) - Get details of directory + # - .directory_contents(PATH) - List files and folders in PATH on that unit + # - .relation(relation, service:rel) - Get relation data from return service + + +if __name__ == '__main__': + unittest.main() diff --git a/examples/NextEPC/params.yaml b/examples/NextEPC/params.yaml new file mode 100644 index 0000000..372c391 --- /dev/null +++ b/examples/NextEPC/params.yaml @@ -0,0 +1,16 @@ +additionalParamsForVnf: +- member-vnf-index: '1' + additionalParams: + spgw_ip: '10.0.6.15' + hss_ip: '10.0.6.20' + password: 'osm4us' + +vnf: +- member-vnf-index: '1' + internal-vld: + - name: s6a + internal-connection-point: + - id-ref: spgwmme-s6a + ip-address: 10.0.6.15 + - id-ref: hss-s6a + ip-address: 10.0.6.20 diff --git a/examples/NextEPC/vEPC_nsd/README b/examples/NextEPC/vEPC_nsd/README new file mode 100644 index 0000000..81581bd --- /dev/null +++ b/examples/NextEPC/vEPC_nsd/README @@ -0,0 +1,2 @@ +Descriptor created by OSM descriptor package generated +Created on Thu Sep 5 15:28:15 EDT 2019 diff --git a/examples/NextEPC/vEPC_nsd/vEPC_nsd.yaml b/examples/NextEPC/vEPC_nsd/vEPC_nsd.yaml new file mode 100644 index 0000000..c8a1598 --- /dev/null +++ b/examples/NextEPC/vEPC_nsd/vEPC_nsd.yaml @@ -0,0 +1,45 @@ +nsd:nsd-catalog: + nsd: + - id: vEPC_nsd + name: vEPC_nsd + short-name: vEPC_nsd + description: Generated by OSM package generator + vendor: OSM_VNFONB_TF + version: '1.0' + constituent-vnfd: + - member-vnf-index: 1 + vnfd-id-ref: vEPC_vnfd + vld: + - id: management + name: management + short-name: management + type: ELAN + mgmt-network: 'true' + vim-network-name: osm-ext + vnfd-connection-point-ref: + - member-vnf-index-ref: 1 + vnfd-id-ref: vEPC_vnfd + vnfd-connection-point-ref: spgwmme-mgmt + - member-vnf-index-ref: 1 + vnfd-id-ref: vEPC_vnfd + vnfd-connection-point-ref: hss-mgmt + - id: s1 + name: s1 + short-name: s1 + type: ELAN + vim-network-name: s1 + vnfd-connection-point-ref: + - member-vnf-index-ref: 1 + vnfd-id-ref: vEPC_vnfd + vnfd-connection-point-ref: spgwmme-s1 + ip-address: 192.168.0.11 + - id: sgi + name: sgi + short-name: sgi + type: ELAN + vim-network-name: sgi + vnfd-connection-point-ref: + - member-vnf-index-ref: 1 + vnfd-id-ref: vEPC_vnfd + vnfd-connection-point-ref: spgwmme-sgi + ip-address: 192.168.2.11 diff --git a/examples/NextEPC/vEPC_vnfd/README b/examples/NextEPC/vEPC_vnfd/README new file mode 100644 index 0000000..81581bd --- /dev/null +++ b/examples/NextEPC/vEPC_vnfd/README @@ -0,0 +1,2 @@ +Descriptor created by OSM descriptor package generated +Created on Thu Sep 5 15:28:15 EDT 2019 diff --git a/examples/NextEPC/vEPC_vnfd/cloud_init/hss-init b/examples/NextEPC/vEPC_vnfd/cloud_init/hss-init new file mode 100644 index 0000000..6b6f79b --- /dev/null +++ b/examples/NextEPC/vEPC_vnfd/cloud_init/hss-init @@ -0,0 +1,5 @@ +#cloud-config +hostname: nextepc-hss +password: {{ password }} +chpasswd: { expire: False } +ssh_pwauth: True diff --git a/examples/NextEPC/vEPC_vnfd/cloud_init/spgwmme-init b/examples/NextEPC/vEPC_vnfd/cloud_init/spgwmme-init new file mode 100644 index 0000000..79b4e15 --- /dev/null +++ b/examples/NextEPC/vEPC_vnfd/cloud_init/spgwmme-init @@ -0,0 +1,5 @@ +#cloud-config +hostname: nextepc-spgw +password: {{ password }} +chpasswd: { expire: False } +ssh_pwauth: True diff --git a/examples/NextEPC/vEPC_vnfd/vEPC_vnfd.yaml b/examples/NextEPC/vEPC_vnfd/vEPC_vnfd.yaml new file mode 100644 index 0000000..e61e202 --- /dev/null +++ b/examples/NextEPC/vEPC_vnfd/vEPC_vnfd.yaml @@ -0,0 +1,184 @@ +vnfd:vnfd-catalog: + vnfd: + - id: vEPC_vnfd + name: vEPC_vnfd + short-name: vEPC_vnfd + description: Generated by OSM package generator + vendor: OSM_VNFONB_TF + version: '1.0' + mgmt-interface: + cp: spgwmme-mgmt + + vdu: + - id: spgwmme + name: spgwmme + description: spgwmme + count: 1 + cloud-init-file: spgwmme-init +# guest-epa: +# cpu-pinning-policy: DEDICATED +# mempage-size: LARGE + vm-flavor: + vcpu-count: 2 + memory-mb: 4096 + storage-gb: 10 + image: 'nextepc-spgwmme-base' + interface: + - name: eth0 + type: EXTERNAL + virtual-interface: + type: PARAVIRT + external-connection-point-ref: spgwmme-mgmt + - name: eth1 + type: EXTERNAL + virtual-interface: +# type: SRIOV + type: PARAVIRT + external-connection-point-ref: spgwmme-s1 + - name: eth2 + type: EXTERNAL + virtual-interface: +# type: SRIOV + type: PARAVIRT + external-connection-point-ref: spgwmme-sgi + - name: eth3 + type: INTERNAL + virtual-interface: + type: PARAVIRT + internal-connection-point-ref: spgwmme-s6a + internal-connection-point: + - id: spgwmme-s6a + name: spgwmme-s6a + type: VPORT + monitoring-param: + - id: "spgw_cpu_util" + nfvi-metric: "cpu_utilization" + - id: "spgw_memory_util" + nfvi-metric: "average_memory_utilization" + + - id: hss + name: hss + description: hss + count: 1 + cloud-init-file: hss-init + vm-flavor: + vcpu-count: 1 + memory-mb: 2048 + storage-gb: 10 + image: 'nextepc-hss-base' + interface: + - name: eth0 + type: EXTERNAL + virtual-interface: + type: PARAVIRT + mgmt-interface: true + external-connection-point-ref: hss-mgmt + - name: eth1 + type: INTERNAL + virtual-interface: + type: PARAVIRT + internal-connection-point-ref: hss-s6a + internal-connection-point: + - id: hss-s6a + name: hss-s6a + type: VPORT + vdu-configuration: + initial-config-primitive: + - seq: '1' + name: config + parameter: + - name: ssh-hostname + value: + - name: ssh-username + value: ubuntu + - name: ssh-password + value: + - seq: '2' + name: configure-hss + parameter: + - name: spgw-ip + data-type: STRING + value: + - name: hss-ip + data-type: STRING + value: + - seq: '3' + name: restart-hss + juju: + charm: hsscharm + + + internal-vld: + - id: s6a + ip-profile-ref: s6a + internal-connection-point: + - id-ref: spgwmme-s6a + - id-ref: hss-s6a + name: s6a + + ip-profiles: + - name: s6a + description: s6a network + ip-profile-params: + ip-version: ipv4 + subnet-address: 10.0.6.0/24 + dhcp-params: + enabled: true + + + connection-point: + - name: spgwmme-mgmt + - name: spgwmme-s1 + - name: spgwmme-sgi + - name: hss-mgmt + + + vnf-configuration: + initial-config-primitive: + - seq: '1' + name: config + parameter: + - name: ssh-hostname + value: + - name: ssh-username + value: ubuntu + - name: ssh-password + value: + - seq: '2' + name: configure-spgw + parameter: + - name: spgw-ip + data-type: STRING + value: + - name: hss-ip + data-type: STRING + value: + - seq: '3' + name: restart-spgw + config-primitive: + - name: add-route + parameter: + - name: external-prefix + data-type: STRING + default-value: '8.8.8.8/32' + - name: next-hop + data-type: STRING + default-value: '192.168.2.1' + juju: + charm: spgwcharm + + + monitoring-param: + - id: "spgw_cpu_util" + name: "spgw_cpu_util" + aggregation-type: AVERAGE + vdu-monitoring-param: + vdu-ref: "spgwmme" + vdu-monitoring-param-ref: "spgw_cpu_util" + - id: "spgw_memory_util" + name: "spgw_memory_util" + aggregation-type: AVERAGE + vdu-monitoring-param: + vdu-ref: "spgwmme" + vdu-monitoring-param-ref: "spgw_memory_util" + -- GitLab From bfe6df6955a149a16cd4dc680fedd3f27c0f4a1e Mon Sep 17 00:00:00 2001 From: beierl Date: Wed, 30 Oct 2019 16:57:21 -0400 Subject: [PATCH 2/2] Network in cloud-init Moves network config from charm to cloud-init so that it will persist across reboots. Signed-off-by: beierl --- examples/NextEPC/build.sh | 1 - .../layers/hsscharm/reactive/hsscharm.py | 10 ++++------ .../layers/spgwcharm/reactive/spgwcharm.py | 14 ++++---------- .../NextEPC/vEPC_vnfd/cloud_init/hss-init | 13 +++++++++++++ .../NextEPC/vEPC_vnfd/cloud_init/spgwmme-init | 19 +++++++++++++++++++ 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/examples/NextEPC/build.sh b/examples/NextEPC/build.sh index 217c5a0..506db3e 100755 --- a/examples/NextEPC/build.sh +++ b/examples/NextEPC/build.sh @@ -27,4 +27,3 @@ osm vnfd-create vEPC_vnfd.tar.gz || exit 1 osm nsd-create vEPC_nsd.tar.gz || exit 1 osm ns-create --ns_name EPC1 --nsd_name vEPC_nsd --ssh_keys ~/.ssh/id_rsa.pub --config_file params.yaml --vim_account vnfob -ssh://git@osm.etsi.org:29419/beierl/vnf-onboarding-guidelines.git diff --git a/examples/NextEPC/charm-sources/layers/hsscharm/reactive/hsscharm.py b/examples/NextEPC/charm-sources/layers/hsscharm/reactive/hsscharm.py index 5d47ec7..73ab300 100644 --- a/examples/NextEPC/charm-sources/layers/hsscharm/reactive/hsscharm.py +++ b/examples/NextEPC/charm-sources/layers/hsscharm/reactive/hsscharm.py @@ -35,12 +35,10 @@ def install_hsscharm(): def configure_hss(): spgw_ip = action_get('spgw-ip') hss_ip = action_get('hss-ip') - cmd1 = "sudo ip link set ens4 up && sudo dhclient ens4" - charms.sshproxy._run(cmd1) - cmd2= 'sudo sed -i "\'s/$hss_ip/{}/g\'" /etc/nextepc/freeDiameter/hss.conf'.format(hss_ip) - charms.sshproxy._run(cmd2) - cmd3= 'sudo sed -i "\'s/$spgw_ip/{}/g\'" /etc/nextepc/freeDiameter/hss.conf'.format(spgw_ip) - charms.sshproxy._run(cmd3) + cmd = 'sudo sed -i "\'s/$hss_ip/{}/g\'" /etc/nextepc/freeDiameter/hss.conf'.format(hss_ip) + charms.sshproxy._run(cmd) + cmd = 'sudo sed -i "\'s/$spgw_ip/{}/g\'" /etc/nextepc/freeDiameter/hss.conf'.format(spgw_ip) + charms.sshproxy._run(cmd) remove_flag('actions.configure-hss') @when('actions.restart-hss') diff --git a/examples/NextEPC/charm-sources/layers/spgwcharm/reactive/spgwcharm.py b/examples/NextEPC/charm-sources/layers/spgwcharm/reactive/spgwcharm.py index 83d5b1b..ecd3960 100644 --- a/examples/NextEPC/charm-sources/layers/spgwcharm/reactive/spgwcharm.py +++ b/examples/NextEPC/charm-sources/layers/spgwcharm/reactive/spgwcharm.py @@ -20,16 +20,10 @@ import charms.sshproxy def configure_spgw(): hss_ip = action_get('hss-ip') spgw_ip = action_get('spgw-ip') - cmd1 = "sudo ip link set ens4 up && sudo dhclient ens4" - charms.sshproxy._run(cmd1) - cmd2 = "sudo ip link set ens5 up && sudo dhclient ens5" - charms.sshproxy._run(cmd2) - cmd3 = "sudo ip link set ens6 up && sudo dhclient ens6" - charms.sshproxy._run(cmd3) - cmd3='sudo sed -i "\'s/$hss_ip/{}/g\'" /etc/nextepc/freeDiameter/mme.conf'.format(hss_ip) - charms.sshproxy._run(cmd3) - cmd4='sudo sed -i "\'s/$spgw_ip/{}/g\'" /etc/nextepc/freeDiameter/mme.conf'.format(spgw_ip) - charms.sshproxy._run(cmd4) + cmd = 'sudo sed -i "\'s/$hss_ip/{}/g\'" /etc/nextepc/freeDiameter/mme.conf'.format(hss_ip) + charms.sshproxy._run(cmd) + cmd = 'sudo sed -i "\'s/$spgw_ip/{}/g\'" /etc/nextepc/freeDiameter/mme.conf'.format(spgw_ip) + charms.sshproxy._run(cmd) remove_flag('actions.configure-spgw') @when('actions.restart-spgw') diff --git a/examples/NextEPC/vEPC_vnfd/cloud_init/hss-init b/examples/NextEPC/vEPC_vnfd/cloud_init/hss-init index 6b6f79b..d6e39fe 100644 --- a/examples/NextEPC/vEPC_vnfd/cloud_init/hss-init +++ b/examples/NextEPC/vEPC_vnfd/cloud_init/hss-init @@ -3,3 +3,16 @@ hostname: nextepc-hss password: {{ password }} chpasswd: { expire: False } ssh_pwauth: True + +write_files: +- owner: root:root + content: | + network: + version: 2 + ethernets: + ens4: + dhcp4: true + path: /etc/netplan/51-additional-interfaces.yaml +runcmd: +- /sbin/ip link set ens4 up +- /usr/sbin/netplan apply diff --git a/examples/NextEPC/vEPC_vnfd/cloud_init/spgwmme-init b/examples/NextEPC/vEPC_vnfd/cloud_init/spgwmme-init index 79b4e15..a89ae90 100644 --- a/examples/NextEPC/vEPC_vnfd/cloud_init/spgwmme-init +++ b/examples/NextEPC/vEPC_vnfd/cloud_init/spgwmme-init @@ -3,3 +3,22 @@ hostname: nextepc-spgw password: {{ password }} chpasswd: { expire: False } ssh_pwauth: True + +write_files: +- owner: root:root + content: | + network: + version: 2 + ethernets: + ens4: + dhcp4: true + ens5: + dhcp4: true + ens6: + dhcp4: true + path: /etc/netplan/51-additional-interfaces.yaml +runcmd: +- /sbin/ip link set ens4 up +- /sbin/ip link set ens5 up +- /sbin/ip link set ens6 up +- /usr/sbin/netplan apply -- GitLab