diff --git a/simple_ee_vnf/cloud_init/cloud-config.txt b/simple_ee_vnf/cloud_init/cloud-config.txt index e22d345c183842dfd2f6a03b28040ce70f72c5b3..a9acf62700fbcaed336d7a5213143e22da63a8c7 100755 --- a/simple_ee_vnf/cloud_init/cloud-config.txt +++ b/simple_ee_vnf/cloud_init/cloud-config.txt @@ -1,12 +1,4 @@ #cloud-config -password: osm4u +password: osm2020 chpasswd: { expire: False } ssh_pwauth: True - -write_files: -- content: | - # My new helloworld file - - owner: root:root - permissions: '0644' - path: /root/helloworld.txt diff --git a/simple_ee_vnf/helm-charts/eechart-0.1.0.tgz b/simple_ee_vnf/helm-charts/eechart-0.1.0.tgz deleted file mode 100644 index 98527426330dc335baa22798114771e45df27c6f..0000000000000000000000000000000000000000 Binary files a/simple_ee_vnf/helm-charts/eechart-0.1.0.tgz and /dev/null differ diff --git a/simple_ee_vnf/helm-charts/eechart/.helmignore b/simple_ee_vnf/helm-charts/eechart/.helmignore new file mode 100755 index 0000000000000000000000000000000000000000..50af0317254197a5a019f4ac2f8ecc223f93f5a7 --- /dev/null +++ b/simple_ee_vnf/helm-charts/eechart/.helmignore @@ -0,0 +1,22 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/simple_ee_vnf/helm-charts/eechart/Chart.yaml b/simple_ee_vnf/helm-charts/eechart/Chart.yaml new file mode 100755 index 0000000000000000000000000000000000000000..414c5f1aa1becbd34d69342874b63db8bb1cb77c --- /dev/null +++ b/simple_ee_vnf/helm-charts/eechart/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: OSM EE helm chart +name: eechart +version: 0.1.0 diff --git a/simple_ee_vnf/helm-charts/eechart/source/install.sh b/simple_ee_vnf/helm-charts/eechart/source/install.sh new file mode 100755 index 0000000000000000000000000000000000000000..248ec4819f981c16cf71f1605646eef294a92697 --- /dev/null +++ b/simple_ee_vnf/helm-charts/eechart/source/install.sh @@ -0,0 +1,29 @@ +#!/bin/bash +## +# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U. +# 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. +## + +# This script is intended for launching RO from a docker container. +# It waits for mysql server ready, normally running on a separate container, ... +# then it checks if database is present and creates it if needed. +# Finally it launches RO server. + +echo "Sample install.sh from source dir" + +# Install libraries +#apt-get install -y ... + +# Install library to execute command remotely by ssh +python3 -m pip install asyncssh + diff --git a/simple_ee_vnf/helm-charts/eechart/source/vnf_ee.py b/simple_ee_vnf/helm-charts/eechart/source/vnf_ee.py new file mode 100755 index 0000000000000000000000000000000000000000..3f4a15bb0496871c95576a351019c7bf99f950cc --- /dev/null +++ b/simple_ee_vnf/helm-charts/eechart/source/vnf_ee.py @@ -0,0 +1,92 @@ +## +# Copyright 2019 Telefonica Investigacion y Desarrollo, S.A.U. +# This file is part of OSM +# All Rights Reserved. +# +# 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. +# +# For those usages not covered by the Apache License, Version 2.0 please +# contact with: nfvlabs@tid.es +## + +import asyncio +import logging +import asyncssh + + +from osm_ee.exceptions import VnfException + + +class VnfEE: + + def __init__(self, config_params): + self.logger = logging.getLogger('osm_ee.vnf') + self.config_params = config_params + + async def config(self, id, params): + self.logger.debug("Execute action config params: {}".format(params)) + # Config action is special, params are merged with previous config calls + self.config_params.update(params) + required_params = ["ssh-hostname"] + self._check_required_params(self.config_params, required_params) + yield "OK", "Configured" + + async def touch(self, id, params): + self.logger.debug("Execute action touch params: '{}', type: {}".format(params, type(params))) + + try: + self._check_required_params(params, ["file-path"]) + + # Check if filename is a single file or a list + file_list = params["file-path"] if isinstance(params["file-path"], list) else [params["file-path"]] + file_list_length = len(file_list) + + async with asyncssh.connect(self.config_params["ssh-hostname"], + password=self.config_params.get("ssh-password"), + username=self.config_params.get("ssh-username"), + known_hosts=None) as conn: + for index, file_name in enumerate(file_list): + command = "touch {}".format(file_name) + self.logger.debug("Execute remote command: '{}'".format(command)) + result = await conn.run(command) + self.logger.debug("Create command result: {}".format(result)) + + if result.exit_status != 0: + detailed_status = result.stderr + # TODO - ok but with some errors + else: + detailed_status = "Created file {}".format(file_name) + + if index + 1 != file_list_length: + yield "PROCESSING", detailed_status + else: + yield "OK", detailed_status + except Exception as e: + self.logger.error("Error creating remote file: {}".format(repr(e))) + yield "ERROR", str(e) + + async def sleep(self, id, params): + self.logger.debug("Execute action sleep, params: {}".format(params)) + + for i in range(3): + await asyncio.sleep(5) + self.logger.debug("Temporal result return, params: {}".format(params)) + yield "PROCESSING", f"Processing {i} action id {id}" + yield "OK", f"Processed action id {id}" + + @staticmethod + def _check_required_params(params, required_params): + for required_param in required_params: + if required_param not in params: + raise VnfException("Missing required param: {}".format(required_param)) diff --git a/simple_ee_vnf/helm-charts/eechart/templates/NOTES.txt b/simple_ee_vnf/helm-charts/eechart/templates/NOTES.txt new file mode 100755 index 0000000000000000000000000000000000000000..c52fc2c419ef6f4cccfb63fd93ca7379bfc04cf7 --- /dev/null +++ b/simple_ee_vnf/helm-charts/eechart/templates/NOTES.txt @@ -0,0 +1,21 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "eechart.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "eechart.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "eechart.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "eechart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl port-forward $POD_NAME 8080:80 +{{- end }} diff --git a/simple_ee_vnf/helm-charts/eechart/templates/_helpers.tpl b/simple_ee_vnf/helm-charts/eechart/templates/_helpers.tpl new file mode 100755 index 0000000000000000000000000000000000000000..d3e28e0260b8bff2fdef09046df0abaea885739c --- /dev/null +++ b/simple_ee_vnf/helm-charts/eechart/templates/_helpers.tpl @@ -0,0 +1,56 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "eechart.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "eechart.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "eechart.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "eechart.labels" -}} +app.kubernetes.io/name: {{ include "eechart.name" . }} +helm.sh/chart: {{ include "eechart.chart" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} + +{{/* +Create the name of the service account to use +*/}} +{{- define "eechart.serviceAccountName" -}} +{{- if .Values.serviceAccount.create -}} + {{ default (include "eechart.fullname" .) .Values.serviceAccount.name }} +{{- else -}} + {{ default "default" .Values.serviceAccount.name }} +{{- end -}} +{{- end -}} diff --git a/simple_ee_vnf/helm-charts/eechart/templates/configmap.yaml b/simple_ee_vnf/helm-charts/eechart/templates/configmap.yaml new file mode 100755 index 0000000000000000000000000000000000000000..5b9634c7e1abe64c6f720f708dd5c9664e72e8cf --- /dev/null +++ b/simple_ee_vnf/helm-charts/eechart/templates/configmap.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "eechart.fullname" . }} +data: +{{ (.Files.Glob "source/*").AsConfig | indent 2 }} diff --git a/simple_ee_vnf/helm-charts/eechart/templates/ingress.yaml b/simple_ee_vnf/helm-charts/eechart/templates/ingress.yaml new file mode 100755 index 0000000000000000000000000000000000000000..264f89091bee2ba8746edc2841c275d28fef1168 --- /dev/null +++ b/simple_ee_vnf/helm-charts/eechart/templates/ingress.yaml @@ -0,0 +1,41 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "eechart.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: +{{ include "eechart.labels" . | indent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: +{{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ . }} + backend: + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} +{{- end }} diff --git a/simple_ee_vnf/helm-charts/eechart/templates/service.yaml b/simple_ee_vnf/helm-charts/eechart/templates/service.yaml new file mode 100755 index 0000000000000000000000000000000000000000..88d38d66a3997c6e2a96754582736cfb065da6c2 --- /dev/null +++ b/simple_ee_vnf/helm-charts/eechart/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "eechart.fullname" . }} + labels: +{{ include "eechart.labels" . | indent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: grpc + protocol: TCP + name: grpc + selector: + app.kubernetes.io/name: {{ include "eechart.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/simple_ee_vnf/helm-charts/eechart/templates/serviceaccount.yaml b/simple_ee_vnf/helm-charts/eechart/templates/serviceaccount.yaml new file mode 100755 index 0000000000000000000000000000000000000000..be615a5f08c7b557446fa74e5e3619e47d2ee804 --- /dev/null +++ b/simple_ee_vnf/helm-charts/eechart/templates/serviceaccount.yaml @@ -0,0 +1,8 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ template "eechart.serviceAccountName" . }} + labels: +{{ include "eechart.labels" . | indent 4 }} +{{- end -}} diff --git a/simple_ee_vnf/helm-charts/eechart/templates/statefulset.yaml b/simple_ee_vnf/helm-charts/eechart/templates/statefulset.yaml new file mode 100755 index 0000000000000000000000000000000000000000..3d721fe2d53ef73ba7b00af3d9567542c3799028 --- /dev/null +++ b/simple_ee_vnf/helm-charts/eechart/templates/statefulset.yaml @@ -0,0 +1,65 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "eechart.fullname" . }} + labels: +{{ include "eechart.labels" . | indent 4 }} +spec: + serviceName: {{ include "eechart.fullname" . }} + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "eechart.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "eechart.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + imagePullSecrets: + - name: regcred + serviceAccountName: {{ template "eechart.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: grpc + containerPort: 50051 + protocol: TCP + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: osm-ee + mountPath: /app/storage + - name: osm-ee-source + mountPath: /app/EE/osm_ee/vnf + volumes: + - name: osm-ee-source + configMap: + name: {{ include "eechart.fullname" . }} + volumeClaimTemplates: + - metadata: + name: osm-ee + spec: + accessModes: [ "ReadWriteOnce" ] + resources: + requests: + storage: 1Gi + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/simple_ee_vnf/helm-charts/eechart/templates/tests/test-connection.yaml b/simple_ee_vnf/helm-charts/eechart/templates/tests/test-connection.yaml new file mode 100755 index 0000000000000000000000000000000000000000..e52b7b8b2515729e582b5efbc22dc5a0bdb0f3b2 --- /dev/null +++ b/simple_ee_vnf/helm-charts/eechart/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "eechart.fullname" . }}-test-connection" + labels: +{{ include "eechart.labels" . | indent 4 }} + annotations: + "helm.sh/hook": test-success +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "eechart.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/simple_ee_vnf/helm-charts/eechart/values.yaml b/simple_ee_vnf/helm-charts/eechart/values.yaml new file mode 100755 index 0000000000000000000000000000000000000000..84cb21b701265e7f293d7b771d389907dba8c988 --- /dev/null +++ b/simple_ee_vnf/helm-charts/eechart/values.yaml @@ -0,0 +1,68 @@ +# Default values for eechart. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: illoret/grpcee + tag: latest + pullPolicy: IfNotPresent + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: false + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 50050 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: [] + + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/simple_ee_vnf/simple_ee_vnfd.yaml b/simple_ee_vnf/simple_ee_vnfd.yaml index d1aa5c0186023a729d799a9f7b6e44e79f4004e9..7960bd10e177afc951226eb69129ec8a5034d623 100644 --- a/simple_ee_vnf/simple_ee_vnfd.yaml +++ b/simple_ee_vnf/simple_ee_vnfd.yaml @@ -44,13 +44,10 @@ vnfd-catalog: ssh-access: default-user: ubuntu required: true - #juju: - # charm: simple-proxy execution-environment-list: - id: monitor - helm-chart: eechart-0.1.0.tgz - metric-service: monitor-snmp-exporter - connection-point-ref: vnf-monitor-cp + helm-chart: eechart + connection-point-ref: vnf-mgmt initial-config-primitive: - seq: "1" name: config @@ -61,7 +58,7 @@ vnfd-catalog: - name: ssh-username value: ubuntu - name: ssh-password - value: osm4u + value: osm2020 - seq: "2" name: touch execution-environment-ref: monitor