418 |
418 |
|
419 |
419 |
return response_content
|
420 |
420 |
|
|
421 |
@staticmethod
|
|
422 |
def _CheckStorageType(storage_type):
|
|
423 |
"""Checks a storage type for validity.
|
|
424 |
|
|
425 |
"""
|
|
426 |
if storage_type not in VALID_STORAGE_TYPES:
|
|
427 |
raise InvalidStorageType("%s is an invalid storage type" % storage_type)
|
|
428 |
|
421 |
429 |
def GetVersion(self):
|
422 |
430 |
"""Gets the Remote API version running on the cluster.
|
423 |
431 |
|
... | ... | |
680 |
688 |
return self._SendRequest(HTTP_POST, "/2/instances/%s/reinstall" % instance,
|
681 |
689 |
query, None)
|
682 |
690 |
|
683 |
|
def ReplaceInstanceDisks(self, instance, disks, mode="replace_auto",
|
684 |
|
remote_node=None, iallocator="hail", dry_run=False):
|
|
691 |
def ReplaceInstanceDisks(self, instance, disks, mode=REPLACE_DISK_AUTO,
|
|
692 |
remote_node=None, iallocator=None, dry_run=False):
|
685 |
693 |
"""Replaces disks on an instance.
|
686 |
694 |
|
687 |
695 |
@type instance: str
|
... | ... | |
689 |
697 |
@type disks: list of str
|
690 |
698 |
@param disks: disks to replace
|
691 |
699 |
@type mode: str
|
692 |
|
@param mode: replacement mode to use. defaults to replace_auto
|
|
700 |
@param mode: replacement mode to use (defaults to replace_auto)
|
693 |
701 |
@type remote_node: str or None
|
694 |
702 |
@param remote_node: new secondary node to use (for use with
|
695 |
|
replace_new_secondary mdoe)
|
|
703 |
replace_new_secondary mode)
|
696 |
704 |
@type iallocator: str or None
|
697 |
705 |
@param iallocator: instance allocator plugin to use (for use with
|
698 |
|
replace_auto mdoe). default is hail
|
|
706 |
replace_auto mode)
|
699 |
707 |
@type dry_run: bool
|
700 |
708 |
@param dry_run: whether to perform a dry run
|
701 |
709 |
|
... | ... | |
708 |
716 |
|
709 |
717 |
"""
|
710 |
718 |
if mode not in VALID_REPLACEMENT_MODES:
|
711 |
|
raise InvalidReplacementMode("%s is not a valid disk replacement mode.",
|
|
719 |
raise InvalidReplacementMode("%s is not a valid disk replacement mode" %
|
712 |
720 |
mode)
|
713 |
721 |
|
714 |
|
query = [("mode", mode), ("disks", ",".join(disks))]
|
|
722 |
query = [
|
|
723 |
("mode", mode),
|
|
724 |
("disks", ",".join(disks)),
|
|
725 |
]
|
715 |
726 |
|
716 |
|
if mode is REPLACE_DISK_AUTO:
|
|
727 |
if mode == REPLACE_DISK_AUTO:
|
717 |
728 |
query.append(("iallocator", iallocator))
|
718 |
|
elif mode is REPLACE_DISK_SECONDARY:
|
|
729 |
elif mode == REPLACE_DISK_SECONDARY:
|
719 |
730 |
if remote_node is None:
|
720 |
|
raise GanetiApiError("You must supply a new secondary node.")
|
|
731 |
raise GanetiApiError("Missing secondary node")
|
721 |
732 |
query.append(("remote_node", remote_node))
|
722 |
733 |
|
723 |
734 |
if dry_run:
|
... | ... | |
816 |
827 |
@raises GanetiApiError: if an iallocator and remote_node are both specified
|
817 |
828 |
|
818 |
829 |
"""
|
819 |
|
query = []
|
820 |
830 |
if iallocator and remote_node:
|
821 |
|
raise GanetiApiError("Only one of iallocator or remote_node can be used.")
|
|
831 |
raise GanetiApiError("Only one of iallocator or remote_node can be used")
|
822 |
832 |
|
|
833 |
query = []
|
823 |
834 |
if iallocator:
|
824 |
835 |
query.append(("iallocator", iallocator))
|
825 |
836 |
if remote_node:
|
... | ... | |
882 |
893 |
|
883 |
894 |
"""
|
884 |
895 |
if role not in VALID_NODE_ROLES:
|
885 |
|
raise InvalidNodeRole("%s is not a valid node role.", role)
|
|
896 |
raise InvalidNodeRole("%s is not a valid node role" % role)
|
886 |
897 |
|
887 |
898 |
query = [("force", force)]
|
|
899 |
|
888 |
900 |
return self._SendRequest(HTTP_PUT, "/2/nodes/%s/role" % node,
|
889 |
901 |
query, role)
|
890 |
902 |
|
... | ... | |
905 |
917 |
|
906 |
918 |
"""
|
907 |
919 |
# TODO: Add default for storage_type & output_fields
|
908 |
|
if storage_type not in VALID_STORAGE_TYPES:
|
909 |
|
raise InvalidStorageType("%s is an invalid storage type.", storage_type)
|
|
920 |
self._CheckStorageType(storage_type)
|
|
921 |
|
|
922 |
query = [
|
|
923 |
("storage_type", storage_type),
|
|
924 |
("output_fields", output_fields),
|
|
925 |
]
|
910 |
926 |
|
911 |
|
query = [("storage_type", storage_type), ("output_fields", output_fields)]
|
912 |
927 |
return self._SendRequest(HTTP_GET, "/2/nodes/%s/storage" % node,
|
913 |
928 |
query, None)
|
914 |
929 |
|
... | ... | |
930 |
945 |
@raise InvalidStorageType: If an invalid storage type is specified
|
931 |
946 |
|
932 |
947 |
"""
|
933 |
|
if storage_type not in VALID_STORAGE_TYPES:
|
934 |
|
raise InvalidStorageType("%s is an invalid storage type.", storage_type)
|
|
948 |
self._CheckStorageType(storage_type)
|
935 |
949 |
|
936 |
950 |
query = [
|
937 |
|
("storage_type", storage_type), ("name", name),
|
938 |
|
("allocatable", allocatable)
|
939 |
|
]
|
|
951 |
("storage_type", storage_type),
|
|
952 |
("name", name),
|
|
953 |
("allocatable", allocatable),
|
|
954 |
]
|
|
955 |
|
940 |
956 |
return self._SendRequest(HTTP_PUT, "/2/nodes/%s/storage/modify" % node,
|
941 |
957 |
query, None)
|
942 |
958 |
|
... | ... | |
956 |
972 |
@raise InvalidStorageType: If an invalid storage type is specified
|
957 |
973 |
|
958 |
974 |
"""
|
959 |
|
if storage_type not in VALID_STORAGE_TYPES:
|
960 |
|
raise InvalidStorageType("%s is an invalid storage type.", storage_type)
|
|
975 |
self._CheckStorageType(storage_type)
|
|
976 |
|
|
977 |
query = [
|
|
978 |
("storage_type", storage_type),
|
|
979 |
("name", name),
|
|
980 |
]
|
961 |
981 |
|
962 |
|
query = [("storage_type", storage_type), ("name", name)]
|
963 |
982 |
return self._SendRequest(HTTP_PUT, "/2/nodes/%s/storage/repair" % node,
|
964 |
983 |
query, None)
|
965 |
984 |
|