Browse Source

Adding status messages in charms - Ticket:[SOL-949]

Bilal Baqar 3 years ago
parent
commit
c9cefc745c
4 changed files with 19 additions and 3 deletions
  1. 13
    1
      hooks/pg_gw_hooks.py
  2. 3
    1
      hooks/pg_gw_utils.py
  3. 1
    0
      hooks/update-status
  4. 2
    1
      templates/kilo/00-pg.conf

+ 13
- 1
hooks/pg_gw_hooks.py View File

@@ -6,12 +6,13 @@
6 6
 # in this file.
7 7
 
8 8
 import sys
9
-
9
+from charmhelpers.core.host import service_running
10 10
 from charmhelpers.core.hookenv import (
11 11
     Hooks,
12 12
     UnregisteredHookError,
13 13
     log,
14 14
     config,
15
+    status_set
15 16
 )
16 17
 
17 18
 from charmhelpers.fetch import (
@@ -45,8 +46,10 @@ def install():
45 46
     '''
46 47
     Install hook is run when the charm is first deployed on a node.
47 48
     '''
49
+    status_set('maintenance', 'Executing pre-install')
48 50
     load_iptables()
49 51
     configure_sources(update=True)
52
+    status_set('maintenance', 'Installing apt packages')
50 53
     pkgs = determine_packages()
51 54
     for pkg in pkgs:
52 55
         apt_install(pkg, options=['--force-yes'], fatal=True)
@@ -88,6 +91,7 @@ def config_changed():
88 91
         charm_config.changed('install_keys') or
89 92
             charm_config.changed('iovisor-build')):
90 93
         stop_pg()
94
+        status_set('maintenance', 'Upgrading apt packages')
91 95
         configure_sources(update=True)
92 96
         pkgs = determine_packages()
93 97
         for pkg in pkgs:
@@ -113,6 +117,14 @@ def stop():
113 117
     stop_pg()
114 118
 
115 119
 
120
+@hooks.hook('update-status')
121
+def update_status():
122
+    if service_running('plumgrid'):
123
+        status_set('active', 'Unit is ready')
124
+    else:
125
+        status_set('blocked', 'plumgrid service not running')
126
+
127
+
116 128
 def main():
117 129
     try:
118 130
         hooks.execute(sys.argv)

+ 3
- 1
hooks/pg_gw_utils.py View File

@@ -16,7 +16,8 @@ from charmhelpers.contrib.openstack import templating
16 16
 from charmhelpers.core.hookenv import (
17 17
     log,
18 18
     config,
19
-    unit_get
19
+    unit_get,
20
+    status_set
20 21
 )
21 22
 from charmhelpers.contrib.network.ip import (
22 23
     get_iface_from_addr,
@@ -160,6 +161,7 @@ def restart_pg():
160 161
                     raise ValueError("plumgrid service couldn't be started")
161 162
             else:
162 163
                 raise ValueError("libvirt-bin service couldn't be started")
164
+    status_set('active', 'Unit is ready')
163 165
 
164 166
 
165 167
 def stop_pg():

+ 1
- 0
hooks/update-status View File

@@ -0,0 +1 @@
1
+pg_gw_hooks.py

+ 2
- 1
templates/kilo/00-pg.conf View File

@@ -1 +1,2 @@
1
-$template ls_json,"{{'{'}}{{'%'}}timestamp:::date-rfc3339,jsonf:@timestamp%,%source:::jsonf:@source_host%,%msg:::json%}":syslogtag,isequal,"pg:" @{{ opsvm_ip }}:6000;ls_json
1
+$template ls_json,"{{'{'}}{{'%'}}timestamp:::date-rfc3339,jsonf:@timestamp%,%source:::jsonf:@source_host%,%msg:::json%}"
2
+:syslogtag,isequal,"pg:" @{{ opsvm_ip }}:6000;ls_json

Loading…
Cancel
Save