Revision a198b2d9
b/lib/rapi/client.py | ||
---|---|---|
32 | 32 |
|
33 | 33 |
|
34 | 34 |
GANETI_RAPI_PORT = 5080 |
35 |
GANETI_RAPI_VERSION = 2 |
|
35 | 36 |
|
36 | 37 |
HTTP_DELETE = "DELETE" |
37 | 38 |
HTTP_GET = "GET" |
... | ... | |
444 | 445 |
@return: operating systems |
445 | 446 |
|
446 | 447 |
""" |
447 |
return self._SendRequest(HTTP_GET, "/2/os", None, None) |
|
448 |
return self._SendRequest(HTTP_GET, "/%s/os" % GANETI_RAPI_VERSION, |
|
449 |
None, None) |
|
448 | 450 |
|
449 | 451 |
def GetInfo(self): |
450 | 452 |
"""Gets info about the cluster. |
... | ... | |
453 | 455 |
@return: information about the cluster |
454 | 456 |
|
455 | 457 |
""" |
456 |
return self._SendRequest(HTTP_GET, "/2/info", None, None) |
|
458 |
return self._SendRequest(HTTP_GET, "/%s/info" % GANETI_RAPI_VERSION, |
|
459 |
None, None) |
|
457 | 460 |
|
458 | 461 |
def GetClusterTags(self): |
459 | 462 |
"""Gets the cluster tags. |
... | ... | |
462 | 465 |
@return: cluster tags |
463 | 466 |
|
464 | 467 |
""" |
465 |
return self._SendRequest(HTTP_GET, "/2/tags", None, None) |
|
468 |
return self._SendRequest(HTTP_GET, "/%s/tags" % GANETI_RAPI_VERSION, |
|
469 |
None, None) |
|
466 | 470 |
|
467 | 471 |
def AddClusterTags(self, tags, dry_run=False): |
468 | 472 |
"""Adds tags to the cluster. |
... | ... | |
480 | 484 |
if dry_run: |
481 | 485 |
query.append(("dry-run", 1)) |
482 | 486 |
|
483 |
return self._SendRequest(HTTP_PUT, "/2/tags", query, None) |
|
487 |
return self._SendRequest(HTTP_PUT, "/%s/tags" % GANETI_RAPI_VERSION, |
|
488 |
query, None) |
|
484 | 489 |
|
485 | 490 |
def DeleteClusterTags(self, tags, dry_run=False): |
486 | 491 |
"""Deletes tags from the cluster. |
... | ... | |
495 | 500 |
if dry_run: |
496 | 501 |
query.append(("dry-run", 1)) |
497 | 502 |
|
498 |
return self._SendRequest(HTTP_DELETE, "/2/tags", query, None) |
|
503 |
return self._SendRequest(HTTP_DELETE, "/%s/tags" % GANETI_RAPI_VERSION, |
|
504 |
query, None) |
|
499 | 505 |
|
500 | 506 |
def GetInstances(self, bulk=False): |
501 | 507 |
"""Gets information about instances on the cluster. |
... | ... | |
511 | 517 |
if bulk: |
512 | 518 |
query.append(("bulk", 1)) |
513 | 519 |
|
514 |
instances = self._SendRequest(HTTP_GET, "/2/instances", query, None) |
|
520 |
instances = self._SendRequest(HTTP_GET, |
|
521 |
"/%s/instances" % GANETI_RAPI_VERSION, |
|
522 |
query, None) |
|
515 | 523 |
if bulk: |
516 | 524 |
return instances |
517 | 525 |
else: |
... | ... | |
527 | 535 |
@return: info about the instance |
528 | 536 |
|
529 | 537 |
""" |
530 |
return self._SendRequest(HTTP_GET, "/2/instances/%s" % instance, None, None) |
|
538 |
return self._SendRequest(HTTP_GET, |
|
539 |
("/%s/instances/%s" % |
|
540 |
(GANETI_RAPI_VERSION, instance)), None, None) |
|
531 | 541 |
|
532 | 542 |
def CreateInstance(self, dry_run=False): |
533 | 543 |
"""Creates a new instance. |
... | ... | |
544 | 554 |
if dry_run: |
545 | 555 |
query.append(("dry-run", 1)) |
546 | 556 |
|
547 |
return self._SendRequest(HTTP_POST, "/2/instances", query, None) |
|
557 |
return self._SendRequest(HTTP_POST, "/%s/instances" % GANETI_RAPI_VERSION, |
|
558 |
query, None) |
|
548 | 559 |
|
549 | 560 |
def DeleteInstance(self, instance, dry_run=False): |
550 | 561 |
"""Deletes an instance. |
... | ... | |
560 | 571 |
if dry_run: |
561 | 572 |
query.append(("dry-run", 1)) |
562 | 573 |
|
563 |
return self._SendRequest(HTTP_DELETE, "/2/instances/%s" % instance, |
|
564 |
query, None) |
|
574 |
return self._SendRequest(HTTP_DELETE, |
|
575 |
("/%s/instances/%s" % |
|
576 |
(GANETI_RAPI_VERSION, instance)), query, None) |
|
565 | 577 |
|
566 | 578 |
def GetInstanceTags(self, instance): |
567 | 579 |
"""Gets tags for an instance. |
... | ... | |
573 | 585 |
@return: tags for the instance |
574 | 586 |
|
575 | 587 |
""" |
576 |
return self._SendRequest(HTTP_GET, "/2/instances/%s/tags" % instance, |
|
577 |
None, None) |
|
588 |
return self._SendRequest(HTTP_GET, |
|
589 |
("/%s/instances/%s/tags" % |
|
590 |
(GANETI_RAPI_VERSION, instance)), None, None) |
|
578 | 591 |
|
579 | 592 |
def AddInstanceTags(self, instance, tags, dry_run=False): |
580 | 593 |
"""Adds tags to an instance. |
... | ... | |
594 | 607 |
if dry_run: |
595 | 608 |
query.append(("dry-run", 1)) |
596 | 609 |
|
597 |
return self._SendRequest(HTTP_PUT, "/2/instances/%s/tags" % instance, |
|
598 |
query, None) |
|
610 |
return self._SendRequest(HTTP_PUT, |
|
611 |
("/%s/instances/%s/tags" % |
|
612 |
(GANETI_RAPI_VERSION, instance)), query, None) |
|
599 | 613 |
|
600 | 614 |
def DeleteInstanceTags(self, instance, tags, dry_run=False): |
601 | 615 |
"""Deletes tags from an instance. |
... | ... | |
612 | 626 |
if dry_run: |
613 | 627 |
query.append(("dry-run", 1)) |
614 | 628 |
|
615 |
return self._SendRequest(HTTP_DELETE, "/2/instances/%s/tags" % instance, |
|
616 |
query, None) |
|
629 |
return self._SendRequest(HTTP_DELETE, |
|
630 |
("/%s/instances/%s/tags" % |
|
631 |
(GANETI_RAPI_VERSION, instance)), query, None) |
|
617 | 632 |
|
618 | 633 |
def RebootInstance(self, instance, reboot_type=None, ignore_secondaries=None, |
619 | 634 |
dry_run=False): |
... | ... | |
638 | 653 |
if dry_run: |
639 | 654 |
query.append(("dry-run", 1)) |
640 | 655 |
|
641 |
return self._SendRequest(HTTP_POST, "/2/instances/%s/reboot" % instance, |
|
642 |
query, None) |
|
656 |
return self._SendRequest(HTTP_POST, |
|
657 |
("/%s/instances/%s/reboot" % |
|
658 |
(GANETI_RAPI_VERSION, instance)), query, None) |
|
643 | 659 |
|
644 | 660 |
def ShutdownInstance(self, instance, dry_run=False): |
645 | 661 |
"""Shuts down an instance. |
... | ... | |
654 | 670 |
if dry_run: |
655 | 671 |
query.append(("dry-run", 1)) |
656 | 672 |
|
657 |
return self._SendRequest(HTTP_PUT, "/2/instances/%s/shutdown" % instance, |
|
658 |
query, None) |
|
673 |
return self._SendRequest(HTTP_PUT, |
|
674 |
("/%s/instances/%s/shutdown" % |
|
675 |
(GANETI_RAPI_VERSION, instance)), query, None) |
|
659 | 676 |
|
660 | 677 |
def StartupInstance(self, instance, dry_run=False): |
661 | 678 |
"""Starts up an instance. |
... | ... | |
670 | 687 |
if dry_run: |
671 | 688 |
query.append(("dry-run", 1)) |
672 | 689 |
|
673 |
return self._SendRequest(HTTP_PUT, "/2/instances/%s/startup" % instance, |
|
674 |
query, None) |
|
690 |
return self._SendRequest(HTTP_PUT, |
|
691 |
("/%s/instances/%s/startup" % |
|
692 |
(GANETI_RAPI_VERSION, instance)), query, None) |
|
675 | 693 |
|
676 | 694 |
def ReinstallInstance(self, instance, os, no_startup=False): |
677 | 695 |
"""Reinstalls an instance. |
... | ... | |
687 | 705 |
query = [("os", os)] |
688 | 706 |
if no_startup: |
689 | 707 |
query.append(("nostartup", 1)) |
690 |
return self._SendRequest(HTTP_POST, "/2/instances/%s/reinstall" % instance, |
|
691 |
query, None) |
|
708 |
return self._SendRequest(HTTP_POST, |
|
709 |
("/%s/instances/%s/reinstall" % |
|
710 |
(GANETI_RAPI_VERSION, instance)), query, None) |
|
692 | 711 |
|
693 | 712 |
def ReplaceInstanceDisks(self, instance, disks, mode=REPLACE_DISK_AUTO, |
694 | 713 |
remote_node=None, iallocator=None, dry_run=False): |
... | ... | |
737 | 756 |
query.append(("dry-run", 1)) |
738 | 757 |
|
739 | 758 |
return self._SendRequest(HTTP_POST, |
740 |
"/2/instances/%s/replace-disks" % instance,
|
|
741 |
query, None) |
|
759 |
("/%s/instances/%s/replace-disks" %
|
|
760 |
(GANETI_RAPI_VERSION, instance)), query, None)
|
|
742 | 761 |
|
743 | 762 |
def GetJobs(self): |
744 | 763 |
"""Gets all jobs for the cluster. |
... | ... | |
748 | 767 |
|
749 | 768 |
""" |
750 | 769 |
return [int(j["id"]) |
751 |
for j in self._SendRequest(HTTP_GET, "/2/jobs", None, None)] |
|
770 |
for j in self._SendRequest(HTTP_GET, |
|
771 |
"/%s/jobs" % GANETI_RAPI_VERSION, |
|
772 |
None, None)] |
|
752 | 773 |
|
753 | 774 |
def GetJobStatus(self, job_id): |
754 | 775 |
"""Gets the status of a job. |
... | ... | |
760 | 781 |
@return: job status |
761 | 782 |
|
762 | 783 |
""" |
763 |
return self._SendRequest(HTTP_GET, "/2/jobs/%s" % job_id, None, None) |
|
784 |
return self._SendRequest(HTTP_GET, |
|
785 |
"/%s/jobs/%s" % (GANETI_RAPI_VERSION, job_id), |
|
786 |
None, None) |
|
764 | 787 |
|
765 | 788 |
def WaitForJobChange(self, job_id, fields, prev_job_info, prev_log_serial): |
766 | 789 |
"""Waits for job changes. |
... | ... | |
775 | 798 |
"previous_log_serial": prev_log_serial, |
776 | 799 |
} |
777 | 800 |
|
778 |
return self._SendRequest(HTTP_GET, "/2/jobs/%s/wait" % job_id, None, body) |
|
801 |
return self._SendRequest(HTTP_GET, |
|
802 |
"/%s/jobs/%s/wait" % (GANETI_RAPI_VERSION, job_id), |
|
803 |
None, body) |
|
779 | 804 |
|
780 | 805 |
def CancelJob(self, job_id, dry_run=False): |
781 | 806 |
"""Cancels a job. |
... | ... | |
790 | 815 |
if dry_run: |
791 | 816 |
query.append(("dry-run", 1)) |
792 | 817 |
|
793 |
return self._SendRequest(HTTP_DELETE, "/2/jobs/%s" % job_id, query, None) |
|
818 |
return self._SendRequest(HTTP_DELETE, |
|
819 |
"/%s/jobs/%s" % (GANETI_RAPI_VERSION, job_id), |
|
820 |
query, None) |
|
794 | 821 |
|
795 | 822 |
def GetNodes(self, bulk=False): |
796 | 823 |
"""Gets all nodes in the cluster. |
... | ... | |
807 | 834 |
if bulk: |
808 | 835 |
query.append(("bulk", 1)) |
809 | 836 |
|
810 |
nodes = self._SendRequest(HTTP_GET, "/2/nodes", query, None) |
|
837 |
nodes = self._SendRequest(HTTP_GET, "/%s/nodes" % GANETI_RAPI_VERSION, |
|
838 |
query, None) |
|
811 | 839 |
if bulk: |
812 | 840 |
return nodes |
813 | 841 |
else: |
... | ... | |
823 | 851 |
@return: info about the node |
824 | 852 |
|
825 | 853 |
""" |
826 |
return self._SendRequest(HTTP_GET, "/2/nodes/%s" % node, None, None) |
|
854 |
return self._SendRequest(HTTP_GET, |
|
855 |
"/%s/nodes/%s" % (GANETI_RAPI_VERSION, node), |
|
856 |
None, None) |
|
827 | 857 |
|
828 | 858 |
def EvacuateNode(self, node, iallocator=None, remote_node=None, |
829 | 859 |
dry_run=False): |
... | ... | |
855 | 885 |
if dry_run: |
856 | 886 |
query.append(("dry-run", 1)) |
857 | 887 |
|
858 |
return self._SendRequest(HTTP_POST, "/2/nodes/%s/evacuate" % node, |
|
859 |
query, None) |
|
888 |
return self._SendRequest(HTTP_POST, |
|
889 |
("/%s/nodes/%s/evacuate" % |
|
890 |
(GANETI_RAPI_VERSION, node)), query, None) |
|
860 | 891 |
|
861 | 892 |
def MigrateNode(self, node, live=True, dry_run=False): |
862 | 893 |
"""Migrates all primary instances from a node. |
... | ... | |
878 | 909 |
if dry_run: |
879 | 910 |
query.append(("dry-run", 1)) |
880 | 911 |
|
881 |
return self._SendRequest(HTTP_POST, "/2/nodes/%s/migrate" % node, |
|
882 |
query, None) |
|
912 |
return self._SendRequest(HTTP_POST, |
|
913 |
("/%s/nodes/%s/migrate" % |
|
914 |
(GANETI_RAPI_VERSION, node)), query, None) |
|
883 | 915 |
|
884 | 916 |
def GetNodeRole(self, node): |
885 | 917 |
"""Gets the current role for a node. |
... | ... | |
891 | 923 |
@return: the current role for a node |
892 | 924 |
|
893 | 925 |
""" |
894 |
return self._SendRequest(HTTP_GET, "/2/nodes/%s/role" % node, None, None) |
|
926 |
return self._SendRequest(HTTP_GET, |
|
927 |
("/%s/nodes/%s/role" % |
|
928 |
(GANETI_RAPI_VERSION, node)), None, None) |
|
895 | 929 |
|
896 | 930 |
def SetNodeRole(self, node, role, force=False): |
897 | 931 |
"""Sets the role for a node. |
... | ... | |
914 | 948 |
|
915 | 949 |
query = [("force", force)] |
916 | 950 |
|
917 |
return self._SendRequest(HTTP_PUT, "/2/nodes/%s/role" % node, |
|
918 |
query, role) |
|
951 |
return self._SendRequest(HTTP_PUT, |
|
952 |
("/%s/nodes/%s/role" % |
|
953 |
(GANETI_RAPI_VERSION, node)), query, role) |
|
919 | 954 |
|
920 | 955 |
def GetNodeStorageUnits(self, node, storage_type, output_fields): |
921 | 956 |
"""Gets the storage units for a node. |
... | ... | |
941 | 976 |
("output_fields", output_fields), |
942 | 977 |
] |
943 | 978 |
|
944 |
return self._SendRequest(HTTP_GET, "/2/nodes/%s/storage" % node, |
|
945 |
query, None) |
|
979 |
return self._SendRequest(HTTP_GET, |
|
980 |
("/%s/nodes/%s/storage" % |
|
981 |
(GANETI_RAPI_VERSION, node)), query, None) |
|
946 | 982 |
|
947 | 983 |
def ModifyNodeStorageUnits(self, node, storage_type, name, allocatable=True): |
948 | 984 |
"""Modifies parameters of storage units on the node. |
... | ... | |
970 | 1006 |
("allocatable", allocatable), |
971 | 1007 |
] |
972 | 1008 |
|
973 |
return self._SendRequest(HTTP_PUT, "/2/nodes/%s/storage/modify" % node, |
|
974 |
query, None) |
|
1009 |
return self._SendRequest(HTTP_PUT, |
|
1010 |
("/%s/nodes/%s/storage/modify" % |
|
1011 |
(GANETI_RAPI_VERSION, node)), query, None) |
|
975 | 1012 |
|
976 | 1013 |
def RepairNodeStorageUnits(self, node, storage_type, name): |
977 | 1014 |
"""Repairs a storage unit on the node. |
... | ... | |
996 | 1033 |
("name", name), |
997 | 1034 |
] |
998 | 1035 |
|
999 |
return self._SendRequest(HTTP_PUT, "/2/nodes/%s/storage/repair" % node, |
|
1000 |
query, None) |
|
1036 |
return self._SendRequest(HTTP_PUT, |
|
1037 |
("/%s/nodes/%s/storage/repair" % |
|
1038 |
(GANETI_RAPI_VERSION, node)), query, None) |
|
1001 | 1039 |
|
1002 | 1040 |
def GetNodeTags(self, node): |
1003 | 1041 |
"""Gets the tags for a node. |
... | ... | |
1009 | 1047 |
@return: tags for the node |
1010 | 1048 |
|
1011 | 1049 |
""" |
1012 |
return self._SendRequest(HTTP_GET, "/2/nodes/%s/tags" % node, None, None) |
|
1050 |
return self._SendRequest(HTTP_GET, |
|
1051 |
("/%s/nodes/%s/tags" % |
|
1052 |
(GANETI_RAPI_VERSION, node)), None, None) |
|
1013 | 1053 |
|
1014 | 1054 |
def AddNodeTags(self, node, tags, dry_run=False): |
1015 | 1055 |
"""Adds tags to a node. |
... | ... | |
1029 | 1069 |
if dry_run: |
1030 | 1070 |
query.append(("dry-run", 1)) |
1031 | 1071 |
|
1032 |
return self._SendRequest(HTTP_PUT, "/2/nodes/%s/tags" % node, |
|
1033 |
query, tags) |
|
1072 |
return self._SendRequest(HTTP_PUT, |
|
1073 |
("/%s/nodes/%s/tags" % |
|
1074 |
(GANETI_RAPI_VERSION, node)), query, tags) |
|
1034 | 1075 |
|
1035 | 1076 |
def DeleteNodeTags(self, node, tags, dry_run=False): |
1036 | 1077 |
"""Delete tags from a node. |
... | ... | |
1050 | 1091 |
if dry_run: |
1051 | 1092 |
query.append(("dry-run", 1)) |
1052 | 1093 |
|
1053 |
return self._SendRequest(HTTP_DELETE, "/2/nodes/%s/tags" % node, |
|
1054 |
query, None) |
|
1094 |
return self._SendRequest(HTTP_DELETE, |
|
1095 |
("/%s/nodes/%s/tags" % |
|
1096 |
(GANETI_RAPI_VERSION, node)), query, None) |
Also available in: Unified diff