Commit e984af0d authored by fleischmann's avatar fleischmann
Browse files

Remove service Actions and add Delete URL



This commit add the deleteurl action which is
written in python. The service action were
removed as they were not working properly.
Signed-off-by: fleischmann's avatarDominik Fleischmann <dominik.fleischmann@canonical.com>
parent ab36046d
addurl:
description: "Add squid config"
description: "Add allowed URL to squid config"
params:
url:
description: "URL that will be allowed"
type: string
default: ""
start:
description: "Start squid service"
restart:
description: "Retart squid service"
stop:
description: "Stop squid service"
deleteurl:
description: "Delete allowed URL squid config"
params:
url:
description: "URL that will stop to be allowed"
type: string
default: ""
......@@ -2,7 +2,7 @@ options:
image:
type: string
description: 'Docker image for squid'
default: 'sameersbn/squid:latest'
default: 'domfleischmann/squid-python'
port:
type: int
description: 'Port'
......
......@@ -12,6 +12,7 @@ from ops.charm import CharmBase
from ops.framework import StoredState
from ops.main import main
from ops.model import ActiveStatus, MaintenanceStatus
import subprocess
class SquidK8SCharm(CharmBase):
......@@ -26,7 +27,7 @@ class SquidK8SCharm(CharmBase):
self.framework.observe(self.on.install, self.on_install)
self.framework.observe(self.on.start, self.on_start)
self.framework.observe(self.on.config_changed, self.on_config_changed)
# self.framework.observe(self.on.addconfig_action, self)
self.framework.observe(self.on.deleteurl_action, self)
# -- initialize states --
self.state.set_default(installed=False)
self.state.set_default(configured=False)
......@@ -91,6 +92,29 @@ class SquidK8SCharm(CharmBase):
self.state.started = True
logging.info("Started")
def on_deleteurl_action(self, event):
"""Handle the deleteurl action."""
url = event.params["url"]
line_to_delete = "acl allowedurls dstdomain .{}".format(url)
line_deleted = False
with open("/etc/squid/squid.conf", "r") as f:
lines = f.readlines()
with open("/etc/squid/squid.conf", "w") as f:
for line in lines:
if line_to_delete not in line:
f.write(line)
else:
line_deleted = True
if line_deleted:
event.set_results({"output": "URL deleted succesfully"})
subprocess.check_output("kill -HUP `cat /var/run/squid.pid`", shell=True)
else:
event.fail("No URL was deleted")
if __name__ == "__main__":
from ops.main import main
main(SquidK8SCharm)
......@@ -11,22 +11,15 @@ vnfd-catalog:
juju-bundle: bundle.yaml
kdu-configuration:
config-primitive:
- name: restart
parameter:
- name: application-name
data-type: STRING
default-value: squid
- name: start
- name: addurl
parameter:
- name: application-name
data-type: STRING
default-value: squid
- name: stop
parameter:
- name: application-name
- name: url
data-type: STRING
default-value: squid
- name: addurl
default-value: ""
- name: deleteurl
parameter:
- name: application-name
data-type: STRING
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment