Revision 870dc44c
b/lib/backend.py | ||
---|---|---|
1943 | 1943 |
@raise RPCFail: if we don't find a valid OS |
1944 | 1944 |
|
1945 | 1945 |
""" |
1946 |
name_only = name.split("+", 1)[0]
|
|
1946 |
name_only = objects.OS.GetName(name)
|
|
1947 | 1947 |
status, payload = _TryOSFromDisk(name_only, base_dir) |
1948 | 1948 |
|
1949 | 1949 |
if not status: |
... | ... | |
1978 | 1978 |
|
1979 | 1979 |
# OS variants |
1980 | 1980 |
if api_version >= constants.OS_API_V15: |
1981 |
try: |
|
1982 |
variant = os_name.split('+', 1)[1] |
|
1983 |
except IndexError: |
|
1981 |
variant = objects.OS.GetVariant(os_name) |
|
1982 |
if not variant: |
|
1984 | 1983 |
variant = inst_os.supported_variants[0] |
1985 | 1984 |
result['OS_VARIANT'] = variant |
1986 | 1985 |
|
... | ... | |
2528 | 2527 |
_Fail("Unknown checks required for OS %s: %s", osname, |
2529 | 2528 |
set(checks).difference(constants.OS_VALIDATE_CALLS)) |
2530 | 2529 |
|
2531 |
name_only = osname.split("+", 1)[0]
|
|
2530 |
name_only = objects.OS.GetName(osname)
|
|
2532 | 2531 |
status, tbv = _TryOSFromDisk(name_only, None) |
2533 | 2532 |
|
2534 | 2533 |
if not status: |
b/lib/cmdlib.py | ||
---|---|---|
1088 | 1088 |
""" |
1089 | 1089 |
if not os_obj.supported_variants: |
1090 | 1090 |
return |
1091 |
try: |
|
1092 |
variant = name.split("+", 1)[1] |
|
1093 |
except IndexError: |
|
1091 |
variant = objects.OS.GetVariant(name) |
|
1092 |
if not variant: |
|
1094 | 1093 |
raise errors.OpPrereqError("OS name must include a variant", |
1095 | 1094 |
errors.ECODE_INVAL) |
1096 | 1095 |
|
b/lib/objects.py | ||
---|---|---|
1 | 1 |
# |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2006, 2007 Google Inc. |
|
4 |
# Copyright (C) 2006, 2007, 2008, 2009, 2010 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
861 | 861 |
@ivar supported_parameters: a list of tuples, name and description, |
862 | 862 |
containing the supported parameters by this OS |
863 | 863 |
|
864 |
@type VARIANT_DELIM: string |
|
865 |
@cvar VARIANT_DELIM: the variant delimiter |
|
866 |
|
|
864 | 867 |
""" |
865 | 868 |
__slots__ = [ |
866 | 869 |
"name", |
... | ... | |
875 | 878 |
"supported_parameters", |
876 | 879 |
] |
877 | 880 |
|
881 |
VARIANT_DELIM = "+" |
|
882 |
|
|
883 |
@classmethod |
|
884 |
def SplitNameVariant(cls, name): |
|
885 |
"""Splits the name into the proper name and variant. |
|
886 |
|
|
887 |
@param name: the OS (unprocessed) name |
|
888 |
@rtype: list |
|
889 |
@return: a list of two elements; if the original name didn't |
|
890 |
contain a variant, it's returned as an empty string |
|
891 |
|
|
892 |
""" |
|
893 |
nv = name.split(cls.VARIANT_DELIM, 1) |
|
894 |
if len(nv) == 1: |
|
895 |
nv.append("") |
|
896 |
return nv |
|
897 |
|
|
898 |
@classmethod |
|
899 |
def GetName(cls, name): |
|
900 |
"""Returns the proper name of the os (without the variant). |
|
901 |
|
|
902 |
@param name: the OS (unprocessed) name |
|
903 |
|
|
904 |
""" |
|
905 |
return cls.SplitNameVariant(name)[0] |
|
906 |
|
|
907 |
@classmethod |
|
908 |
def GetVariant(cls, name): |
|
909 |
"""Returns the variant the os (without the base name). |
|
910 |
|
|
911 |
@param name: the OS (unprocessed) name |
|
912 |
|
|
913 |
""" |
|
914 |
return cls.SplitNameVariant(name)[1] |
|
915 |
|
|
878 | 916 |
|
879 | 917 |
class Node(TaggableObject): |
880 | 918 |
"""Config object representing a node.""" |
b/test/ganeti.objects_unittest.py | ||
---|---|---|
1 | 1 |
#!/usr/bin/python |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2006, 2007, 2008 Google Inc. |
|
4 |
# Copyright (C) 2006, 2007, 2008, 2010 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
142 | 142 |
self.fake_cl.FillHV(fake_inst)) |
143 | 143 |
|
144 | 144 |
|
145 |
class TestOS(unittest.TestCase): |
|
146 |
ALL_DATA = [ |
|
147 |
"debootstrap", |
|
148 |
"debootstrap+default", |
|
149 |
"debootstrap++default", |
|
150 |
] |
|
151 |
|
|
152 |
def testSplitNameVariant(self): |
|
153 |
for name in self.ALL_DATA: |
|
154 |
self.assertEqual(len(objects.OS.SplitNameVariant(name)), 2) |
|
155 |
|
|
156 |
def testVariant(self): |
|
157 |
self.assertEqual(objects.OS.GetVariant("debootstrap"), "") |
|
158 |
self.assertEqual(objects.OS.GetVariant("debootstrap+default"), "default") |
|
159 |
|
|
160 |
|
|
145 | 161 |
if __name__ == '__main__': |
146 | 162 |
testutils.GanetiTestProgram() |
Also available in: Unified diff