vici: Extract command wrappers in Python bindings
[strongswan.git] / src / libcharon / plugins / vici / python / vici / command_wrappers.py
1 class CommandWrappers(object):
2 def version(self):
3 """Retrieve daemon and system specific version information.
4
5 :return: daemon and system specific version information
6 :rtype: dict
7 """
8 return self.request("version")
9
10 def stats(self):
11 """Retrieve IKE daemon statistics and load information.
12
13 :return: IKE daemon statistics and load information
14 :rtype: dict
15 """
16 return self.request("stats")
17
18 def reload_settings(self):
19 """Reload strongswan.conf settings and any plugins supporting reload.
20 """
21 self.request("reload-settings")
22
23 def initiate(self, sa):
24 """Initiate an SA.
25
26 :param sa: the SA to initiate
27 :type sa: dict
28 :return: generator for logs emitted as dict
29 :rtype: generator
30 """
31 return self.streamed_request("initiate", "control-log", sa)
32
33 def terminate(self, sa):
34 """Terminate an SA.
35
36 :param sa: the SA to terminate
37 :type sa: dict
38 :return: generator for logs emitted as dict
39 :rtype: generator
40 """
41 return self.streamed_request("terminate", "control-log", sa)
42
43 def redirect(self, sa):
44 """Redirect an IKE_SA.
45
46 :param sa: the SA to redirect
47 :type sa: dict
48 """
49 self.request("redirect", sa)
50
51 def install(self, policy):
52 """Install a trap, drop or bypass policy defined by a CHILD_SA config.
53
54 :param policy: policy to install
55 :type policy: dict
56 """
57 self.request("install", policy)
58
59 def uninstall(self, policy):
60 """Uninstall a trap, drop or bypass policy defined by a CHILD_SA config.
61
62 :param policy: policy to uninstall
63 :type policy: dict
64 """
65 self.request("uninstall", policy)
66
67 def list_sas(self, filters=None):
68 """Retrieve active IKE_SAs and associated CHILD_SAs.
69
70 :param filters: retrieve only matching IKE_SAs (optional)
71 :type filters: dict
72 :return: generator for active IKE_SAs and associated CHILD_SAs as dict
73 :rtype: generator
74 """
75 return self.streamed_request("list-sas", "list-sa", filters)
76
77 def list_policies(self, filters=None):
78 """Retrieve installed trap, drop and bypass policies.
79
80 :param filters: retrieve only matching policies (optional)
81 :type filters: dict
82 :return: generator for installed trap, drop and bypass policies as dict
83 :rtype: generator
84 """
85 return self.streamed_request("list-policies", "list-policy",
86 filters)
87
88 def list_conns(self, filters=None):
89 """Retrieve loaded connections.
90
91 :param filters: retrieve only matching configuration names (optional)
92 :type filters: dict
93 :return: generator for loaded connections as dict
94 :rtype: generator
95 """
96 return self.streamed_request("list-conns", "list-conn",
97 filters)
98
99 def get_conns(self):
100 """Retrieve connection names loaded exclusively over vici.
101
102 :return: connection names
103 :rtype: dict
104 """
105 return self.request("get-conns")
106
107 def list_certs(self, filters=None):
108 """Retrieve loaded certificates.
109
110 :param filters: retrieve only matching certificates (optional)
111 :type filters: dict
112 :return: generator for loaded certificates as dict
113 :rtype: generator
114 """
115 return self.streamed_request("list-certs", "list-cert", filters)
116
117 def load_conn(self, connection):
118 """Load a connection definition into the daemon.
119
120 :param connection: connection definition
121 :type connection: dict
122 """
123 self.request("load-conn", connection)
124
125 def unload_conn(self, name):
126 """Unload a connection definition.
127
128 :param name: connection definition name
129 :type name: dict
130 """
131 self.request("unload-conn", name)
132
133 def load_cert(self, certificate):
134 """Load a certificate into the daemon.
135
136 :param certificate: PEM or DER encoded certificate
137 :type certificate: dict
138 """
139 self.request("load-cert", certificate)
140
141 def load_key(self, private_key):
142 """Load a private key into the daemon.
143
144 :param private_key: PEM or DER encoded key
145 """
146 self.request("load-key", private_key)
147
148 def load_shared(self, secret):
149 """Load a shared IKE PSK, EAP or XAuth secret into the daemon.
150
151 :param secret: shared IKE PSK, EAP or XAuth secret
152 :type secret: dict
153 """
154 self.request("load-shared", secret)
155
156 def flush_certs(self, filter=None):
157 """Flush the volatile certificate cache.
158
159 Flush the certificate stored temporarily in the cache. The filter
160 allows to flush only a certain type of certificates, e.g. CRLs.
161
162 :param filter: flush only certificates of a given type (optional)
163 :type filter: dict
164 """
165 self.request("flush-certs", filter)
166
167 def clear_creds(self):
168 """Clear credentials loaded over vici.
169
170 Clear all loaded certificate, private key and shared key credentials.
171 This affects only credentials loaded over vici, but additionally
172 flushes the credential cache.
173 """
174 self.request("clear-creds")
175
176 def load_pool(self, pool):
177 """Load a virtual IP pool.
178
179 Load an in-memory virtual IP and configuration attribute pool.
180 Existing pools with the same name get updated, if possible.
181
182 :param pool: virtual IP and configuration attribute pool
183 :type pool: dict
184 """
185 return self.request("load-pool", pool)
186
187 def unload_pool(self, pool_name):
188 """Unload a virtual IP pool.
189
190 Unload a previously loaded virtual IP and configuration attribute pool.
191 Unloading fails for pools with leases currently online.
192
193 :param pool_name: pool by name
194 :type pool_name: dict
195 """
196 self.request("unload-pool", pool_name)
197
198 def get_pools(self, options):
199 """Retrieve loaded pools.
200
201 :param options: filter by name and/or retrieve leases (optional)
202 :type options: dict
203 :return: loaded pools
204 :rtype: dict
205 """
206 return self.request("get-pools", options)