author | Drew Fisher <drew.fisher@oracle.com> |
Mon, 08 Aug 2011 14:21:15 -0600 | |
changeset 1376 | 1586eba25902 |
parent 1370 | 0e49021cc774 |
child 1377 | 51a448c0a1b5 |
permissions | -rw-r--r-- |
1112 | 1 |
#!/usr/bin/python |
2 |
# |
|
3 |
# CDDL HEADER START |
|
4 |
# |
|
5 |
# The contents of this file are subject to the terms of the |
|
6 |
# Common Development and Distribution License (the "License"). |
|
7 |
# You may not use this file except in compliance with the License. |
|
8 |
# |
|
9 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
10 |
# or http://www.opensolaris.org/os/licensing. |
|
11 |
# See the License for the specific language governing permissions |
|
12 |
# and limitations under the License. |
|
13 |
# |
|
14 |
# When distributing Covered Code, include this CDDL HEADER in each |
|
15 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
16 |
# If applicable, add the following below this CDDL HEADER, with the |
|
17 |
# fields enclosed by brackets "[]" replaced with your own identifying |
|
18 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
|
19 |
# |
|
20 |
# CDDL HEADER END |
|
21 |
# |
|
22 |
||
23 |
# |
|
24 |
# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
|
25 |
# |
|
26 |
||
27 |
""" controller.py, TargetController and related classes. |
|
28 |
""" |
|
29 |
||
30 |
import logging |
|
31 |
import os |
|
32 |
import platform |
|
33 |
||
34 |
from copy import copy, deepcopy |
|
35 |
||
36 |
from solaris_install import Popen |
|
37 |
from solaris_install.data_object.simple import SimpleXmlHandlerBase |
|
38 |
from solaris_install.logger import INSTALL_LOGGER_NAME |
|
39 |
from solaris_install.target import Target |
|
40 |
from solaris_install.target.libadm.const import V_ROOT |
|
41 |
from solaris_install.target.logical import Logical, BE |
|
42 |
from solaris_install.target.physical import Disk, Partition, Slice |
|
43 |
from solaris_install.target.size import Size |
|
44 |
||
45 |
LOGGER = None |
|
46 |
||
47 |
# If install image size not available, use 4GB |
|
48 |
FALLBACK_IMAGE_SIZE = Size("4" + Size.gb_units) |
|
49 |
||
50 |
# Values for Swap and Dump calculations. All values are in MB |
|
1370
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
51 |
MIN_SWAP_SIZE = 1024 |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
52 |
MAX_SWAP_SIZE = (Size("4gb")).get(Size.mb_units) |
1112 | 53 |
MIN_DUMP_SIZE = 256 |
1370
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
54 |
MAX_DUMP_SIZE = (Size("64gb")).get(Size.mb_units) |
1112 | 55 |
OVERHEAD = 1024 |
56 |
FUTURE_UPGRADE_SPACE = (Size("2gb")).get(Size.mb_units) |
|
57 |
# Swap ZVOL is required if memory is below this |
|
58 |
ZVOL_REQ_MEM = 900 |
|
59 |
||
1121
670325895b19
7004610 Update Text Installer to use CUD
Karen Tung <karen.tung@oracle.com>
parents:
1113
diff
changeset
|
60 |
VFSTAB_FILE = "etc/vfstab" |
1112 | 61 |
|
62 |
# "TargetController data" is an area in the DataObjectCache |
|
63 |
# intended for the TargetController class's private use. It |
|
64 |
# is identified by a top-level <target> element, with the name |
|
65 |
# "TargetController data", under the DOC's persistent tree. |
|
66 |
# See TargetControllerBackupEntry class for more details. |
|
67 |
DATA_AREA_NAME = "TargetController data" |
|
68 |
||
69 |
DEFAULT_LOGICAL_NAME = "logical" |
|
70 |
DEFAULT_ZPOOL_NAME = "rpool" |
|
71 |
DEFAULT_VDEV_NAME = "vdev" |
|
72 |
VDEV_REDUNDANCY_NONE = "none" |
|
73 |
VDEV_REDUNDANCY_MIRROR = "mirror" |
|
74 |
||
75 |
||
76 |
class BadDiskError(Exception): |
|
77 |
''' General purpose error class for when TargetController is unable |
|
78 |
to access a disk. |
|
79 |
''' |
|
80 |
pass |
|
81 |
||
1236
2f3a9d3aa9cb
7051027 Installer not enabling disk write cache when entire disk selected
Drew Fisher <drew.fisher@oracle.com>
parents:
1204
diff
changeset
|
82 |
|
1204
5c7590b24780
7050438 Update GUI Install to use CUD
Dermot <Dermot.McCluskey@Oracle.COM>
parents:
1151
diff
changeset
|
83 |
class SubSizeDiskError(BadDiskError): |
5c7590b24780
7050438 Update GUI Install to use CUD
Dermot <Dermot.McCluskey@Oracle.COM>
parents:
1151
diff
changeset
|
84 |
''' Specific exception sub-class for when a disk is below the |
5c7590b24780
7050438 Update GUI Install to use CUD
Dermot <Dermot.McCluskey@Oracle.COM>
parents:
1151
diff
changeset
|
85 |
minimum required size for installation. |
5c7590b24780
7050438 Update GUI Install to use CUD
Dermot <Dermot.McCluskey@Oracle.COM>
parents:
1151
diff
changeset
|
86 |
''' |
5c7590b24780
7050438 Update GUI Install to use CUD
Dermot <Dermot.McCluskey@Oracle.COM>
parents:
1151
diff
changeset
|
87 |
pass |
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
88 |
|
1236
2f3a9d3aa9cb
7051027 Installer not enabling disk write cache when entire disk selected
Drew Fisher <drew.fisher@oracle.com>
parents:
1204
diff
changeset
|
89 |
|
1112 | 90 |
class SwapDumpGeneralError(Exception): |
91 |
''' General exception for errors computing swap and dump values. |
|
92 |
''' |
|
93 |
pass |
|
94 |
||
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
95 |
|
1112 | 96 |
class SwapDumpSpaceError(Exception): |
97 |
''' Not enough space in the target disk for successful installation. |
|
98 |
''' |
|
99 |
pass |
|
100 |
||
101 |
||
102 |
class TargetController(object): |
|
103 |
''' The TargetController (TC) class is intended to be used by all the |
|
104 |
Install client apps for the purpose of selecting the disk |
|
105 |
or disks for the install. It creates and sets up the |
|
106 |
"desired targets" area in the DataObjectCache (DOC) in the manner |
|
107 |
expected by the TargetInstantiation (TI) checkpoint, which |
|
108 |
will typically be run later. |
|
109 |
||
110 |
TC also calculates minimum and recommended sizes for the installation |
|
111 |
target, based on the passed-in image size and calculates sizes |
|
112 |
for swap and dump devices, if required. |
|
113 |
||
114 |
NB: |
|
115 |
Where TC methods accept Disk objects as parameters, these can |
|
116 |
be the actual Disk objects discovered by TargetDiscovery |
|
117 |
(TD), which the calling application will have retrieved from the |
|
118 |
"discovered targets" area of the DOC. Or, they can be other |
|
119 |
Disk objects which represent the same disks as the "discovered |
|
120 |
targets". In this case, TargetController will locate the |
|
121 |
corresponding Disks from "discovered targets" before processing |
|
122 |
them. |
|
123 |
Where TC methods return Disk objects, these will always be |
|
124 |
(possibly modified) copies of those discovered disks: TC takes |
|
125 |
in references to the "discovered targets", makes copies of those |
|
126 |
objects, places the copies in "desired targets" and returns the |
|
127 |
copies to the calling code. |
|
128 |
||
129 |
TC does not itself control changes to the partitioning layout |
|
130 |
of the selected disk(s) - this is done directly by the |
|
131 |
application by operating on the Disk objects returned from |
|
132 |
TC's methods. |
|
133 |
||
134 |
TC also maintains a backup of the previously selected disk(s), |
|
135 |
so that if the user makes changes to the partitioning layout |
|
136 |
of the selected disk(s); then changes the selected disk(s); |
|
137 |
and then changes back to the original disk(s), the previous |
|
138 |
partitioning layout that they configured will not be lost. |
|
139 |
||
140 |
APIs: |
|
141 |
||
142 |
from solaris_install.target.controller import TargetController, \ |
|
143 |
BadDiskError, SwapDumpGeneralError, SwapDumpSpaceError |
|
144 |
||
145 |
target_controller = TargetController(doc, debug=False) |
|
146 |
disks = target_controller.initialize( |
|
147 |
image_size=FALLBACK_IMAGE_SIZE, |
|
148 |
no_initial_disk=False, |
|
149 |
no_initial_logical=False, |
|
150 |
install_mountpoint="/a", |
|
151 |
unique_zpool_name=False) |
|
152 |
logical = target_controller.apply_default_logical( |
|
153 |
logical=None, |
|
154 |
mountpoint="/a", |
|
155 |
redundancy="none", |
|
156 |
unique_zpool_name=True) |
|
157 |
disk = target_controller.select_initial_disk() |
|
158 |
disks = target_controller.select_disk( |
|
159 |
disks, |
|
160 |
use_whole_disk=False) |
|
161 |
disks = target_controller.add_disk( |
|
162 |
disks, |
|
163 |
use_whole_disk=False) |
|
164 |
disks = target_controller.reset_layout( |
|
165 |
disk=None, |
|
166 |
use_whole_disk=False) |
|
167 |
target_controller.apply_default_layout( |
|
168 |
disk, |
|
169 |
use_whole_disk, |
|
170 |
wipe_disk=False, |
|
171 |
in_zpool=DEFAULT_ZPOOL_NAME, |
|
172 |
in_vdev=DEFAULT_VDEV_NAME) |
|
173 |
swap_type, swap_size, dump_type, dump_size = \ |
|
174 |
target_controller.calc_swap_dump_size( |
|
175 |
installation_size, |
|
176 |
available_size, |
|
177 |
swap_included=False) |
|
178 |
target_controller.setup_vfstab_for_swap( |
|
179 |
pool_name, |
|
180 |
basedir) |
|
181 |
||
182 |
min_size = target_controller.minimum_target_size |
|
183 |
rec_size = target_controller.recommended_target_size |
|
184 |
||
185 |
type = TargetController.SWAP_DUMP_ZVOL |
|
186 |
type = TargetController.SWAP_DUMP_NONE |
|
187 |
''' |
|
188 |
||
189 |
SWAP_DUMP_ZVOL = "ZVOL" |
|
190 |
SWAP_DUMP_NONE = "None" |
|
191 |
||
192 |
#-------------------------------------------------------------------------- |
|
193 |
# Public methods |
|
194 |
||
1355
7e6507b2a970
6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents:
1236
diff
changeset
|
195 |
def __init__(self, doc, debug=False, dry_run=False): |
1112 | 196 |
''' Initializer method. Called by the constructor. |
197 |
||
198 |
Parameters: |
|
199 |
doc. A reference to a DataObjectCache instance where |
|
200 |
TD places details of the "discovered targets" and |
|
201 |
where TC will create the "desired targets" area. |
|
202 |
debug=False. If True, XML is generated for the backup |
|
203 |
area and will get written to logs. |
|
1355
7e6507b2a970
6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents:
1236
diff
changeset
|
204 |
dry_run=False. If True, certain actions will be prevented |
7e6507b2a970
6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents:
1236
diff
changeset
|
205 |
from running so the disks are not modified |
1112 | 206 |
|
207 |
Returns: Nothing |
|
208 |
||
209 |
Raises: Nothing |
|
210 |
''' |
|
211 |
||
212 |
global LOGGER |
|
213 |
LOGGER = logging.getLogger(INSTALL_LOGGER_NAME) |
|
214 |
||
215 |
self._doc = doc |
|
216 |
self._debug = debug |
|
1355
7e6507b2a970
6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents:
1236
diff
changeset
|
217 |
self._dry_run = dry_run |
1112 | 218 |
self._discovered_root = None |
219 |
self._discovered_disks = None |
|
220 |
self._desired_root = None |
|
221 |
self._backup_area = None |
|
222 |
self._need_backup = False |
|
223 |
self._logical = None |
|
224 |
self._zpool = None |
|
225 |
self._vdev = None |
|
226 |
self._be = None |
|
227 |
||
228 |
self._image_size = None |
|
229 |
self._mem_size = None |
|
230 |
self._minimum_target_size = None |
|
231 |
self._recommended_target_size = None |
|
232 |
self._swap_dump_computed = False |
|
233 |
self._swap_type = TargetController.SWAP_DUMP_NONE |
|
234 |
self._swap_size = None |
|
235 |
self._dump_type = TargetController.SWAP_DUMP_NONE |
|
236 |
self._dump_size = None |
|
237 |
||
238 |
self._this_processor = platform.processor() |
|
239 |
||
240 |
super(TargetController, self).__init__() |
|
241 |
||
242 |
def initialize(self, image_size=FALLBACK_IMAGE_SIZE, |
|
243 |
no_initial_logical=False, no_initial_disk=False, |
|
244 |
install_mountpoint="/a", unique_zpool_name=False): |
|
245 |
''' Creates the top-level structure for the "desired targets" area |
|
246 |
in the DOC and, optionally, selects an initial disk to be the |
|
247 |
target for this install. |
|
248 |
||
249 |
The TargetDiscovery checkpoint must have run successfully, |
|
250 |
saving details of the system's storage devices in the |
|
251 |
"discovered targets" area of the DOC, before initialize() |
|
252 |
is called, or an error is raised. |
|
253 |
||
254 |
Parameters: |
|
255 |
image_size=FALLBACK_IMAGE_SIZE. If specified, must be a Size |
|
256 |
object. TC will use this value to compute the minimum |
|
257 |
disk size that can be selected. |
|
258 |
no_initial_logical=False. If set to True, then initialize will |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
259 |
not set up a default rpool structure. Will also ensure |
1112 | 260 |
no default disk is selected. |
261 |
no_initial_disk=False. If set to True, then initialize will |
|
262 |
not select an initial disk. This may be useful for non- |
|
263 |
interactive installers, where they know before calling TC |
|
264 |
which disk(s) they will be installing on. |
|
265 |
install_mountpoint="/a". The mountpoint attribute of the |
|
266 |
created BE will be set to this value. |
|
267 |
unique_zpool_name=False If set to True, will ensure that the name |
|
268 |
of the pool will not match any existing zpools on the system. |
|
269 |
||
270 |
Returns: A list of the initially selected Disks. |
|
271 |
||
272 |
Raises: BadDiskError |
|
273 |
''' |
|
274 |
||
275 |
# Ensure that TD has already been successfully run by searching |
|
276 |
# for a <target name="discovered"> root node in the DOC. Save a |
|
277 |
# reference to this node for future use. |
|
278 |
self._discovered_root = self._doc.persistent.get_first_child( |
|
279 |
name=Target.DISCOVERED) |
|
280 |
if self._discovered_root is None: |
|
281 |
raise BadDiskError("No discovered targets available") |
|
282 |
||
283 |
self._image_size = image_size |
|
284 |
self._mem_size = _get_system_memory() |
|
285 |
# Reset these values to None so they get correctly recomputed |
|
286 |
self._minimum_target_size = None |
|
287 |
self._recommended_target_size = None |
|
288 |
||
289 |
# Clear out any previous "desired targets" from the DOC |
|
290 |
self._doc.persistent.delete_children(name=Target.DESIRED, |
|
291 |
class_type=Target) |
|
292 |
||
293 |
# Create a tree of DataObjects representing the initial |
|
294 |
# top-level nodes of the "desired targets" tree to be created |
|
295 |
# in the DOC. The created tree will be similar to: |
|
296 |
# <target name="desired"> |
|
297 |
# <!-- selected disks will be inserted here --> |
|
298 |
# <logical> |
|
299 |
# <zpool name="rpool" is_root="true"> |
|
300 |
# <vdev name="vdev"/> |
|
301 |
# <be name="solaris" mountpoint="/a"/> |
|
302 |
# </zpool> |
|
303 |
# </logical> |
|
304 |
# </target> |
|
305 |
self._desired_root = Target(Target.DESIRED) |
|
306 |
self._doc.persistent.insert_children(self._desired_root) |
|
307 |
||
308 |
# Return after creating Desired root node |
|
309 |
if no_initial_logical: |
|
310 |
return list() |
|
311 |
||
312 |
self._logical = self.apply_default_logical( |
|
313 |
mountpoint=install_mountpoint, |
|
314 |
unique_zpool_name=unique_zpool_name) |
|
315 |
self._desired_root.insert_children(self._logical) |
|
316 |
||
317 |
if no_initial_disk: |
|
318 |
return list() |
|
319 |
||
320 |
# select an initial disk and return it |
|
321 |
initial_disk = self.select_initial_disk() |
|
322 |
return_disks = self._add_disks([initial_disk], False) |
|
323 |
self._need_backup = True |
|
324 |
return return_disks |
|
325 |
||
326 |
def apply_default_logical(self, logical=None, mountpoint="/a", |
|
327 |
redundancy="none", unique_zpool_name=True): |
|
328 |
''' Create a default logical layout for root pool. |
|
329 |
Only create logical element if not already done so, if not |
|
330 |
none it is assumed this logical contains no children. |
|
331 |
Optionally, ensure root pool name is unique and does not |
|
332 |
exist already. |
|
333 |
''' |
|
334 |
||
335 |
if logical is None: |
|
336 |
logical = Logical(DEFAULT_LOGICAL_NAME) |
|
337 |
||
338 |
self._zpool = logical.add_zpool( |
|
339 |
DEFAULT_ZPOOL_NAME, is_root=True) |
|
340 |
||
341 |
if unique_zpool_name: |
|
342 |
# Ensure this root pool name is unique |
|
343 |
if self._zpool.exists: |
|
344 |
self._zpool._name = self._get_unique_pool_name(self._zpool) |
|
345 |
LOGGER.warning("Default root zpool '%s' exists, Using '%s' " \ |
|
346 |
"instead." % (DEFAULT_ZPOOL_NAME, self._zpool._name)) |
|
347 |
||
348 |
self._vdev = self._zpool.add_vdev(DEFAULT_VDEV_NAME, redundancy) |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
349 |
|
1112 | 350 |
self._be = BE() |
351 |
self._be.mountpoint = mountpoint |
|
352 |
self._zpool.insert_children(self._be) |
|
353 |
||
354 |
return logical |
|
355 |
||
356 |
def select_disk(self, disks, use_whole_disk=False): |
|
357 |
''' Select one or more disks to be used for the install. |
|
358 |
If any disk(s) were previously selected, they will be |
|
359 |
replaced with the newly selected disks. |
|
360 |
||
361 |
Parameters: |
|
362 |
disks, either a single Disk object or a list of Disks |
|
363 |
use_whole_disk=False, specifies whether the selected |
|
364 |
disk(s) are to be used as entire disks or whether |
|
365 |
they will be divided into partitions |
|
366 |
||
367 |
Returns: |
|
368 |
A list containing the selected disk(s). |
|
369 |
||
370 |
Raises: BadDiskError |
|
371 |
''' |
|
372 |
||
373 |
# If initialize() has not already been called, call it. |
|
374 |
# In this situation we do not select an initial disk. |
|
375 |
if self._desired_root is None: |
|
376 |
self.initialize(no_initial_disk=True) |
|
377 |
||
378 |
# param disks can either be a singleton Disk object |
|
379 |
# or a tuple of Disk objects |
|
380 |
if isinstance(disks, Disk): |
|
381 |
disks = [disks] |
|
382 |
||
383 |
disks = self._get_corresponding_discovered_disks(disks) |
|
384 |
self._check_disks_are_suitable(disks) |
|
385 |
||
386 |
previous_disks = self._get_desired_disks() |
|
387 |
||
388 |
# Clear the previously selected disks (if any) from "desired targets" |
|
389 |
self._desired_root.delete_children(class_type=Disk, |
|
390 |
not_found_is_err=False) |
|
391 |
||
392 |
if self._need_backup: |
|
393 |
# Backup the previously selected disks |
|
394 |
self._backup_disks(previous_disks) |
|
395 |
||
396 |
return_disks = self._add_disks(disks, use_whole_disk) |
|
397 |
||
398 |
# If use_whole_disk=False on this call to select_disk(), |
|
399 |
# then we will need to back up the disk layout on the |
|
400 |
# next call to select_disk(). (If use_whole_disk=True, there |
|
401 |
# is no user-defined layout to back up.) |
|
402 |
if use_whole_disk == False: |
|
403 |
self._need_backup = True |
|
404 |
else: |
|
405 |
self._need_backup = False |
|
406 |
||
407 |
return return_disks |
|
408 |
||
409 |
def add_disk(self, disks, use_whole_disk=False): |
|
410 |
''' Add one or more disks to the currently selected disks |
|
411 |
for this install. |
|
412 |
||
413 |
Parameters: |
|
414 |
disks, either a single Disk object or a list of Disks. |
|
415 |
use_whole_disk=False, specifies whether the selected |
|
416 |
disk(s) are to be used as entire disks or whether |
|
417 |
they will be divided into partitions |
|
418 |
||
419 |
Returns: A list containing the added disk(s). |
|
420 |
||
421 |
Raises: BadDiskError |
|
422 |
''' |
|
423 |
||
424 |
# If initialize() has not already been called, call it. |
|
425 |
# In this situation we do not select an initial disk. |
|
426 |
if self._desired_root is None: |
|
427 |
self.initialize(no_initial_disk=True) |
|
428 |
||
429 |
# param disks can either be a singleton Disk object |
|
430 |
# or a list of Disk objects |
|
431 |
if isinstance(disks, Disk): |
|
432 |
disks = [disks] |
|
433 |
||
434 |
disks = self._get_corresponding_discovered_disks(disks) |
|
435 |
self._check_disks_are_suitable(disks) |
|
436 |
||
437 |
# Check that disk(s) being added are not already in "desired targets" |
|
438 |
current_disks = self._get_desired_disks() |
|
439 |
if current_disks is not None: |
|
440 |
for current_disk in current_disks: |
|
441 |
for new_disk in disks: |
|
442 |
if current_disk.name_matches(new_disk): |
|
443 |
raise BadDiskError("Attempt to add same disk twice!") |
|
444 |
||
445 |
return_disks = self._add_disks(disks, use_whole_disk) |
|
446 |
||
447 |
return return_disks |
|
448 |
||
449 |
def reset_layout(self, disk=None, use_whole_disk=False): |
|
450 |
''' Resets the partitioning layout of either all currently |
|
451 |
selected disks, or a specific disk, back to their |
|
452 |
original layout from "discovered targets". However |
|
453 |
for disks that have no usable partitions and/or slices |
|
454 |
the call to apply_default_layout will also reset the |
|
455 |
suggested layout before returning. |
|
456 |
||
457 |
Parameters: |
|
458 |
disk=None. If not given, or None, then all the currently |
|
459 |
selected disks are reset. Otherwise disk must be a |
|
460 |
single Disk object. |
|
461 |
use_whole_disk=False, specifies whether the selected |
|
462 |
disk(s) are to be used as entire disks or whether |
|
463 |
they will be divided into partitions |
|
464 |
||
465 |
Returns: |
|
466 |
A list containing the reset Disks. |
|
467 |
||
468 |
Raises: |
|
469 |
BadDiskError |
|
470 |
''' |
|
471 |
||
472 |
# Ensure initialize() has already been called. |
|
473 |
if self._desired_root is None: |
|
474 |
raise BadDiskError("No selected disks to reset!") |
|
475 |
||
476 |
current_disks = self._get_desired_disks() |
|
477 |
||
478 |
disks = list() |
|
479 |
if disk is None: |
|
480 |
# The user didn't say which disk(s) to reset. So get from |
|
481 |
# the "discovered targets", the disks corresponding to |
|
482 |
# all the currently selected disks |
|
483 |
for current_disk in current_disks: |
|
484 |
for discovered_disk in self.discovered_disks: |
|
485 |
if current_disk.name_matches(discovered_disk): |
|
486 |
disks.append(discovered_disk) |
|
487 |
else: |
|
488 |
disks.append(disk) |
|
489 |
||
490 |
return_disks = list() |
|
491 |
for disk in disks: |
|
492 |
if disk.ctd not in \ |
|
493 |
[disc_disk.ctd for disc_disk in self.discovered_disks]: |
|
494 |
raise BadDiskError( |
|
495 |
"Trying to reset a disk not in discovered targets!") |
|
496 |
||
497 |
# find the disk in the descovered disks |
|
498 |
for disc_disk in self.discovered_disks: |
|
499 |
if disk.ctd == disc_disk.ctd: |
|
500 |
break |
|
501 |
||
502 |
# remove equivalent disk from "desired targets" |
|
503 |
found = False |
|
504 |
for current_disk in current_disks: |
|
505 |
if disk.name_matches(current_disk): |
|
506 |
self._desired_root.delete_children(children=current_disk, |
|
507 |
not_found_is_err=True) |
|
508 |
found = True |
|
509 |
||
510 |
if not found: |
|
511 |
raise BadDiskError("Trying to reset an unselected disk!") |
|
512 |
||
513 |
# re-insert a fresh copy of the disk, with the original |
|
514 |
# layout discovered by TD, into "desired targets". However |
|
515 |
# for disks that have no usable partitions and/or slices |
|
516 |
# the call to apply_default_layout will also reset the |
|
517 |
# suggested layout before returning. |
|
518 |
if disc_disk is not None: |
|
519 |
copy_disk = deepcopy(disc_disk) |
|
520 |
self.apply_default_layout(copy_disk, use_whole_disk, False) |
|
521 |
if self._fixup_disk(copy_disk, use_whole_disk): |
|
522 |
self._desired_root.insert_children(copy_disk, |
|
523 |
before=self._logical) |
|
524 |
return_disks.append(copy_disk) |
|
525 |
||
526 |
return return_disks |
|
527 |
||
528 |
def apply_default_layout(self, disk, use_whole_disk, |
|
529 |
wipe_disk=False, in_zpool=DEFAULT_ZPOOL_NAME, |
|
530 |
in_vdev=DEFAULT_VDEV_NAME): |
|
531 |
''' Attempt to apply the default layout to a disk. |
|
532 |
Only apply to disks if we are not using whole disk. |
|
533 |
||
534 |
If wipe disk specified then delete all existing partition |
|
535 |
and slice information from the disk supplied. |
|
536 |
''' |
|
537 |
||
538 |
if use_whole_disk: |
|
539 |
return |
|
540 |
||
1355
7e6507b2a970
6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents:
1236
diff
changeset
|
541 |
# force a VTOC label and update the disk's geometry and dev_size |
1369
681cdf117ece
7075669 controller.py shouldn't try to relabel a disk already labeled with a VTOC label (fix for unittests)
Drew Fisher <drew.fisher@oracle.com>
parents:
1364
diff
changeset
|
542 |
if disk.label == "VTOC" and not self._dry_run: |
1364
9e621cf78c3d
7075669 controller.py shouldn't try to relabel a disk already labeled with a VTOC label
Drew Fisher <drew.fisher@oracle.com>
parents:
1355
diff
changeset
|
543 |
# look for this disk in the DISCOVERED target tree to see if the |
9e621cf78c3d
7075669 controller.py shouldn't try to relabel a disk already labeled with a VTOC label
Drew Fisher <drew.fisher@oracle.com>
parents:
1355
diff
changeset
|
544 |
# label changed from EFI to VTOC |
1376
1586eba25902
7076343 AI fails in snv_172 in the target-discovery phase
Drew Fisher <drew.fisher@oracle.com>
parents:
1370
diff
changeset
|
545 |
for discovered_disk in self.discovered_disks: |
1364
9e621cf78c3d
7075669 controller.py shouldn't try to relabel a disk already labeled with a VTOC label
Drew Fisher <drew.fisher@oracle.com>
parents:
1355
diff
changeset
|
546 |
if disk.ctd == discovered_disk.ctd: |
9e621cf78c3d
7075669 controller.py shouldn't try to relabel a disk already labeled with a VTOC label
Drew Fisher <drew.fisher@oracle.com>
parents:
1355
diff
changeset
|
547 |
if discovered_disk.label == "GPT": |
9e621cf78c3d
7075669 controller.py shouldn't try to relabel a disk already labeled with a VTOC label
Drew Fisher <drew.fisher@oracle.com>
parents:
1355
diff
changeset
|
548 |
# we need to reset the label |
9e621cf78c3d
7075669 controller.py shouldn't try to relabel a disk already labeled with a VTOC label
Drew Fisher <drew.fisher@oracle.com>
parents:
1355
diff
changeset
|
549 |
disk._set_vtoc_label_and_geometry(self._dry_run) |
1355
7e6507b2a970
6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents:
1236
diff
changeset
|
550 |
|
1112 | 551 |
if wipe_disk: |
552 |
for obj in [Partition, Slice]: |
|
553 |
disk.delete_children(class_type=obj) |
|
554 |
||
555 |
partitions = disk.get_descendants(class_type=Partition) |
|
556 |
slices = disk.get_descendants(class_type=Slice) |
|
557 |
# set the start sector to one cylinder worth of sectors |
|
558 |
start = disk.geometry.cylsize |
|
559 |
slice_size = disk.disk_prop.dev_size.sectors - start |
|
560 |
||
561 |
if not partitions and not slices: |
|
562 |
# We need to add some back in to create the disk set up in such a |
|
563 |
# way that we end up with a bootable pool. |
|
564 |
if self._this_processor == "i386": |
|
565 |
new_partition = disk.add_partition("1", start, slice_size, |
|
566 |
Size.sector_units, partition_type=191, |
|
567 |
bootid=Partition.ACTIVE) |
|
568 |
||
569 |
new_slice = new_partition.add_slice("0", start, slice_size, |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
570 |
Size.sector_units, force=True) |
1112 | 571 |
else: |
572 |
new_slice = disk.add_slice("0", start, slice_size, |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
573 |
Size.sector_units, force=True) |
1236
2f3a9d3aa9cb
7051027 Installer not enabling disk write cache when entire disk selected
Drew Fisher <drew.fisher@oracle.com>
parents:
1204
diff
changeset
|
574 |
|
2f3a9d3aa9cb
7051027 Installer not enabling disk write cache when entire disk selected
Drew Fisher <drew.fisher@oracle.com>
parents:
1204
diff
changeset
|
575 |
# enable the disk's write-cache if wipe_disk is True. |
2f3a9d3aa9cb
7051027 Installer not enabling disk write cache when entire disk selected
Drew Fisher <drew.fisher@oracle.com>
parents:
1204
diff
changeset
|
576 |
if wipe_disk: |
2f3a9d3aa9cb
7051027 Installer not enabling disk write cache when entire disk selected
Drew Fisher <drew.fisher@oracle.com>
parents:
1204
diff
changeset
|
577 |
disk.write_cache = True |
2f3a9d3aa9cb
7051027 Installer not enabling disk write cache when entire disk selected
Drew Fisher <drew.fisher@oracle.com>
parents:
1204
diff
changeset
|
578 |
|
1112 | 579 |
else: |
580 |
# Compile a list of the usable slices, if any |
|
581 |
slice_list = list() |
|
582 |
for slc in slices: |
|
583 |
if slc.name != "2": |
|
584 |
if slc.size >= self.minimum_target_size: |
|
585 |
slice_list.append(slc) |
|
586 |
break |
|
587 |
||
588 |
if self._this_processor == "sparc": |
|
589 |
# No Partitions to look through, just check the slices. |
|
590 |
||
591 |
if slice_list: |
|
592 |
# We have a useable slice already, so nothing more to do |
|
593 |
return |
|
594 |
||
595 |
# No useable slices. Clear the slices and add a root slice |
|
596 |
disk.delete_children(class_type=Slice) |
|
597 |
new_slice = disk.add_slice("0", start, slice_size, |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
598 |
Size.sector_units, force=True) |
1112 | 599 |
else: |
600 |
for partition in partitions: |
|
601 |
if partition.is_solaris and disk.label == "VTOC": |
|
602 |
# Mark partition as ACTIVE to be sure, and change |
|
603 |
# action to create to ensure active flag is set. |
|
604 |
# Create shouldn't change existing VTOC unless the |
|
605 |
# sizes differ for any reason, which they shouldn't |
|
606 |
partition.action = "create" |
|
607 |
if partition.is_primary: |
|
608 |
partition.bootid = Partition.ACTIVE |
|
609 |
||
610 |
if slice_list: |
|
611 |
# We have a useable slice already, so nothing |
|
612 |
# more to do. |
|
613 |
return |
|
614 |
||
615 |
# No useable slices. Clear the slices and add a |
|
616 |
# root slice |
|
617 |
partition.delete_children(class_type=Slice) |
|
618 |
new_slice = partition.add_slice("0", start, |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
619 |
slice_size, Size.sector_units, force=True) |
1112 | 620 |
break |
1113
3d0384a5e577
7042689 slim_unit_tests failure for target controller is broken after 7042578 is put back.
dermotm@brokedown
parents:
1112
diff
changeset
|
621 |
else: |
3d0384a5e577
7042689 slim_unit_tests failure for target controller is broken after 7042578 is put back.
dermotm@brokedown
parents:
1112
diff
changeset
|
622 |
return |
1112 | 623 |
|
624 |
new_slice.tag = V_ROOT |
|
625 |
new_slice.in_vdev = in_vdev |
|
626 |
new_slice.in_zpool = in_zpool |
|
627 |
||
628 |
def select_initial_disk(self): |
|
629 |
''' Iterate through the disks discovered by TD and select |
|
630 |
one of them to be the initial install target. |
|
631 |
||
632 |
Returns: The selected Disk object |
|
633 |
||
1204
5c7590b24780
7050438 Update GUI Install to use CUD
Dermot <Dermot.McCluskey@Oracle.COM>
parents:
1151
diff
changeset
|
634 |
Raises: SubSizeDiskError, BadDiskError |
1112 | 635 |
''' |
636 |
||
637 |
# Check #1 - look for a disk has the disk_keyword "boot_disk" |
|
638 |
# and is big enough |
|
639 |
for disk in self.discovered_disks: |
|
640 |
if disk.is_boot_disk() and self._is_big_enough(disk): |
|
641 |
return disk |
|
642 |
||
643 |
# Check #2 - get 1st disk that is big enough |
|
644 |
for disk in self.discovered_disks: |
|
645 |
if self._is_big_enough(disk): |
|
646 |
return disk |
|
647 |
else: |
|
648 |
raise BadDiskError( |
|
649 |
"None of the available disks are big enough for install!") |
|
650 |
||
651 |
def calc_swap_dump_size(self, installation_size, available_size, |
|
652 |
swap_included=False): |
|
653 |
''' Calculate swap/dump, based on the amount of |
|
654 |
system memory, installation size and available size. |
|
655 |
||
656 |
The following rules are used for determining the type of |
|
657 |
swap to be created, whether swap zvol is required and the |
|
658 |
size of swap to be created. |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
659 |
|
1112 | 660 |
memory type required size |
661 |
-------------------------------------------------- |
|
1370
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
662 |
<900mb zvol yes 1G (MIN_SWAP_SIZE) |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
663 |
900mb-4G zvol no 1G |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
664 |
4G-16G zvol no 2G |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
665 |
16G-128G zvol no 4G |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
666 |
>128G zvol no 4G (MAX_SWAP_SIZE) |
1112 | 667 |
|
668 |
The following rules are used for calculating the amount |
|
669 |
of required space for dump. |
|
670 |
||
671 |
memory type size |
|
672 |
-------------------------------------------------- |
|
673 |
<0.5G zvol 256MB (MIN_DUMP_SIZE) |
|
1370
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
674 |
0.5G-128G zvol 256M-64G (1/2 of memory) |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
675 |
>128G zvol 64G (MAX_DUMP_SIZE) |
1112 | 676 |
|
677 |
If slice/zvol is required, and there's not enough space in the, |
|
678 |
target, an error will be raised. If swap zvol is |
|
1370
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
679 |
not required, spaces in the root pool will first be allocated |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
680 |
for installation data, any left over space up to 80% of |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
681 |
the total root pool size, will be allocated for swap/dump. |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
682 |
This is to make sure that the root pool is less than |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
683 |
80% full. |
1112 | 684 |
|
685 |
Size of all calculation is done in MB |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
686 |
|
1112 | 687 |
Parameters: |
688 |
- installation_size: Size object. The size required for |
|
689 |
the installation |
|
690 |
- available_size: Size object. The available size on the |
|
691 |
target disk. |
|
692 |
- swap_included=False: Boolean. Indicates whether required swap |
|
693 |
space is already included and validated in the installation size. |
|
694 |
||
695 |
Returns: |
|
696 |
Tuple consisting of: |
|
697 |
swap_type, swap_size, dump_type, dump_size |
|
698 |
whose types are: |
|
699 |
string, Size object, string, Size object |
|
700 |
||
701 |
Raise: |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
702 |
SwapDumpSpaceError |
1112 | 703 |
''' |
704 |
||
705 |
if self._swap_dump_computed: |
|
706 |
# Only need to compute these once: |
|
707 |
return(self._swap_type, self._swap_size, self._dump_type, |
|
708 |
self._dump_size) |
|
709 |
||
710 |
if (installation_size > available_size): |
|
711 |
LOGGER.error("Space required for installation: %s", |
|
712 |
installation_size) |
|
713 |
LOGGER.error("Total available space: %s", available_size) |
|
714 |
raise SwapDumpSpaceError |
|
715 |
||
716 |
# Do all calcuations in MB |
|
717 |
installation_size_mb = installation_size.get(units=Size.mb_units) |
|
718 |
available_size_mb = available_size.get(units=Size.mb_units) |
|
719 |
swap_size_mb = self._get_required_swap_size() |
|
720 |
||
721 |
swap_required = False |
|
722 |
if swap_size_mb != 0: |
|
723 |
swap_required = True |
|
724 |
||
725 |
LOGGER.debug("Installation size: %s", installation_size) |
|
726 |
LOGGER.debug("Available size: %s", available_size) |
|
727 |
LOGGER.debug("Memory: %sMB. Swap Required: %s", |
|
728 |
self._mem_size, swap_required) |
|
729 |
||
730 |
if swap_required: |
|
731 |
# Make sure target disk has enough space for both swap and software |
|
732 |
if swap_included: |
|
733 |
required_size_mb = installation_size_mb |
|
734 |
else: |
|
735 |
required_size_mb = installation_size_mb + swap_size_mb |
|
736 |
if (available_size_mb < required_size_mb): |
|
737 |
LOGGER.error("Space required for installation " |
|
738 |
"with required swap: %s", required_size_mb) |
|
739 |
LOGGER.error("Total available space: %s", available_size) |
|
740 |
raise SwapDumpSpaceError |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
741 |
|
1370
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
742 |
# Since ZFS pools perform best when it is less than 80% full, |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
743 |
# specify 80% of available size for dump calculation |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
744 |
dump_size_mb = self._calc_dump_size( |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
745 |
int(available_size_mb * 0.8) - required_size_mb) |
1112 | 746 |
else: |
1370
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
747 |
# Since ZFS pools perform best when it is less than 80% full, |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
748 |
# use 80% of available_size for swap/dump calculation |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
749 |
|
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
750 |
free_space_mb = int(available_size_mb * 0.8) - installation_size_mb |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
751 |
|
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
752 |
if free_space_mb > 0: |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
753 |
swap_size_mb = self._calc_swap_size( |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
754 |
((free_space_mb * MIN_SWAP_SIZE) / |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
755 |
(MIN_SWAP_SIZE + MIN_DUMP_SIZE))) |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
756 |
|
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
757 |
dump_size_mb = self._calc_dump_size( \ |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
758 |
free_space_mb - swap_size_mb) |
1112 | 759 |
|
760 |
self._swap_size = Size(str(swap_size_mb) + Size.mb_units) |
|
761 |
if swap_size_mb > 0: |
|
762 |
self._swap_type = TargetController.SWAP_DUMP_ZVOL |
|
763 |
||
764 |
self._dump_size = Size(str(dump_size_mb) + Size.mb_units) |
|
765 |
if dump_size_mb > 0: |
|
766 |
self._dump_type = TargetController.SWAP_DUMP_ZVOL |
|
767 |
||
768 |
LOGGER.debug("Swap Type: %s", self._swap_type) |
|
769 |
LOGGER.debug("Swap Size: %s", self._swap_size) |
|
770 |
LOGGER.debug("Dump Type: %s", self._dump_type) |
|
771 |
LOGGER.debug("Dump Size: %s", self._dump_size) |
|
772 |
self._swap_dump_computed = True |
|
773 |
||
774 |
return (self._swap_type, self._swap_size, self._dump_type, |
|
775 |
self._dump_size) |
|
776 |
||
777 |
def setup_vfstab_for_swap(self, pool_name, basedir): |
|
778 |
'''Add the swap device to /etc/vfstab. |
|
779 |
''' |
|
780 |
swap_device = self._get_swap_device(pool_name) |
|
781 |
||
782 |
if swap_device is None: |
|
783 |
#nothing to do |
|
784 |
return |
|
785 |
||
786 |
fname = os.path.join(basedir, VFSTAB_FILE) |
|
787 |
try: |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
788 |
with open(fname, 'a+') as vf: |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
789 |
vf.write("%s\t%s\t\t%s\t\t%s\t%s\t%s\t%s\n" % |
1112 | 790 |
(swap_device, "-", "-", "swap", "-", "no", "-")) |
791 |
except IOError, ioe: |
|
792 |
LOGGER.error("Failed to write to %s", fname) |
|
793 |
LOGGER.exception(ioe) |
|
794 |
raise SwapDumpGeneralError |
|
795 |
||
796 |
@property |
|
797 |
def minimum_target_size(self): |
|
798 |
''' The minimum amount of space required for an installation. |
|
799 |
||
800 |
This takes into account MIN_SWAP_SIZE required for |
|
801 |
low-memory system. |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
802 |
|
1112 | 803 |
Returns: Size object |
804 |
''' |
|
805 |
||
806 |
if self._minimum_target_size is None: |
|
807 |
swap_size_mb = self._get_required_swap_size() |
|
808 |
min_size_mb = self._image_size.get(units=Size.mb_units) \ |
|
809 |
+ OVERHEAD + swap_size_mb |
|
810 |
||
811 |
self._minimum_target_size = Size(str(min_size_mb) + Size.mb_units) |
|
812 |
||
813 |
return(self._minimum_target_size) |
|
814 |
||
815 |
@property |
|
816 |
def recommended_target_size(self): |
|
817 |
''' The recommended size to perform an installation. |
|
818 |
||
819 |
This takes into account estimated space to perform an upgrade. |
|
820 |
||
821 |
Returns: Size object |
|
822 |
''' |
|
823 |
||
824 |
if self._recommended_target_size is None: |
|
825 |
rec_size_mb = self.minimum_target_size.get(units=Size.mb_units) \ |
|
826 |
+ FUTURE_UPGRADE_SPACE |
|
827 |
||
828 |
self._recommended_target_size = Size(str(rec_size_mb) \ |
|
829 |
+ Size.mb_units) |
|
830 |
||
831 |
return(self._recommended_target_size) |
|
832 |
||
833 |
#-------------------------------------------------------------------------- |
|
834 |
# Private methods |
|
835 |
def _get_unique_pool_name(self, zpool): |
|
836 |
''' Get the next available pool name that does not exist, via |
|
837 |
appending ascending numbers to end of the zpool.name. |
|
838 |
''' |
|
839 |
||
840 |
ztmp = copy(zpool) |
|
841 |
zcount = 1 |
|
842 |
||
843 |
ztmp._name = zpool.name + str(zcount) |
|
844 |
while ztmp.exists: |
|
845 |
zcount += 1 |
|
846 |
ztmp._name = zpool.name + str(zcount) |
|
847 |
||
848 |
return ztmp.name |
|
849 |
||
850 |
def _add_disks(self, disks, use_whole_disk): |
|
851 |
''' Convenience method called from select_disk, add_disk |
|
852 |
and initialize. |
|
853 |
''' |
|
854 |
||
855 |
# if use_whole_disk is False, then check if there is a backup |
|
856 |
# available for this exact set of disks |
|
857 |
backup = None |
|
858 |
if not use_whole_disk: |
|
859 |
backup = self._fetch_from_backup(disks) |
|
860 |
||
861 |
return_disks = list() |
|
862 |
if backup is not None: |
|
863 |
self._backup_area.delete_children( |
|
864 |
children=backup, |
|
865 |
not_found_is_err=True) |
|
866 |
||
867 |
for disk in backup.disks: |
|
868 |
if self._fixup_disk(disk, use_whole_disk): |
|
869 |
self._desired_root.insert_children(disk, |
|
870 |
before=self._logical) |
|
871 |
return_disks = backup.disks |
|
872 |
else: |
|
873 |
for disk in disks: |
|
874 |
copy_disk = deepcopy(disk) |
|
875 |
self.apply_default_layout(copy_disk, use_whole_disk, False) |
|
876 |
if not self._fixup_disk(copy_disk, use_whole_disk): |
|
877 |
continue |
|
878 |
self._desired_root.insert_children(copy_disk, |
|
879 |
before=self._logical) |
|
880 |
return_disks.append(copy_disk) |
|
881 |
||
882 |
# If there is now 1 disk selected, set the vdev redundancy |
|
883 |
# to "none". Otherwise, set it to "mirror". |
|
884 |
if len(self._get_desired_disks()) == 1: |
|
885 |
self._vdev.redundancy = "none" |
|
886 |
else: |
|
887 |
self._vdev.redundancy = "mirror" |
|
888 |
||
889 |
return return_disks |
|
890 |
||
891 |
def _get_corresponding_discovered_disks(self, disks): |
|
892 |
''' Given a list of Disk object, return the corresponding |
|
893 |
Disks from "desired targets" which represent those same |
|
894 |
disks. |
|
895 |
''' |
|
896 |
||
897 |
return_disks = list() |
|
898 |
for disk in disks: |
|
899 |
found = False |
|
900 |
for discovered_disk in self.discovered_disks: |
|
901 |
if disk == discovered_disk: |
|
902 |
found = True |
|
903 |
return_disks.append(disk) |
|
904 |
break |
|
905 |
if disk.name_matches(discovered_disk): |
|
906 |
found = True |
|
907 |
return_disks.append(discovered_disk) |
|
908 |
break |
|
909 |
if not found: |
|
910 |
raise BadDiskError("No equivalent Disk in discovered targets!") |
|
911 |
||
912 |
return return_disks |
|
913 |
||
914 |
def _check_disks_are_suitable(self, disks): |
|
915 |
''' Convenience method that checks that the passed-in disks |
|
916 |
are all from the "discovered targets" list created by TD |
|
917 |
and that they are all large enough for installing Solaris. |
|
918 |
If either check fails for any disk an exception is raised. |
|
919 |
||
920 |
Returns: nothing |
|
921 |
||
1204
5c7590b24780
7050438 Update GUI Install to use CUD
Dermot <Dermot.McCluskey@Oracle.COM>
parents:
1151
diff
changeset
|
922 |
Raises: SubSizeDiskError, BadDiskError |
1112 | 923 |
''' |
924 |
||
925 |
for disk in disks: |
|
926 |
# confirm that the passed in disks are all from TD list |
|
927 |
# (they must be the actual Disk objects from TD, not copies). |
|
928 |
if disk not in self.discovered_disks: |
|
929 |
raise BadDiskError("Disk is not in discovered targets!") |
|
930 |
||
931 |
if not self._is_big_enough(disk): |
|
1204
5c7590b24780
7050438 Update GUI Install to use CUD
Dermot <Dermot.McCluskey@Oracle.COM>
parents:
1151
diff
changeset
|
932 |
raise SubSizeDiskError("Disk is not big enough for install") |
1112 | 933 |
|
934 |
def _backup_disks(self, disks): |
|
935 |
''' Make a backup of a set of disks. |
|
936 |
||
937 |
If the backup area does not already exist, create it. |
|
938 |
If there is already an older entry in the backup area |
|
939 |
for the exact combination of disks being backed up, |
|
940 |
then delete that backup entry. |
|
941 |
Finally, construct a new backup entry for the passed-in |
|
942 |
disks and save it in the backup area. |
|
943 |
||
944 |
Returns: nothing. |
|
945 |
''' |
|
946 |
||
947 |
if disks is None: |
|
948 |
return |
|
949 |
||
950 |
# If "TargetController data" area does not already exist, create it |
|
951 |
if self._backup_area is None: |
|
952 |
self._backup_area = Target(DATA_AREA_NAME) |
|
953 |
||
954 |
self._doc.persistent.insert_children(self._backup_area) |
|
955 |
||
956 |
# if an older backup of same disk(s) exists, delete it |
|
957 |
backup_entries = self._backup_area.get_children() |
|
958 |
if backup_entries is not None: |
|
959 |
for backup_entry in backup_entries: |
|
960 |
if backup_entry.contains_same_disks(disks): |
|
961 |
self._backup_area.delete_children(children=backup_entry, |
|
962 |
not_found_is_err=True) |
|
963 |
||
964 |
# Construct the new backup entry |
|
965 |
new_backup_entry = TargetControllerBackupEntry("backup") |
|
966 |
new_backup_entry.insert_children(disks) |
|
967 |
||
968 |
self._backup_area.insert_children(new_backup_entry) |
|
969 |
||
970 |
def _fetch_from_backup(self, disks): |
|
971 |
''' Retrieve a list of Disks from the backup area that matches the |
|
972 |
passed-in disks, if such a backup exists. |
|
973 |
||
974 |
Iterates through the backup area, comparing the Disks in each |
|
975 |
backup entry with the list of Disks passed in. If a match |
|
976 |
is found, then return the corresponding list of Disks from |
|
977 |
the backup area. |
|
978 |
||
979 |
The Disks passed in are typically objects taken directly from |
|
980 |
the "discovered targets" area, while the returned Disks are |
|
981 |
copies of those objects containing the most recent layout |
|
982 |
modifications which the user has made for those disks. |
|
983 |
||
984 |
Returns a TargetControllerBackupEntry object if a match is found. |
|
985 |
Otherwise, returns None. |
|
986 |
''' |
|
987 |
||
988 |
if self._backup_area is None: |
|
989 |
return None |
|
990 |
||
991 |
backup_entries = self._backup_area.get_children() |
|
992 |
||
993 |
if backup_entries is None: |
|
994 |
return None |
|
995 |
||
996 |
for backup_entry in backup_entries: |
|
997 |
if backup_entry.contains_same_disks(disks): |
|
998 |
return backup_entry |
|
999 |
||
1000 |
return None |
|
1001 |
||
1002 |
def _fixup_disk(self, disk, use_whole_disk): |
|
1003 |
''' Prepare the passed-in Disk object for placement |
|
1004 |
in the "desired targets" area. |
|
1005 |
||
1006 |
Returns: |
|
1007 |
True if disk or slice successfully setup; |
|
1008 |
False if not. |
|
1009 |
''' |
|
1010 |
||
1011 |
if not use_whole_disk: |
|
1012 |
slices = disk.get_descendants(class_type=Slice) |
|
1013 |
if not slices: |
|
1014 |
if self._vdev is not None: |
|
1015 |
disk.in_vdev = self._vdev.name |
|
1016 |
if self._zpool is not None: |
|
1017 |
disk.in_zpool = self._zpool.name |
|
1018 |
return True |
|
1019 |
else: |
|
1020 |
if len(slices) == 1: |
|
1021 |
# There is only one slice we need to check to see if it's |
|
1022 |
# slice "2". If is it we need to add a slice "0" and set |
|
1023 |
# in_vdev and in_zpool. |
|
1024 |
||
1025 |
# NB: This will need to be updated when GPT is supported |
|
1026 |
||
1027 |
if slices[0].name == "2": |
|
1028 |
# Add a slice |
|
1029 |
start = 1 |
|
1030 |
slice_size = disk.disk_prop.dev_size.sectors - start |
|
1031 |
||
1032 |
# parent will either be a Partition (i386) or a |
|
1033 |
# Slice (sparc) |
|
1034 |
parent = slices[0].parent |
|
1035 |
new_slice = parent.add_slice("0", start, slice_size, |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
1036 |
Size.sector_units, force=True) |
1112 | 1037 |
|
1038 |
new_slice.tag = V_ROOT |
|
1204
5c7590b24780
7050438 Update GUI Install to use CUD
Dermot <Dermot.McCluskey@Oracle.COM>
parents:
1151
diff
changeset
|
1039 |
new_slice.force = True |
1112 | 1040 |
|
1041 |
if self._vdev is not None: |
|
1042 |
new_slice.in_vdev = self._vdev.name |
|
1043 |
if self._zpool is not None: |
|
1044 |
new_slice.in_zpool = self._zpool.name |
|
1045 |
return True |
|
1046 |
else: |
|
1047 |
if self._vdev is not None: |
|
1048 |
slices[0].in_vdev = self._vdev.name |
|
1049 |
if self._zpool is not None: |
|
1050 |
slices[0].in_zpool = self._zpool.name |
|
1051 |
return True |
|
1052 |
else: |
|
1053 |
for nextslice in slices: |
|
1054 |
if nextslice.name != "2" and int(nextslice.name) < 8: |
|
1055 |
# find the first slice that's big enough |
|
1056 |
# and move on |
|
1057 |
if nextslice.size >= self.minimum_target_size: |
|
1058 |
if self._vdev is not None: |
|
1059 |
nextslice.in_vdev = self._vdev.name |
|
1060 |
if self._zpool is not None: |
|
1061 |
nextslice.in_zpool = self._zpool.name |
|
1062 |
return True |
|
1063 |
return False |
|
1064 |
else: |
|
1065 |
new_slice = None |
|
1066 |
# If user requested use_whole_disk, then: |
|
1067 |
# - delete any partitions on the disk |
|
1068 |
# - delete any slices on the disk |
|
1069 |
# - set the whole_disk attribute on the disk |
|
1070 |
||
1071 |
self.apply_default_layout(disk, use_whole_disk=False, |
|
1072 |
wipe_disk=True) |
|
1073 |
# We don't want the whole disk here right now since that |
|
1074 |
# causes zpool create to use an EFI label on the disk which |
|
1075 |
# is not supported by ZFS boot. When EFI support is available |
|
1076 |
# disk.whole_disk should be set to the value of us_whole_disk |
|
1077 |
disk.whole_disk = False |
|
1078 |
||
1079 |
# Set the in_vdev and/or in_zpool attributes |
|
1080 |
slices = disk.get_descendants(name="0", class_type=Slice) |
|
1081 |
if slices: |
|
1082 |
# There should only be one slice with name="0" |
|
1083 |
slice_zero = slices[0] |
|
1084 |
||
1085 |
# Set the in_vdev and/or in_zpool attributes |
|
1086 |
if self._vdev is not None: |
|
1087 |
slice_zero.in_vdev = self._vdev.name |
|
1088 |
if self._zpool is not None: |
|
1089 |
slice_zero.in_zpool = self._zpool.name |
|
1090 |
slice_zero.tag = V_ROOT |
|
1091 |
return True |
|
1092 |
return False |
|
1093 |
||
1094 |
@property |
|
1095 |
def discovered_disks(self): |
|
1096 |
''' Returns a list of the disks discovered by TD.''' |
|
1097 |
||
1098 |
if self._discovered_disks is None: |
|
1099 |
if self._discovered_root is None: |
|
1100 |
return None |
|
1101 |
||
1102 |
self._discovered_disks = self._discovered_root.get_children( |
|
1103 |
class_type=Disk) |
|
1104 |
||
1105 |
return self._discovered_disks |
|
1106 |
||
1107 |
def _get_desired_disks(self): |
|
1108 |
''' Returns the list of disks currently in desired targets.''' |
|
1109 |
||
1110 |
if self._desired_root is None: |
|
1111 |
return None |
|
1112 |
||
1113 |
return self._desired_root.get_children(class_type=Disk) |
|
1114 |
||
1115 |
def _is_big_enough(self, disk): |
|
1116 |
''' Returns True if the passed in Disk is big enough |
|
1117 |
to install Solaris; otherwise returns False. |
|
1118 |
''' |
|
1119 |
||
1120 |
if disk.disk_prop is not None and disk.disk_prop.dev_size is not None: |
|
1121 |
if disk.disk_prop.dev_size >= self.minimum_target_size: |
|
1122 |
return True |
|
1123 |
||
1124 |
return False |
|
1125 |
||
1370
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1126 |
def _calc_swap_size(self, available_space): |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1127 |
''' Calculates size of swap based on amount of |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1128 |
physical memory. |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1129 |
|
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1130 |
The following rule is applied: |
1112 | 1131 |
|
1370
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1132 |
memory swap size |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1133 |
-------------------------------------------------- |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1134 |
<4G 1G |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1135 |
4G-16G 2G |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1136 |
>16G 4G |
1112 | 1137 |
|
1138 |
Parameters: |
|
1139 |
- available_space: Space that can be dedicated to swap (MB) |
|
1140 |
||
1141 |
Returns: |
|
1142 |
size of swap in MB |
|
1143 |
''' |
|
1144 |
||
1145 |
if available_space == 0: |
|
1146 |
return 0 |
|
1147 |
||
1370
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1148 |
if self._mem_size <= (Size("4gb")).get(Size.mb_units): |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1149 |
size = (Size("1gb")).get(Size.mb_units) |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1150 |
elif self._mem_size > (Size("16gb")).get(Size.mb_units): |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1151 |
size = (Size("4gb")).get(Size.mb_units) |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1152 |
else: |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1153 |
size = (Size("2gb")).get(Size.mb_units) |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1154 |
|
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1155 |
if available_space < size: |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1156 |
size = available_space |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1157 |
|
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1158 |
return size |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1159 |
|
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1160 |
def _calc_dump_size(self, available_space): |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1161 |
''' Calculates size of dump based on amount of physical memory. |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1162 |
|
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1163 |
The following rule is applied: |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1164 |
|
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1165 |
memory dump size |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1166 |
-------------------------------------------------- |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1167 |
<0.5G 256mb (MIN_DUMP_SIZE) |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1168 |
0.5-128G 1/2 of memory |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1169 |
>128G 64G (MAX_DUMP_SIZE) |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1170 |
|
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1171 |
If calculated space is more than the available space, |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1172 |
the dump size will be trimmed down to the available space. |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1173 |
|
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1174 |
Parameters: |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1175 |
- available_space: Space that can be dedicated to dump (MB) |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1176 |
|
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1177 |
Returns: |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1178 |
size of dump in MB |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1179 |
''' |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1180 |
|
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1181 |
if available_space == 0: |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1182 |
return 0 |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1183 |
|
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1184 |
if self._mem_size < (Size("0.5gb")).get(Size.mb_units): |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1185 |
size = MIN_DUMP_SIZE |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1186 |
elif self._mem_size > (Size("128gb")).get(Size.mb_units): |
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1187 |
size = MAX_DUMP_SIZE |
1112 | 1188 |
else: |
1189 |
size = self._mem_size / 2 |
|
1190 |
||
1191 |
if available_space < size: |
|
1192 |
size = available_space |
|
1193 |
||
1194 |
return int(size) |
|
1195 |
||
1196 |
def _get_required_swap_size(self): |
|
1197 |
''' Determines whether swap is required. If so, the amount of |
|
1198 |
space used for swap is returned. If swap is not required, |
|
1199 |
0 will be returned. Value returned is in MB. |
|
1200 |
||
1201 |
If system memory is less than 900mb, swap is required. |
|
1370
0e49021cc774
6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents:
1369
diff
changeset
|
1202 |
Minimum required space for swap is MIN_SWAP_SIZE. |
1112 | 1203 |
''' |
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
1204 |
|
1112 | 1205 |
if self._mem_size < ZVOL_REQ_MEM: |
1206 |
return MIN_SWAP_SIZE |
|
1207 |
||
1208 |
return 0 |
|
1209 |
||
1210 |
def _get_swap_device(self, pool_name): |
|
1211 |
''' Return the string representing the device used for swap ''' |
|
1212 |
if self._swap_type == TargetController.SWAP_DUMP_ZVOL: |
|
1213 |
return "/dev/zvol/dsk/" + pool_name + "/swap" |
|
1214 |
||
1215 |
return None |
|
1216 |
||
1217 |
||
1218 |
class TargetControllerBackupEntry(SimpleXmlHandlerBase): |
|
1219 |
''' This class is only used within the TargetController class. |
|
1220 |
||
1221 |
Class for storing backups of previously selected |
|
1222 |
disks, so that they can be retrieved, with any |
|
1223 |
layout changes that the user has made, if those |
|
1224 |
disks are selected again. |
|
1225 |
||
1226 |
Each backup entry consists of a top-level object |
|
1227 |
plus a unique conbination of one or more disk |
|
1228 |
objects, which are stored as its children. |
|
1229 |
||
1230 |
Only a unique conbination of selected disks can be |
|
1231 |
restored: eg if the user had previously selected |
|
1232 |
a disk on its own and is now selecting that disk |
|
1233 |
as part of a tuple of disks, the backup will not |
|
1234 |
be retrieved. |
|
1235 |
||
1236 |
This is a sub-class of SimpleXmlHandlerBase, meaning |
|
1237 |
it can be stored in the DOC. |
|
1238 |
''' |
|
1239 |
||
1240 |
# SimpleXmlHandlerBase class requires that this be redefined |
|
1241 |
TAG_NAME = "backup_entry" |
|
1242 |
||
1243 |
def __init__(self, name): |
|
1244 |
''' Initializer method.''' |
|
1245 |
super(TargetControllerBackupEntry, self).__init__(name) |
|
1246 |
||
1247 |
@property |
|
1248 |
def disks(self): |
|
1249 |
''' Returns all the children objects, which will always be disks.''' |
|
1250 |
return self.get_children(not_found_is_err=True) |
|
1251 |
||
1252 |
def contains_same_disks(self, disks): |
|
1253 |
''' Returns True if this objects's children represent |
|
1254 |
the same list of Disks as the list of Disks passed in. |
|
1255 |
||
1256 |
Otherwise, returns False. |
|
1257 |
||
1258 |
Disks being the "same" means the current object and the |
|
1259 |
passed-in list contain the same number of Disks and each |
|
1260 |
of the passed-in Disks has the same identifier as one |
|
1261 |
of the current object's Disks. |
|
1262 |
''' |
|
1263 |
||
1264 |
backup_entry_disks = self.disks |
|
1265 |
||
1266 |
if len(backup_entry_disks) != len(disks): |
|
1267 |
return False |
|
1268 |
||
1269 |
for disk in disks: |
|
1270 |
found = False |
|
1271 |
for backup_disk in backup_entry_disks: |
|
1272 |
if disk.name_matches(backup_disk): |
|
1273 |
found = True |
|
1274 |
if not found: |
|
1275 |
return False |
|
1276 |
||
1277 |
return True |
|
1278 |
||
1279 |
#------------------------------------------------------------------------------ |
|
1280 |
# Module private functions |
|
1281 |
||
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1140
diff
changeset
|
1282 |
|
1112 | 1283 |
def _get_system_memory(): |
1284 |
''' Returns the amount of memory available in the system ''' |
|
1285 |
||
1286 |
memory_size = 0 |
|
1287 |
||
1288 |
p = Popen.check_call(["/usr/sbin/prtconf"], stdout=Popen.STORE, |
|
1289 |
stderr=Popen.STORE, logger=LOGGER) |
|
1290 |
for line in p.stdout.splitlines(): |
|
1291 |
if "Memory size" in line: |
|
1292 |
memory_size = int(line.split()[2]) |
|
1293 |
break |
|
1294 |
||
1295 |
if memory_size <= 0: |
|
1296 |
# We should have a valid size now |
|
1297 |
LOGGER.error("Unable to determine amount of system memory") |
|
1298 |
raise SwapDumpGeneralError |
|
1299 |
||
1300 |
return memory_size |