1 ##############################################################################
2 # Copyright (c) 2015 Todd Gaunt and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
12 from pharosvalidator.util import approxsize
15 from pharosvalidator.const import *
18 """Compares system cpu against the pharos specification"""
21 # Architecture evaluation, a value of 63 or greater indicates at least a 64-bit OS
22 if cpudata["bitsize"] >= 63:
26 result = {"architecture": {
28 "description": str(cpudata["architecture"])}}
29 results.append(result)
32 if cpudata["cores"] < MIN_CORECOUNT:
36 desc = "Have {0}, Need at least {1}".format(cpudata["cores"], MIN_CORECOUNT)
37 result = {"corecount": {
40 results.append(result)
44 for cpufreq in cpudata["frequency"]:
45 # Cpufrequency was not read if this is the result
47 desc = "(Cpu freuency could not be read)"
49 if approxsize(cpufreq, MIN_CPUFREQ, 5) or cpufreq > MIN_CPUFREQ:
53 desc = "Have {:.2f}Mhz, Need at least ~= {:.2f}Mhz".format( \
55 result = {"cpu"+str(i): {
58 results.append(result)
64 """Compares system meminfo object against the pharos specification"""
65 logger = logging.getLogger(__name__)
69 logger.debug("required memory: {}, detected memory: {}".format(\
70 MIN_MEMSIZE, memdata["size"]))
72 if approxsize(memdata["size"], MIN_MEMSIZE, 5) or memdata["size"] > MIN_MEMSIZE:
77 desc = "Have {:.2f}G, Need at least ~= {:.2f}G".format( \
78 memdata["size"], MIN_MEMSIZE/1000000)
80 result = {"memory capacity": {
83 results.append(result)
87 def storage(diskdata):
88 """Compares system storage against the Pharos specification"""
89 def sizecmp(a, b, unit):
90 if approxsize(a, b, 10) or a > b:
94 desc = "capacity is {:.2f}{}, Need at least ~= {:.2f}{}".format(a, \
99 # Disk size evaluation (also counts the disks)
100 diskcount = {"ssd":0, "non-ssd":0}
101 for disk in diskdata["names"]:
102 if diskdata["rotational"][disk]:
104 diskcount["non-ssd"] += 1
107 diskcount["ssd"] += 1
108 val, desc = sizecmp(diskdata["sizes"][disk], MIN_SSDSIZE, 'G')
109 data = diskdata["sizes"][disk]
112 "description": "Disk type: disktype; " + desc}}
113 results.append(result)
115 # Disk number evaluation
116 if sum(diskcount.values()) >= 3 and diskcount["ssd"] >= 1:
120 desc = "Have {0} drives, Need at least {1} drives and {3} ssds".format( \
121 sum(diskcount.values()), MIN_DISKCOUNT, \
122 diskcount["ssd"], MIN_SSDCOUNT)
125 result = {"diskcount": {
127 "description": desc}}
128 results.append(result)
132 def netinterfaces(netfaces):
134 for netface in netfaces:
135 if netface.status <= 0:
142 MACaddr = netface.MAC[0]["addr"]
145 if len(netface.addrs) > 0:
147 for addr in netface.addrs:
150 addrs += addr['addr']
151 addrs = "addresses: " + addrs
154 desc = "({0} is {1} with {2})".format(netface.name, state, addrs)
156 results.append(gen_yamltext(netface.name, val, desc, data))