-
Notifications
You must be signed in to change notification settings - Fork 17
/
lxd.py
3625 lines (2704 loc) · 94.1 KB
/
lxd.py
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
'''
Module for managing the LXD daemon and its containers.
.. versionadded:: Fluorine
`LXD(1)`__ is a container "hypervisor". This execution module provides
several functions to help manage it and its containers.
.. note:
- `pylxd(2)`__ version >=2.2.5 is required to let this work,
currently only available via pip.
To install on Ubuntu:
$ apt-get install libssl-dev python-pip
$ pip install -U pylxd
- you need lxd installed on the minion
for the init() and version() methods.
- for the config_get() and config_get() methods
you need to have lxd-client installed.
.. __: https://linuxcontainers.org/lxd/
.. __: https://github.com/lxc/pylxd/blob/master/doc/source/installation.rst
:maintainer: René Jochum <[email protected]>
:maturity: new
:depends: python-pylxd
:platform: Linux
'''
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
import os
from datetime import datetime
# Import salt libs
try:
import salt.utils.decorators.path
except ImportError:
# Dirty monkey patch salt.utils.decorators to have
# the relocated 'salt.utils.decorators.which' decorator
# available as 'salt.utils.decorators.path.which'
import salt.utils.decorators
salt.utils.decorators.path = salt.utils.decorators
import salt.utils.files
from salt.utils.versions import LooseVersion
from salt.exceptions import CommandExecutionError
from salt.exceptions import SaltInvocationError
import salt.ext.six as six
from salt.ext.six.moves import map
from salt.ext.six.moves import zip
# Import 3rd-party libs
try:
import pylxd
PYLXD_AVAILABLE = True
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
except ImportError:
PYLXD_AVAILABLE = False
# Set up logging
import logging
log = logging.getLogger(__name__)
__docformat__ = 'restructuredtext en'
_pylxd_minimal_version = "2.2.5"
# Keep in sync with: https://github.com/lxc/lxd/blob/master/shared/osarch/architectures.go # noqa
_architectures = {
'unknown': '0',
'i686': '1',
'x86_64': '2',
'armv7l': '3',
'aarch64': '4',
'ppc': '5',
'ppc64': '6',
'ppc64le': '7',
's390x': '8'
}
# Keep in sync with: https://github.com/lxc/lxd/blob/master/shared/api/status_code.go # noqa
CONTAINER_STATUS_RUNNING = 103
__virtualname__ = 'lxd'
_connection_pool = {}
def __virtual__():
if PYLXD_AVAILABLE:
if (LooseVersion(pylxd_version()) <
LooseVersion(_pylxd_minimal_version)):
return (
False,
('The lxd execution module cannot be loaded:'
' pylxd "{0}" is not supported,'
' you need at least pylxd "{1}"').format(
pylxd_version(),
_pylxd_minimal_version)
)
return __virtualname__
return (
False,
('The lxd execution module cannot be loaded: '
'the pylxd python module is not available.')
)
################
# LXD Management
################
@salt.utils.decorators.path.which('lxd')
def version():
'''
Returns the actual lxd version.
CLI Example:
.. code-block:: bash
salt '*' lxd.version
'''
return __salt__['cmd.run']('lxd --version')
def pylxd_version():
'''
Returns the actual pylxd version.
CLI Example:
.. code-block:: bash
salt '*' lxd.pylxd_version
'''
return pylxd.__version__
@salt.utils.decorators.path.which('lxd')
def init(storage_backend='dir', trust_password=None, network_address=None,
network_port=None, storage_create_device=None,
storage_create_loop=None, storage_pool=None):
'''
Calls lxd init --auto -- opts
storage_backend :
Storage backend to use (zfs or dir, default: dir)
trust_password :
Password required to add new clients
network_address : None
Address to bind LXD to (default: none)
network_port : None
Port to bind LXD to (Default: 8443)
storage_create_device : None
Setup device based storage using this DEVICE
storage_create_loop : None
Setup loop based storage with this SIZE in GB
storage_pool : None
Storage pool to use or create
CLI Examples:
To listen on all IPv4/IPv6 Addresses:
.. code-block:: bash
salt '*' lxd.init dir PaSsW0rD [::]
To not listen on Network:
.. code-block:: bash
salt '*' lxd.init
'''
cmd = ('lxd init --auto'
' --storage-backend="{0}"').format(
storage_backend
)
if trust_password is not None:
cmd = cmd + ' --trust-password="{0}"'.format(trust_password)
if network_address is not None:
cmd = cmd + ' --network-address="{0}"'.format(network_address)
if network_port is not None:
cmd = cmd + ' --network-port="{0}"'.format(network_port)
if storage_create_device is not None:
cmd = cmd + ' --storage-create-device="{0}"'.format(
storage_create_device
)
if storage_create_loop is not None:
cmd = cmd + ' --storage-create-loop="{0}"'.format(
storage_create_loop
)
if storage_pool is not None:
cmd = cmd + ' --storage-pool="{0}"'.format(storage_pool)
try:
output = __salt__['cmd.run'](cmd)
except ValueError as e:
raise CommandExecutionError(
"Failed to call: '{0}', error was: {1}".format(
cmd, six.text_type(e)
),
)
if 'error:' in output:
raise CommandExecutionError(
output[output.index('error:') + 7:],
)
return output
@salt.utils.decorators.path.which('lxd')
@salt.utils.decorators.path.which('lxc')
def config_set(key, value):
'''
Set an LXD daemon config option
CLI Examples:
To listen on IPv4 and IPv6 port 8443,
you can omit the :8443 its the default:
.. code-block:: bash
salt '*' lxd.config_set core.https_address [::]:8443
To set the server trust password:
.. code-block:: bash
salt '*' lxd.config_set core.trust_password blah
'''
cmd = 'lxc config set "{0}" "{1}"'.format(
key,
value,
)
output = __salt__['cmd.run'](cmd)
if 'error:' in output:
raise CommandExecutionError(
output[output.index('error:') + 7:],
)
return 'Config value "{0}" successfully set.'.format(key),
@salt.utils.decorators.path.which('lxd')
@salt.utils.decorators.path.which('lxc')
def config_get(key):
'''
Get an LXD daemon config option
key :
The key of the config value to retrieve
CLI Examples:
.. code-block:: bash
salt '*' lxd.config_get core.https_address
'''
cmd = 'lxc config get "{0}"'.format(
key
)
output = __salt__['cmd.run'](cmd)
if 'error:' in output:
raise CommandExecutionError(
output[output.index('error:') + 7:],
)
return output
#######################
# Connection Management
#######################
def pylxd_client_get(remote_addr=None, cert=None, key=None, verify_cert=True):
'''
Get an pyxld client, this is not ment to be runned over the CLI.
remote_addr :
An URL to a remote Server, you also have to give cert and key if you
provide remote_addr and its a TCP Address!
Examples:
https://myserver.lan:8443
/var/lib/mysocket.sock
cert :
PEM Formatted SSL Certificate.
Examples:
~/.config/lxc/client.crt
key :
PEM Formatted SSL Key.
Examples:
~/.config/lxc/client.key
verify_cert : True
Wherever to verify the cert, this is by default True
but in the most cases you want to set it off as LXD
normaly uses self-signed certificates.
See the `requests-docs`_ for the SSL stuff.
.. _requests-docs: http://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification
# noqa
'''
pool_key = '|'.join((six.text_type(remote_addr),
six.text_type(cert),
six.text_type(key),
six.text_type(verify_cert),))
if pool_key in _connection_pool:
log.debug((
'Returning the client "{0}" from our connection pool'
).format(remote_addr))
return _connection_pool[pool_key]
try:
if remote_addr is None or remote_addr == '/var/lib/lxd/unix.socket':
log.debug('Trying to connect to the local unix socket')
client = pylxd.Client()
else:
if remote_addr.startswith('/'):
client = pylxd.Client(remote_addr)
else:
if cert is None or key is None:
raise SaltInvocationError(
('You have to give a Cert and '
'Key file for remote endpoints.')
)
cert = os.path.expanduser(cert)
key = os.path.expanduser(key)
if not os.path.isfile(cert):
raise SaltInvocationError(
('You have given an invalid cert path: "{0}", '
'the file does not exists or is not a file.').format(
cert
)
)
if not os.path.isfile(key):
raise SaltInvocationError(
('You have given an invalid key path: "{0}", '
'the file does not exists or is not a file.').format(
key
)
)
log.debug((
'Trying to connecto to "{0}" '
'with cert "{1}", key "{2}" and '
'verify_cert "{3!s}"'.format(
remote_addr, cert, key, verify_cert)
))
client = pylxd.Client(
endpoint=remote_addr,
cert=(cert, key,),
verify=verify_cert
)
except pylxd.exceptions.ClientConnectionFailed:
raise CommandExecutionError(
"Failed to connect to '{0}'".format(remote_addr)
)
except TypeError as e:
# Happens when the verification failed.
raise CommandExecutionError(
('Failed to connect to "{0}",'
' looks like the SSL verification failed, error was: {1}'
).format(remote_addr, six.text_type(e))
)
_connection_pool[pool_key] = client
return client
def pylxd_save_object(obj):
''' Saves an object (profile/image/container) and
translate its execpetion on failure
obj :
The object to save
This is an internal method, no CLI Example.
'''
try:
obj.save()
except pylxd.exceptions.LXDAPIException as e:
raise CommandExecutionError(six.text_type(e))
return True
def authenticate(remote_addr, password, cert, key, verify_cert=True):
'''
Authenticate with a remote LXDaemon.
remote_addr :
An URL to a remote Server, you also have to give cert and key if you
provide remote_addr and its a TCP Address!
Examples:
https://myserver.lan:8443
password :
The password of the remote.
cert :
PEM Formatted SSL Certificate.
Examples:
~/.config/lxc/client.crt
key :
PEM Formatted SSL Key.
Examples:
~/.config/lxc/client.key
verify_cert : True
Wherever to verify the cert, this is by default True
but in the most cases you want to set it off as LXD
normaly uses self-signed certificates.
CLI Example:
.. code-block:: bash
$ salt '*' lxd.authenticate https://srv01:8443 <yourpass> ~/.config/lxc/client.crt ~/.config/lxc/client.key false
See the `requests-docs`_ for the SSL stuff.
.. _requests-docs: http://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification
# noqa
'''
client = pylxd_client_get(remote_addr, cert, key, verify_cert)
if client.trusted:
return True
try:
client.authenticate(password)
except pylxd.exceptions.LXDAPIException as e:
# Wrong password
raise CommandExecutionError(six.text_type(e))
return client.trusted
######################
# Container Management
######################
def container_list(list_names=False, remote_addr=None,
cert=None, key=None, verify_cert=True):
'''
Lists containers
list_names : False
Only return a list of names when True
remote_addr :
An URL to a remote Server, you also have to give cert and key if
you provide remote_addr and its a TCP Address!
Examples:
https://myserver.lan:8443
/var/lib/mysocket.sock
cert :
PEM Formatted SSL Certificate.
Examples:
~/.config/lxc/client.crt
key :
PEM Formatted SSL Key.
Examples:
~/.config/lxc/client.key
verify_cert : True
Wherever to verify the cert, this is by default True
but in the most cases you want to set it off as LXD
normaly uses self-signed certificates.
CLI Examples:
Full dict with all available informations:
.. code-block:: bash
salt '*' lxd.container_list
For a list of names:
.. code-block:: bash
salt '*' lxd.container_list true
# See: https://github.com/lxc/pylxd/blob/master/doc/source/containers.rst#container-attributes
# noqa
'''
client = pylxd_client_get(remote_addr, cert, key, verify_cert)
containers = client.containers.all()
if list_names:
return [c.name for c in containers]
return map(_pylxd_model_to_dict, containers)
def container_create(name, source, profiles=None,
config=None, devices=None, architecture='x86_64',
ephemeral=False, wait=True,
remote_addr=None, cert=None, key=None, verify_cert=True,
_raw=False):
'''
Create a container
name :
The name of the container
source :
Can be either a string containing an image alias:
"xenial/amd64"
or an dict with type "image" with alias:
{"type": "image",
"alias": "xenial/amd64"}
or image with "fingerprint":
{"type": "image",
"fingerprint": "SHA-256"}
or image with "properties":
{"type": "image",
"properties": {
"os": "ubuntu",
"release": "14.04",
"architecture": "x86_64"
}}
or none:
{"type": "none"}
or copy:
{"type": "copy",
"source": "my-old-container"}
profiles : ['default']
List of profiles to apply on this container
config :
A config dict or None (None = unset).
Can also be a list:
[{'key': 'boot.autostart', 'value': 1},
{'key': 'security.privileged', 'value': '1'}]
devices :
A device dict or None (None = unset).
architecture : 'x86_64'
Can be one of the following:
* unknown
* i686
* x86_64
* armv7l
* aarch64
* ppc
* ppc64
* ppc64le
* s390x
ephemeral : False
Destroy this container after stop?
remote_addr :
An URL to a remote Server, you also have to give cert and key if
you provide remote_addr and its a TCP Address!
Examples:
https://myserver.lan:8443
/var/lib/mysocket.sock
cert :
PEM Formatted SSL Certificate.
Examples:
~/.config/lxc/client.crt
key :
PEM Formatted SSL Key.
Examples:
~/.config/lxc/client.key
verify_cert : True
Wherever to verify the cert, this is by default True
but in the most cases you want to set it off as LXD
normaly uses self-signed certificates.
_raw : False
Return the raw pyxld object or a dict?
CLI Examples:
.. code-block:: bash
salt '*' lxd.container_create test xenial/amd64
# See: https://github.com/lxc/lxd/blob/master/doc/rest-api.md#post-1
'''
if profiles is None:
profiles = ['default']
if config is None:
config = {}
if devices is None:
devices = {}
client = pylxd_client_get(remote_addr, cert, key, verify_cert)
if not isinstance(profiles, (list, tuple, set,)):
raise SaltInvocationError(
"'profiles' must be formatted as list/tuple/set."
)
if architecture not in _architectures:
raise SaltInvocationError(
("Unknown architecture '{0}' "
"given for the container '{1}'").format(architecture, name)
)
if isinstance(source, six.string_types):
source = {'type': 'image', 'alias': source}
config, devices = normalize_input_values(
config,
devices
)
try:
container = client.containers.create(
{
'name': name,
'architecture': _architectures[architecture],
'profiles': profiles,
'source': source,
'config': config,
'ephemeral': ephemeral
},
wait=wait
)
except pylxd.exceptions.LXDAPIException as e:
raise CommandExecutionError(
six.text_type(e)
)
if not wait:
return container.json()['operation']
# Add devices if not wait and devices have been given.
if devices:
for dn, dargs in six.iteritems(devices):
container_device_add(name, dn, **dargs)
if _raw:
return container
return _pylxd_model_to_dict(container)
def container_get(name=None, remote_addr=None,
cert=None, key=None, verify_cert=True, _raw=False):
''' Gets a container from the LXD
name :
The name of the container to get.
remote_addr :
An URL to a remote Server, you also have to give cert and key if
you provide remote_addr and its a TCP Address!
Examples:
https://myserver.lan:8443
/var/lib/mysocket.sock
cert :
PEM Formatted SSL Certificate.
Examples:
~/.config/lxc/client.crt
key :
PEM Formatted SSL Key.
Examples:
~/.config/lxc/client.key
verify_cert : True
Wherever to verify the cert, this is by default True
but in the most cases you want to set it off as LXD
normaly uses self-signed certificates.
_raw :
Return the pylxd object, this is internal and by states in use.
'''
client = pylxd_client_get(remote_addr, cert, key, verify_cert)
if name is None:
containers = client.containers.all()
if _raw:
return containers
else:
containers = []
try:
containers = [client.containers.get(name)]
except pylxd.exceptions.LXDAPIException:
raise SaltInvocationError(
'Container \'{0}\' not found'.format(name)
)
if _raw:
return containers[0]
infos = []
for container in containers:
infos.append(dict([
(container.name, _pylxd_model_to_dict(container))
]))
return infos
def container_delete(name, remote_addr=None,
cert=None, key=None, verify_cert=True):
'''
Delete a container
name :
Name of the container to delete
remote_addr :
An URL to a remote Server, you also have to give cert and key if
you provide remote_addr and its a TCP Address!
Examples:
https://myserver.lan:8443
/var/lib/mysocket.sock
cert :
PEM Formatted SSL Certificate.
Examples:
~/.config/lxc/client.crt
key :
PEM Formatted SSL Key.
Examples:
~/.config/lxc/client.key
verify_cert : True
Wherever to verify the cert, this is by default True
but in the most cases you want to set it off as LXD
normaly uses self-signed certificates.
'''
container = container_get(
name, remote_addr, cert, key, verify_cert, _raw=True
)
container.delete(wait=True)
return True
def container_rename(name, newname, remote_addr=None,
cert=None, key=None, verify_cert=True):
'''
Rename a container
name :
Name of the container to Rename
newname :
The new name of the contianer
remote_addr :
An URL to a remote Server, you also have to give cert and key if
you provide remote_addr and its a TCP Address!
Examples:
https://myserver.lan:8443
/var/lib/mysocket.sock
cert :
PEM Formatted SSL Certificate.
Examples:
~/.config/lxc/client.crt
key :
PEM Formatted SSL Key.
Examples:
~/.config/lxc/client.key
verify_cert : True
Wherever to verify the cert, this is by default True
but in the most cases you want to set it off as LXD
normaly uses self-signed certificates.
'''
container = container_get(
name, remote_addr, cert, key, verify_cert, _raw=True
)
if container.status_code == CONTAINER_STATUS_RUNNING:
raise SaltInvocationError(
"Can't rename the running container '{0}'.".format(name)
)
container.rename(newname, wait=True)
return _pylxd_model_to_dict(container)
def container_state(name=None, remote_addr=None,
cert=None, key=None, verify_cert=True):
'''
Get container state
remote_addr :
An URL to a remote Server, you also have to give cert and key if
you provide remote_addr and its a TCP Address!
Examples:
https://myserver.lan:8443
/var/lib/mysocket.sock
cert :
PEM Formatted SSL Certificate.
Examples:
~/.config/lxc/client.crt
key :
PEM Formatted SSL Key.
Examples:
~/.config/lxc/client.key
verify_cert : True
Wherever to verify the cert, this is by default True
but in the most cases you want to set it off as LXD
normaly uses self-signed certificates.
'''
client = pylxd_client_get(remote_addr, cert, key, verify_cert)
if name is None:
containers = client.containers.all()
else:
try:
containers = [client.containers.get(name)]
except pylxd.exceptions.LXDAPIException:
raise SaltInvocationError(
'Container \'{0}\' not found'.format(name)
)
states = []
for container in containers:
state = {}
state = container.state()
states.append(dict([
(
container.name,
dict([
(k, getattr(state, k))
for k in dir(state)
if not k.startswith('_')
])
)
]))
return states
def container_start(name, remote_addr=None,
cert=None, key=None, verify_cert=True):
'''
Start a container
name :
Name of the container to start
remote_addr :
An URL to a remote Server, you also have to give cert and key if
you provide remote_addr and its a TCP Address!
Examples:
https://myserver.lan:8443
/var/lib/mysocket.sock
cert :
PEM Formatted SSL Certificate.
Examples:
~/.config/lxc/client.crt
key :
PEM Formatted SSL Key.
Examples:
~/.config/lxc/client.key
verify_cert : True
Wherever to verify the cert, this is by default True
but in the most cases you want to set it off as LXD
normaly uses self-signed certificates.
'''
container = container_get(
name, remote_addr, cert, key, verify_cert, _raw=True
)
container.start(wait=True)
return _pylxd_model_to_dict(container)
def container_stop(name, timeout=30, force=True, remote_addr=None,
cert=None, key=None, verify_cert=True):
'''
Stop a container
name :
Name of the container to stop
remote_addr :
An URL to a remote Server, you also have to give cert and key if
you provide remote_addr and its a TCP Address!
Examples:
https://myserver.lan:8443
/var/lib/mysocket.sock
cert :
PEM Formatted SSL Certificate.
Examples:
~/.config/lxc/client.crt
key :
PEM Formatted SSL Key.
Examples:
~/.config/lxc/client.key
verify_cert : True
Wherever to verify the cert, this is by default True
but in the most cases you want to set it off as LXD
normaly uses self-signed certificates.
'''
container = container_get(
name, remote_addr, cert, key, verify_cert, _raw=True
)
container.stop(timeout, force, wait=True)
return _pylxd_model_to_dict(container)
def container_restart(name, remote_addr=None,
cert=None, key=None, verify_cert=True):
'''