Skip to content
Snippets Groups Projects
Commit 081f469e authored by garciadav's avatar garciadav
Browse files

Add NG-UI Charm


Change-Id: Id94b6e0383994580c2b11ab66a44f7c197cb7412
Signed-off-by: default avatarDavid Garcia <david.garcia@canonical.com>
parent 18c7a8b4
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,9 @@
# 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.
[submodule "installers/charm/pla/mod/operator"]
path = installers/charm/pla/mod/operator
url = https://github.com/canonical/operator
[submodule "installers/charm/ng-ui/mod/operator"]
path = installers/charm/ng-ui/mod/operator
url = https://github.com/canonical/operator
......@@ -43,7 +43,8 @@ The "layers" folder include one common layer for all the osm charms (osm-common)
├── nbi-k8s
├── pol-k8s
├── ro-k8s
└── ui-k8s
├── ui-k8s
└── ng-ui --> new operator framework
```
......
# Copyright 2020 Canonical Ltd.
#
# 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.
---
extends: default
yaml-files:
- "*.yaml"
- "*.yml"
- ".yamllint"
ignore: |
.tox
mod
<!-- # Copyright 2020 Canonical Ltd.
#
# 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. -->
# NG-UI Charm
\ No newline at end of file
# -*- coding: utf-8 -*-
# Copyright 2020 Arctos Labs Scandinavia AB
#
# 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.
options:
image:
description: Docker image name
type: string
default: opensourcemano/ng-ui:8.0.0rc1
port:
description: Port number
type: int
default: 80
server_name:
description: Server name
type: string
default: localhost
client_max_body_size:
description: Client maximum body size
type: string
default: 15M
nbi_hostname:
description: NBI hostname
type: string
default: nbi-k8s
nbi_port:
description: NBI Port
type: int
default: 9999
# Copyright 2020 Canonical Ltd.
#
# 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.
server {
listen $port;
server_name $server_name;
root /usr/share/nginx/html;
index index.html index.htm;
client_max_body_size $client_max_body_size;
location /osm {
proxy_pass http://$nbi_hostname:$nbi_port;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_set_header Accept-Encoding "";
}
location / {
try_files $$uri $$uri/ /index.html;
}
}
../src/charm.py
\ No newline at end of file
../mod/operator/ops
\ No newline at end of file
# Copyright 2020 Canonical Ltd.
#
# 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.
name: ng-ui
summary: A Next Generation UI charm for Opensource MANO
description: |
New UI for OSM
series:
- kubernetes
min-juju-version: 2.7.0
deployment:
type: stateless
service: cluster
provides:
nbi:
interface: osm-nbi
Subproject commit a84ce8776b368a8b2bccdb173716e342db9a6b36
#!/usr/bin/env python3
# Copyright 2020 Canonical Ltd.
#
# 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.
import sys
import logging
sys.path.append("lib")
from ops.charm import CharmBase
from ops.framework import StoredState, Object
from ops.main import main
from ops.model import (
ActiveStatus,
MaintenanceStatus,
)
from glob import glob
from pathlib import Path
from string import Template
logger = logging.getLogger(__name__)
class NGUICharm(CharmBase):
state = StoredState()
def __init__(self, framework, key):
super().__init__(framework, key)
self.state.set_default(spec=None)
# Observe Charm related events
self.framework.observe(self.on.config_changed, self.on_config_changed)
self.framework.observe(self.on.start, self.on_start)
self.framework.observe(self.on.upgrade_charm, self.on_upgrade_charm)
# self.framework.observe(
# self.on.nbi_relation_joined, self.on_nbi_relation_joined
# )
def _apply_spec(self):
# Only apply the spec if this unit is a leader.
if not self.framework.model.unit.is_leader():
return
new_spec = self.make_pod_spec()
if new_spec == self.state.spec:
return
self.framework.model.pod.set_spec(new_spec)
self.state.spec = new_spec
def make_pod_spec(self):
config = self.framework.model.config
ports = [
{"name": "port", "containerPort": config["port"], "protocol": "TCP",},
]
kubernetes = {
"readinessProbe": {
"tcpSocket": {"port": config["port"]},
"timeoutSeconds": 5,
"periodSeconds": 5,
"initialDelaySeconds": 10,
},
"livenessProbe": {
"tcpSocket": {"port": config["port"]},
"timeoutSeconds": 5,
"initialDelaySeconds": 45,
},
}
config_spec = {
"port": config["port"],
"server_name": config["server_name"],
"client_max_body_size": config["client_max_body_size"],
"nbi_hostname": config["nbi_hostname"],
"nbi_port": config["nbi_port"],
}
files = [
{
"name": "configuration",
"mountPath": "/etc/nginx/sites-available/",
"files": {
Path(filename)
.name: Template(Path(filename).read_text())
.substitute(config_spec)
for filename in glob("files/*")
},
},
]
logger.debug(files)
spec = {
"version": 2,
"containers": [
{
"name": self.framework.model.app.name,
"image": "{}".format(config["image"]),
"ports": ports,
"kubernetes": kubernetes,
"files": files,
}
],
}
return spec
def on_config_changed(self, event):
"""Handle changes in configuration"""
unit = self.model.unit
unit.status = MaintenanceStatus("Applying new pod spec")
self._apply_spec()
unit.status = ActiveStatus("Ready")
def on_start(self, event):
"""Called when the charm is being installed"""
unit = self.model.unit
unit.status = MaintenanceStatus("Applying pod spec")
self._apply_spec()
unit.status = ActiveStatus("Ready")
def on_upgrade_charm(self, event):
"""Upgrade the charm."""
unit = self.model.unit
unit.status = MaintenanceStatus("Upgrading charm")
self.on_start(event)
# def on_nbi_relation_joined(self, event):
# unit = self.model.unit
# if not unit.is_leader():
# return
# config = self.framework.model.config
# unit = MaintenanceStatus("Sending connection data")
# unit = ActiveStatus("Ready")
if __name__ == "__main__":
main(NGUICharm)
# Copyright 2020 Canonical Ltd.
#
# 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.
[tox]
envlist = pep8
skipsdist = True
[testenv]
setenv = VIRTUAL_ENV={envdir}
PYTHONHASHSEED=0
whitelist_externals = juju
passenv = HOME TERM CS_API_* OS_* AMULET_*
deps = -r{toxinidir}/test-requirements.txt
install_command =
pip install {opts} {packages}
[testenv:black]
basepython = python3
deps =
black
yamllint
commands =
black --check --diff src
yamllint .
[testenv:pep8]
basepython = python3
deps=charm-tools
commands = charm-proof
[testenv:func-noop]
basepython = python3
commands =
true
[testenv:func]
basepython = python3
commands = functest-run-suite
[testenv:func-smoke]
basepython = python3
commands = functest-run-suite --keep-model --smoke
[testenv:venv]
commands = {posargs}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment