-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsolusvm.py
940 lines (762 loc) · 24.6 KB
/
solusvm.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
"""
Python library for SolusVM's XMLRPC API
https://documentation.solusvm.com/display/DOCS/API
@author Benton Snyder
@website http://bensnyde.me
@email [email protected]
@created 7/24/13
@updated 5/21/16
"""
import requests
class SolusVM:
def __init__(self, base_url, api_id, api_key):
"""SolusVM JSON API Library constructor.
Parameters
base_url: SolusVM base_url
api_id: SolusVM API authentiction ID hash
api_key: SolusVM API authentication key hash
Returns
None
"""
self.base_url = base_url
self.id = api_id
self.key = api_key
def _sQuery(self, kwargs):
"""Queries specified SolusVM API with specified query string.
Parameters
kwargs: dictionary GET vars
Returns
json
"""
kwargs.update({
'rdtype':'json',
'id':self.id,
'key':self.key
})
response = requests.get('https://'+self.base_url+':5656/api/admin/command.php', params=kwargs, timeout=2)
return response.json()
def listVirtualServers(self, nodeid):
"""Lists virtual servers allocated on specified node.
https://documentation.solusvm.com/display/DOCS/List+Virtual+Servers
Parameters
nodeid: id of node
Returns
json
"""
return self._sQuery({
'action': 'node-virtualservers',
'nodeid': nodeid
})
def diablePXE(self, vserverid):
"""Disables PXE on specified virtual server.
https://documentation.solusvm.com/display/DOCS/Disable+PXE
Parameters
vserverid: id of virtual server
Returns
json
"""
return self._sQuery({
'action': 'vserver-network-disable',
'vserverid': vserverid
})
def enablePXE(self, vserverid):
"""Enables PXE on specified virtual server.
https://documentation.solusvm.com/display/DOCS/Enable+PXE
Parameters
vserverid: id of virtual server
Returns
json
"""
return self._sQuery({
'action': 'vserver-network-enable',
'vserverid': vserverid
})
def enableTUN(self, vserverid):
"""Enables TUN/TAP on specified virtual server.
https://documentation.solusvm.com/pages/viewpage.action?pageId=558498
Parameters
vserverid: id of virtual server
Returns
json
"""
return self._sQuery({
'action': 'vserver-tun-enable',
'vserverid': vserverid
})
def disableTUN(self, vserverid):
"""Disables TUN/TAP on specified virtual server.
https://documentation.solusvm.com/pages/viewpage.action?pageId=558494
Parameters
vserverid: id of virtual server
Returns
json
"""
return self._sQuery({
'action': 'vserver-tun-disable',
'vserverid': vserverid
})
def togglePAE(self, vserverid, pae):
"""Toggles PAE for specified virtual server.
https://documentation.solusvm.com/pages/viewpage.action?pageId=558505
Parameters
vserverid: id of virtual server
pae: on|off
Returns
json
"""
return self._sQuery({
'action': 'vserver-pae',
'vserverid': vserverid,
'pae':pae
})
def shutdownVirtualServer(self, vserverid):
"""Shuts down specified virtual server.
https://documentation.solusvm.com/display/DOCS/Shutdown+Virtual+Server
Parameters
vserverid: id of virtual server
Returns
json
"""
return self._sQuery({
'action': 'vserver-shutdown',
'vserverid': vserverid
})
def terminateVirtualServer(self, vserverid, deleteclient=False):
"""Deletes specified virtual server.
https://documentation.solusvm.com/display/DOCS/Terminate+Virtual+Server
Parameters
vserverid: id of virtual server
deleteclient: whether or not to delete client too
Returns
json
"""
return self._sQuery({
'action': 'vserver-terminate',
'vserverid': vserverid,
'deleteclient': deleteclient
})
def changeVNCPassword(self, vserverid, vncpassword):
"""Updates VNC password for specified virtual server.
https://documentation.solusvm.com/display/DOCS/Change+VNC+Password
Parameters
vserverid: id of virtual server
vncpassword: new password
Returns
json
"""
return self._sQuery({
'action': 'vserver-vncpass',
'vserverid': vserverid,
'vncpassword': vncpassword
})
def vncInfo(self, vserverid):
"""Retrieves VNC information for specified virtual server.
https://documentation.solusvm.com/display/DOCS/VNC+Info
Parameters
vserverid: id of virtual server
Returns
json
"""
return self._sQuery({
'action': 'vserver-vnc',
'vserverid': vserverid
})
def suspendVirtualServer(self, vserverid):
"""Suspends specified virtual server.
https://documentation.solusvm.com/display/DOCS/Suspend+Virtual+Server
Parameters
vserverid: id of virtual server
Returns
json
"""
return self._sQuery({
'action': 'vserver-suspend',
'vserverid':vserverid
})
def unsuspendVirtualServer(self, vserverid):
"""Unsuspends specified virtual server.
https://documentation.solusvm.com/display/DOCS/Unsuspend+Virtual+Server
Parameters
vserverid: id of virtual server
Returns
json
"""
return self._sQuery({
'action': 'vserver-unsuspend',
'vserverid': vserverid
})
def virtualServerStatus(self, vserverid):
"""Retrieves status of specified virtual server.
https://documentation.solusvm.com/display/DOCS/Virtual+Server+Status
Parameters
vserverid: id of virtual server
Returns
json
"""
return self._sQuery({
'action': 'vserver-status',
'vserverid': vserverid
})
def changeRootPassword(self, vserverid, rootpassword):
"""Retrieves status of specified virtual server.
https://documentation.solusvm.com/display/DOCS/Change+Root+Password
Parameters
vserverid: id of virtual server
rootpassword: new root password
Returns
json
"""
return self._sQuery({
'action': 'vserver-rootpassword',
'vserverid': vserverid,
'rootpassword': rootpassword
})
def rebuildVirtualServer(self, vserverid, template):
"""Rebuilds specified virtual server with specified template.
https://documentation.solusvm.com/display/DOCS/Rebuild+Virtual+Server
Parameters
vserverid: id of virtual server
template: template filename without extension
Returns
json
"""
return self._sQuery({
'action': 'vserver-rebuild',
'vserverid': vserverid,
'template': template
})
def changeHostname(self, vserverid, hostname):
"""Updates specified virtual server's hostname.
https://documentation.solusvm.com/display/DOCS/Change+Hostname
Parameters
vserverid: id of virtual server
hostname: new hostname
Returns
json
"""
return self._sQuery({
'action': 'vserver-hostname',
'vserverid': vserverid,
'hostname': hostname
})
def rebootVirtualServer(self, vserverid):
"""Reboots specified virtual server.
https://documentation.solusvm.com/display/DOCS/Reboot+Virtual+Server
Parameters
vserverid: id of virtual server
Returns
json
"""
return self._sQuery({
'action': 'vserver-reboot',
'vserverid': vserverid
})
def unmountISO(self, vserverid):
"""Unmounts ISO from specified virtual server.
https://documentation.solusvm.com/display/DOCS/Unmount+ISO
Parameters
vserverid: id of virtual server
Returns
json
"""
return self._sQuery({
'action': 'vserver-unmountiso',
'vserverid': vserverid
})
def mountISO(self, vserverid, iso):
"""Mounts specified ISO to specified virtual server.
https://documentation.solusvm.com/display/DOCS/Mount+ISO
Parameters
vserverid: id of virtual server
iso: filename of iso
Returns
json
"""
return self._sQuery({
'action': 'vserver-mountiso',
'vserverid': vserverid,
'iso': iso
})
def checkVirtualServerExists(self, vserverid):
"""Checks if specified virtual server exists.
https://documentation.solusvm.com/display/DOCS/Check+Exists
Parameters
vserverid: id of virtual server
Returns
json
"""
return self._sQuery({
'action': 'vserver-checkexists',
'vserverid': vserverid
})
def virtualServerState(self, vserverid, nostatus=False, nographs=False):
"""Retrieves information about specified virtual server.
https://documentation.solusvm.com/display/DOCS/Virtual+Server+State
Parameters
vserverid: id of virtual server
nostatus: whether or not to retrieve status
nographs: whether or not to generate graphs
Returns
json
"""
return self._sQuery({
'action': 'vserver-infoall',
'vserverid': vserverid,
'nostatus': nostatus,
'nographs': nographs
})
def virtualServerInfo(self, vserverid):
"""Retrieves information about specified virtual server.
https://documentation.solusvm.com/display/DOCS/Virtual+Server+Information
Parameters
vserverid: id of virtual server
Returns
json
"""
return self._sQuery({
'action': 'vserver-info',
'vserverid': vserverid
})
def deleteIPAddress(self, vserverid, ipaddr):
"""Removes specified IP Address from specified virtual server.
https://documentation.solusvm.com/display/DOCS/Delete+IP+Address
Parameters
vserverid: id of virtual server
ipaddr: ip address
Returns
json
"""
return self._sQuery({
'action': 'vserver-delip',
'vserverid': vserverid,
'ipaddr': ipaddr
})
def toggleSerialConsole(self, vserverid, access=None, time=None):
"""Retrieves, enables or disables serial console for specified virtual server.
https://documentation.solusvm.com/display/DOCS/Serial+Console
Parameters
vserverid: id of virtual server
access: enable|disable
time: 1|2|3|4|5|6|7|8
Returns
json
"""
return self._sQuery({
'action': 'vserver-console',
'vserverid': vserverid,
'time': time,
'access': access
})
def changePlan(self, vserverid, plan):
"""Changes specified virtual server's plan.
https://documentation.solusvm.com/display/DOCS/Change+Plan
Parameters
vserverid: id of virtual server
plan: new plan name
Returns
json
"""
return self._sQuery({
'action': 'vserver-change',
'vserverid': vserverid,
'plan':plan
})
def changeOwner(self, vserverid, clientid):
"""Changes specified virtual server's owner.
https://documentation.solusvm.com/display/DOCS/Change+Owner
Parameters
vserverid: id of virtual server
clientid: new clients id
Returns
json
"""
return self._sQuery({
'action': 'vserver-changeowner',
'vserverid': vserverid,
'clientid': clientid
})
def changeBootOrder(self, vserverid, bootorder):
"""Changes specified virtual server's boot order.
https://documentation.solusvm.com/display/DOCS/Change+Boot+Order
Parameters
vserverid: id of virtual server
bootorder: cd|dc|c|d (c=CDROM, d=HDD)
Returns
json
"""
return self._sQuery({
'action': 'vserver-bootorder',
'vserverid': vserverid,
'bootorder': bootorder
})
def changeBandwidthLimits(self, vserverid, limit, overlimit):
"""Changes specified virtual server's bandwidth limits.
https://documentation.solusvm.com/display/DOCS/Change+Bandwidth+Limits
Parameters
vserverid: id of virtual server
limit: bandwidth limit in Gb
overlimit: bandwidth overlimit in Gb
Returns
json
"""
return self._sQuery({
'action': 'vserver-bandwidth',
'vserverid': vserverid,
'limit': limit,
'overlimit': overlimit
})
def changeMemory(self, vserverid, memory):
"""Changes specified virtual server's allocated memory.
https://documentation.solusvm.com/display/DOCS/Change+Memory
Parameters
vserverid: id of virtual server
memory: amount in Mb
Returns
json
"""
return self._sQuery({
'action': 'vserver-change-memory',
'vserverid': vserverid,
'memory': memory
})
def changeCPU(self, vserverid, cpu):
"""Changes specified virtual server's number of CPU cores.
https://documentation.solusvm.com/display/DOCS/Change+CPU
Parameters
vserverid: id of virtual server
cpu: number of cpu cores [1-128]
Returns
json
"""
return self._sQuery({
'action': 'vserver-change-cpu',
'vserverid': vserverid,
'cpu': cpu,
})
def changeHDD(self, vserverid, hdd):
"""Changes specified virtual server's hard disk size.
https://documentation.solusvm.com/display/DOCS/Change+Hard+Disk+Size
Parameters
vserverid: id of virtual server
hdd: hard disk size in Gb
Returns
json
"""
return self._sQuery({
'action': 'vserver-change-hdd',
'vserverid': vserverid,
'hdd': hdd,
})
def addIPAddress(self, vserverid):
"""Adds an IP address to specified virtual server.
https://documentation.solusvm.com/display/DOCS/Add+IP+Address
Parameters
vserverid: id of virtual server
Returns
json
"""
return self._sQuery({
'action': 'vserver-addip',
'vserverid': vserverid
})
def bootVirtualServer(self, vserverid):
"""Boots specified virtual server.
https://documentation.solusvm.com/display/DOCS/Boot+Virtual+Server
Parameters
vserverid: id of virtual server
Returns
json
"""
return self._sQuery({
'action': 'vserver-boot',
'vserverid': vserverid
})
def createVirtualServer(self, kwargs):
"""Creates virtual server.
https://documentation.solusvm.com/display/DOCS/Create+Virtual+Server
Parameters
data: dictionary parameter pairs
Returns
json
"""
kwargs['action'] = 'vserver-create'
return self._sQuery(kwargs)
def listNodesById(self, vtype='kvm'):
"""Lists Nodes by their ID.
https://documentation.solusvm.com/display/DOCS/List+Nodes+by+ID
Parameters
vtype: openvz|xen|xen hvm|kvm
Returns
json
"""
return self._sQuery({
'action': 'node-idlist',
'type': vtype
})
def listNodesByName(self, vtype='kvm'):
"""List nodes by name.
https://documentation.solusvm.com/display/DOCS/List+Nodes+by+Name
Parameters
vtype: openvz|xen|xen hvm|kvm
Returns
json
"""
return self._sQuery({
'action': 'listnodes',
'type': vtype
})
def listISO(self, vtype='kvm'):
"""Lists available ISO images.
https://documentation.solusvm.com/display/DOCS/List+ISO+Images
Parameters
vtype: xen hvm|kvm
Returns
json
"""
return self._sQuery({
'action': 'listiso',
'type': vtype
})
def listNodeGroups(self, vtype='kvm'):
"""List node groups.
https://documentation.solusvm.com/display/DOCS/List+Node+Groups
Parameters
vtype: xen hvm|kvm
Returns
json
"""
return self._sQuery({
'action': 'listnodegroups',
'type': vtype
})
def listNodesIPAddresses(self, nodeid):
"""List all IP addresses for a node.
https://documentation.solusvm.com/display/DOCS/List+All+IP+Addresses+for+a+Node
Parameters
nodeid: id of node
Returns
json
"""
return self._sQuery({
'action': 'node-iplist',
'nodeid': nodeid
})
def listPlans(self, vtype='kvm'):
"""List plans.
https://documentation.solusvm.com/display/DOCS/List+Plans
Parameters
vtype: openvz|xen|xen hvm|kvm
Returns
json
"""
return self._sQuery({
'action': 'listplans',
'type': vtype
})
def listTemplates(self, vtype='kvm'):
"""List templates.
https://documentation.solusvm.com/display/DOCS/List+Templates
Parameters
vtype: openvz|xen|xen hvm|kvm
Returns
json
"""
return self._sQuery({
'action': 'listtemplates',
'type': vtype
})
def xenNodeResources(self, nodeid):
"""Retrieve resource count from specified xen node.
https://documentation.solusvm.com/display/DOCS/Xen+Node+Resources
Parameters
nodeid: id of node
Returns
json
"""
return self._sQuery({
'action': 'node-xenresources',
'nodeid': nodeid
})
def nodeStatistics(self, nodeid):
"""Retrieve statistics for specified node.
https://documentation.solusvm.com/display/DOCS/Node+Statistics
Parameters
nodeid: id of node
Returns
json
"""
return self._sQuery({
'action': 'node-statistics',
'nodeid': nodeid
})
def clientAuthenticate(self, username, password):
"""Authenticates specified username and password.
https://documentation.solusvm.com/display/DOCS/Client+Authenticate
Parameters
username:
password:
Returns
json
"""
return self._sQuery({
'action': 'client-authenticate',
'username': username,
'password': password
})
def clientExists(self, username):
"""Checks to see if the specified client exists.
https://documentation.solusvm.com/display/DOCS/Check+if+Client+Exists
Parameters
username:
Returns
json
"""
return self._sQuery({
'action': 'client-checkexists',
'username': username
})
def createClient(self, username, password, email, firstname, lastname, company):
"""Creates a client.
https://documentation.solusvm.com/pages/viewpage.action?pageId=558430
Parameters
username:
password:
email:
firstname:
lastname:
company:
Returns
json
"""
return self._sQuery({
'action': 'client-create',
'username': username,
'password': password,
'email': email,
'firstname': firstname,
'lastname': lastname,
'company': company
})
def changeClientPassword(self, username, password):
"""Updates the specified client's password.
https://documentation.solusvm.com/display/DOCS/Change+Client+Password
Parameters
username:
password:
Returns
json
"""
return self._sQuery({
'action': 'client-updatepassword',
'username': username,
'password': password
})
def changeClientUsername(self, username, newusername):
"""Updates the specified client's password.
https://documentation.solusvm.com/display/DOCS/Change+Client+Username
Parameters
username: old username
newusername: new username
Returns
json
"""
return self._sQuery({
'action': 'client-change-username',
'username': username,
'newusername': newusername
})
def listClients(self):
"""Lists all clients.
https://documentation.solusvm.com/display/DOCS/List+Clients
Parameters
None
Returns
json
"""
return self._sQuery({
'action':'client-list'
})
def deleteClient(self, username):
"""Deletes specified client.
https://documentation.solusvm.com/display/DOCS/Delete+Client
Parameters
username:
Returns
json
"""
return self._sQuery({
'action': 'client-delete',
'username': username
})
def editClient(self, username, kwargs):
"""Edits specified client.
https://documentation.solusvm.com/display/DOCS/Edit+Client
Parameters
username:
*firsntame
*lastname
*company
*email
Returns
json
"""
kwargs['action'] = 'client-edit'
kwargs['username'] = username
return self._sQuery(kwargs)
def deleteReseller(self, username):
"""Deletes specified reseller.
https://documentation.solusvm.com/display/DOCS/Delete+Reseller
Parameters
username:
Returns
json
"""
return self._sQuery({
'action': 'reseller-delete',
'username': username
})
def resellerInfo(self, username):
"""Retrieves details of specified reseller.
https://documentation.solusvm.com/display/DOCS/Reseller+Information
Parameters
username:
Returns
json
"""
return self._sQuery({
'action': 'reseller-info',
'username': username
})
def listResellers(self):
"""Lists all resellers.
https://documentation.solusvm.com/display/DOCS/List+Resellers
Parameters
None
Returns
json
"""
return self._sQuery({
'action':'reseller-list'
})
def createReseller(self, kwargs):
"""Creates reseller.
https://documentation.solusvm.com/display/DOCS/Create+Reseller
Parameters
data: dictionary key/value pairs
Returns
json
"""
kwargs['action'] = 'reseller-create'
return self._sQuery(kwargs)
def modifyResellerResources(self, username, kwargs):
"""Modifies reseller's available resources.
https://documentation.solusvm.com/display/DOCS/Modify+Reseller+Resources
Parameters
username:
data: dictionary key/value pairs
Returns
json
"""
kwargs['action'] = 'reseller-modifyresources'
kwargs['username'] = username
return self._sQuery(kwargs)