Revision 553cb5f7
b/doc/rapi.rst | ||
---|---|---|
196 | 196 |
constants.ISPEC_DISK_SIZE, |
197 | 197 |
constants.ISPEC_DISK_COUNT, |
198 | 198 |
constants.ISPEC_CPU_COUNT, |
199 |
constants.ISPEC_NIC_COUNT])) |
|
199 |
constants.ISPEC_NIC_COUNT, |
|
200 |
constants.ISPEC_SPINDLE_USE])) |
|
200 | 201 |
|
201 | 202 |
.. |ispec-min| replace:: :pyeval:`constants.ISPECS_MIN` |
202 | 203 |
.. |ispec-max| replace:: :pyeval:`constants.ISPECS_MAX` |
... | ... | |
217 | 218 |
The numbers of cpus used |
218 | 219 |
:pyeval:`constants.ISPEC_NIC_COUNT` |
219 | 220 |
The numbers of nics used |
221 |
:pyeval:`constants.ISPEC_SPINDLE_USE` |
|
222 |
The numbers of virtual disk spindles used by this instance. They are |
|
223 |
not real, but useful for account the spindle usage on the residing |
|
224 |
node. |
|
220 | 225 |
:pyeval:`constants.IPOLICY_DTS` |
221 | 226 |
A `list` of disk templates allowed for instances using this policy |
222 | 227 |
:pyeval:`constants.IPOLICY_VCPU_RATIO` |
b/lib/cmdlib.py | ||
---|---|---|
1093 | 1093 |
|
1094 | 1094 |
|
1095 | 1095 |
def _ComputeIPolicySpecViolation(ipolicy, mem_size, cpu_count, disk_count, |
1096 |
nic_count, disk_sizes, |
|
1096 |
nic_count, disk_sizes, spindle_use,
|
|
1097 | 1097 |
_compute_fn=_ComputeMinMaxSpec): |
1098 | 1098 |
"""Verifies ipolicy against provided specs. |
1099 | 1099 |
|
... | ... | |
1109 | 1109 |
@param nic_count: Number of nics used |
1110 | 1110 |
@type disk_sizes: list of ints |
1111 | 1111 |
@param disk_sizes: Disk sizes of used disk (len must match C{disk_count}) |
1112 |
@type spindle_use: int |
|
1113 |
@param spindle_use: The number of spindles this instance uses |
|
1112 | 1114 |
@param _compute_fn: The compute function (unittest only) |
1113 | 1115 |
@return: A list of violations, or an empty list of no violations are found |
1114 | 1116 |
|
... | ... | |
1120 | 1122 |
(constants.ISPEC_CPU_COUNT, cpu_count), |
1121 | 1123 |
(constants.ISPEC_DISK_COUNT, disk_count), |
1122 | 1124 |
(constants.ISPEC_NIC_COUNT, nic_count), |
1125 |
(constants.ISPEC_SPINDLE_USE, spindle_use), |
|
1123 | 1126 |
] + map((lambda d: (constants.ISPEC_DISK_SIZE, d)), disk_sizes) |
1124 | 1127 |
|
1125 | 1128 |
return filter(None, |
... | ... | |
1141 | 1144 |
""" |
1142 | 1145 |
mem_size = instance.beparams.get(constants.BE_MAXMEM, None) |
1143 | 1146 |
cpu_count = instance.beparams.get(constants.BE_VCPUS, None) |
1147 |
spindle_use = instance.beparams.get(constants.BE_SPINDLE_USAGE, None) |
|
1144 | 1148 |
disk_count = len(instance.disks) |
1145 | 1149 |
disk_sizes = [disk.size for disk in instance.disks] |
1146 | 1150 |
nic_count = len(instance.nics) |
1147 | 1151 |
|
1148 | 1152 |
return _compute_fn(ipolicy, mem_size, cpu_count, disk_count, nic_count, |
1149 |
disk_sizes) |
|
1153 |
disk_sizes, spindle_use)
|
|
1150 | 1154 |
|
1151 | 1155 |
|
1152 | 1156 |
def _ComputeIPolicyInstanceSpecViolation(ipolicy, instance_spec, |
... | ... | |
1166 | 1170 |
disk_count = instance_spec.get(constants.ISPEC_DISK_COUNT, 0) |
1167 | 1171 |
disk_sizes = instance_spec.get(constants.ISPEC_DISK_SIZE, []) |
1168 | 1172 |
nic_count = instance_spec.get(constants.ISPEC_NIC_COUNT, 0) |
1173 |
spindle_use = instance_spec.get(constants.ISPEC_SPINDLE_USE, None) |
|
1169 | 1174 |
|
1170 | 1175 |
return _compute_fn(ipolicy, mem_size, cpu_count, disk_count, nic_count, |
1171 |
disk_sizes) |
|
1176 |
disk_sizes, spindle_use)
|
|
1172 | 1177 |
|
1173 | 1178 |
|
1174 | 1179 |
def _ComputeIPolicyNodeViolation(ipolicy, instance, current_group, |
... | ... | |
9845 | 9850 |
nodenames = [pnode.name] + self.secondaries |
9846 | 9851 |
|
9847 | 9852 |
# Verify instance specs |
9853 |
spindle_use = self.be_full.get(constants.BE_SPINDLE_USAGE, None) |
|
9848 | 9854 |
ispec = { |
9849 | 9855 |
constants.ISPEC_MEM_SIZE: self.be_full.get(constants.BE_MAXMEM, None), |
9850 | 9856 |
constants.ISPEC_CPU_COUNT: self.be_full.get(constants.BE_VCPUS, None), |
9851 | 9857 |
constants.ISPEC_DISK_COUNT: len(self.disks), |
9852 | 9858 |
constants.ISPEC_DISK_SIZE: [disk["size"] for disk in self.disks], |
9853 | 9859 |
constants.ISPEC_NIC_COUNT: len(self.nics), |
9860 |
constants.ISPEC_SPINDLE_USE: spindle_use, |
|
9854 | 9861 |
} |
9855 | 9862 |
|
9856 | 9863 |
group_info = self.cfg.GetNodeGroup(pnode.group) |
b/lib/constants.py | ||
---|---|---|
942 | 942 |
ISPEC_DISK_COUNT = "disk-count" |
943 | 943 |
ISPEC_DISK_SIZE = "disk-size" |
944 | 944 |
ISPEC_NIC_COUNT = "nic-count" |
945 |
ISPEC_SPINDLE_USE = "spindle-use" |
|
945 | 946 |
|
946 | 947 |
ISPECS_PARAMETER_TYPES = { |
947 | 948 |
ISPEC_MEM_SIZE: VTYPE_INT, |
... | ... | |
949 | 950 |
ISPEC_DISK_COUNT: VTYPE_INT, |
950 | 951 |
ISPEC_DISK_SIZE: VTYPE_INT, |
951 | 952 |
ISPEC_NIC_COUNT: VTYPE_INT, |
953 |
ISPEC_SPINDLE_USE: VTYPE_INT, |
|
952 | 954 |
} |
953 | 955 |
|
954 | 956 |
ISPECS_PARAMETERS = frozenset(ISPECS_PARAMETER_TYPES.keys()) |
... | ... | |
1914 | 1916 |
ISPEC_DISK_COUNT: 1, |
1915 | 1917 |
ISPEC_DISK_SIZE: 1024, |
1916 | 1918 |
ISPEC_NIC_COUNT: 1, |
1919 |
ISPEC_SPINDLE_USE: 1, |
|
1917 | 1920 |
}, |
1918 | 1921 |
ISPECS_MAX: { |
1919 | 1922 |
ISPEC_MEM_SIZE: 32768, |
... | ... | |
1921 | 1924 |
ISPEC_DISK_COUNT: MAX_DISKS, |
1922 | 1925 |
ISPEC_DISK_SIZE: 1024 * 1024, |
1923 | 1926 |
ISPEC_NIC_COUNT: MAX_NICS, |
1927 |
ISPEC_SPINDLE_USE: 12, |
|
1924 | 1928 |
}, |
1925 | 1929 |
ISPECS_STD: { |
1926 | 1930 |
ISPEC_MEM_SIZE: 128, |
... | ... | |
1928 | 1932 |
ISPEC_DISK_COUNT: 1, |
1929 | 1933 |
ISPEC_DISK_SIZE: 1024, |
1930 | 1934 |
ISPEC_NIC_COUNT: 1, |
1935 |
ISPEC_SPINDLE_USE: 1, |
|
1931 | 1936 |
}, |
1932 | 1937 |
IPOLICY_DTS: DISK_TEMPLATES, |
1933 | 1938 |
IPOLICY_VCPU_RATIO: 4.0, |
b/test/ganeti.cmdlib_unittest.py | ||
---|---|---|
645 | 645 |
def test(self): |
646 | 646 |
compute_fn = _ValidateComputeMinMaxSpec |
647 | 647 |
ret = cmdlib._ComputeIPolicySpecViolation(NotImplemented, 1024, 1, 1, 1, |
648 |
[1024], _compute_fn=compute_fn) |
|
648 |
[1024], 1, _compute_fn=compute_fn)
|
|
649 | 649 |
self.assertEqual(ret, []) |
650 | 650 |
|
651 | 651 |
def testInvalidArguments(self): |
652 | 652 |
self.assertRaises(AssertionError, cmdlib._ComputeIPolicySpecViolation, |
653 |
NotImplemented, 1024, 1, 1, 1, []) |
|
653 |
NotImplemented, 1024, 1, 1, 1, [], 1)
|
|
654 | 654 |
|
655 | 655 |
def testInvalidSpec(self): |
656 |
spec = _SpecWrapper([None, False, "foo", None, "bar"]) |
|
656 |
spec = _SpecWrapper([None, False, "foo", None, "bar", None])
|
|
657 | 657 |
compute_fn = spec.ComputeMinMaxSpec |
658 | 658 |
ret = cmdlib._ComputeIPolicySpecViolation(NotImplemented, 1024, 1, 1, 1, |
659 |
[1024], _compute_fn=compute_fn) |
|
659 |
[1024], 1, _compute_fn=compute_fn)
|
|
660 | 660 |
self.assertEqual(ret, ["foo", "bar"]) |
661 | 661 |
self.assertFalse(spec.spec) |
662 | 662 |
|
663 | 663 |
|
664 | 664 |
class _StubComputeIPolicySpecViolation: |
665 |
def __init__(self, mem_size, cpu_count, disk_count, nic_count, disk_sizes): |
|
665 |
def __init__(self, mem_size, cpu_count, disk_count, nic_count, disk_sizes, |
|
666 |
spindle_use): |
|
666 | 667 |
self.mem_size = mem_size |
667 | 668 |
self.cpu_count = cpu_count |
668 | 669 |
self.disk_count = disk_count |
669 | 670 |
self.nic_count = nic_count |
670 | 671 |
self.disk_sizes = disk_sizes |
672 |
self.spindle_use = spindle_use |
|
671 | 673 |
|
672 |
def __call__(self, _, mem_size, cpu_count, disk_count, nic_count, disk_sizes): |
|
674 |
def __call__(self, _, mem_size, cpu_count, disk_count, nic_count, disk_sizes, |
|
675 |
spindle_use): |
|
673 | 676 |
assert self.mem_size == mem_size |
674 | 677 |
assert self.cpu_count == cpu_count |
675 | 678 |
assert self.disk_count == disk_count |
676 | 679 |
assert self.nic_count == nic_count |
677 | 680 |
assert self.disk_sizes == disk_sizes |
681 |
assert self.spindle_use == spindle_use |
|
678 | 682 |
|
679 | 683 |
return [] |
680 | 684 |
|
... | ... | |
684 | 688 |
beparams = { |
685 | 689 |
constants.BE_MAXMEM: 2048, |
686 | 690 |
constants.BE_VCPUS: 2, |
691 |
constants.BE_SPINDLE_USAGE: 4, |
|
687 | 692 |
} |
688 | 693 |
disks = [objects.Disk(size=512)] |
689 | 694 |
instance = objects.Instance(beparams=beparams, disks=disks, nics=[]) |
690 |
stub = _StubComputeIPolicySpecViolation(2048, 2, 1, 0, [512]) |
|
695 |
stub = _StubComputeIPolicySpecViolation(2048, 2, 1, 0, [512], 4)
|
|
691 | 696 |
ret = cmdlib._ComputeIPolicyInstanceViolation(NotImplemented, instance, |
692 | 697 |
_compute_fn=stub) |
693 | 698 |
self.assertEqual(ret, []) |
... | ... | |
701 | 706 |
constants.ISPEC_DISK_COUNT: 1, |
702 | 707 |
constants.ISPEC_DISK_SIZE: [512], |
703 | 708 |
constants.ISPEC_NIC_COUNT: 0, |
709 |
constants.ISPEC_SPINDLE_USE: 1, |
|
704 | 710 |
} |
705 |
stub = _StubComputeIPolicySpecViolation(2048, 2, 1, 0, [512]) |
|
711 |
stub = _StubComputeIPolicySpecViolation(2048, 2, 1, 0, [512], 1)
|
|
706 | 712 |
ret = cmdlib._ComputeIPolicyInstanceSpecViolation(NotImplemented, ispec, |
707 | 713 |
_compute_fn=stub) |
708 | 714 |
self.assertEqual(ret, []) |
Also available in: Unified diff