Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from charmhelpers.core.hookenv import (
action_fail,
action_set,
)
from charms.reactive import (
when,
clear_flag,
)
import charms.sshproxy
@when('actions.reboot')
def reboot():
err = ''
try:
result, err = charms.sshproxy._run("reboot")
except:
action_fail('command failed:' + err)
else:
action_set({'outout': result})
finally:
clear_flag('actions.reboot')
###############################################################################
# Below is an example implementation of the start/stop/restart actions. #
# To use this, copy the below code into your layer and add the appropriate #
# command(s) necessary to perform the action. #
###############################################################################
# @when('actions.start')
# def start():
# err = ''
# try:
# cmd = "service myname start"
# result, err = charms.sshproxy._run(cmd)
# except:
# action_fail('command failed:' + err)
# else:
# action_set({'outout': result})
# finally:
# clear_flag('actions.start')
#
#
# @when('actions.stop')
# def stop():
# err = ''
# try:
# # Enter the command to stop your service(s)
# cmd = "service myname stop"
# result, err = charms.sshproxy._run(cmd)
# except:
# action_fail('command failed:' + err)
# else:
# action_set({'outout': result})
# finally:
# clear_flag('actions.stop')
#
#
# @when('actions.restart')
# def restart():
# err = ''
# try:
# # Enter the command to restart your service(s)
# cmd = "service myname restart"
# result, err = charms.sshproxy._run(cmd)
# except:
# action_fail('command failed:' + err)
# else:
# action_set({'outout': result})
# finally:
# clear_flag('actions.restart')
#
#
# @when('actions.upgrade')
# def upgrade_vnf():
# err = ''
# try:
# # Add the command(s) to perform a VNF software upgrade
# cmd = ''
# result, err = charms.sshproxy._run(cmd)
# except:
# action_fail('command failed:' + err)
# else:
# action_set({'outout': result})
# finally:
# clear_flag('actions.upgrade')
#