Class: Yast::AutoinstDriveClass
- Inherits:
-
Module
- Object
- Module
- Yast::AutoinstDriveClass
- Defined in:
- ../../src/modules/AutoinstDrive.rb
Instance Method Summary (collapse)
-
- (Object) addPartition(drive, partition)
Add a partition to a drive.
- - (Object) areEqual(d1, d2)
-
- (Object) createTree(drive)
Create tree representation of drive for the tree widget.
-
- (Object) Export(drive)
Export the DriveT to the generic map representation used by autoyast.
-
- (Object) getNextAvailablePartitionNumber(drive)
Return lowest partition number not already in use.
-
- (Object) getNodeName(drive, enableHTML)
Construct node name for display in tree.
-
- (String) getNodeReference(drive)
Construct reference to drive for use in tree.
-
- (Object) getPartition(drive, idx)
Get partition identified by idx from drive.
-
- (Object) getPartitionCount(drive)
Returns number of partitions on spcified drive.
- - (Object) hasValidType(field, value)
-
- (Object) isDrive(drive)
Convenience wrappers for more general object predicates.
- - (Object) isField(field)
-
- (Object) isValidDiskType(type)
Determine if type is a valid drive type.
- - (Object) main
-
- (Object) new(name, type)
Constructor Constructs a new drive of type type with “device” set to name.
-
- (Object) parseDrive(drive)
Import a generic drive map and create DriveT from it.
-
- (Object) removePartition(drive, idx)
Remove partition from drive.
-
- (Object) set(drive, field, value)
Set field on drive to value.
-
- (Object) updatePartition(drive, idx, partition)
Update partition on drive.
Instance Method Details
- (Object) addPartition(drive, partition)
Add a partition to a drive.
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File '../../src/modules/AutoinstDrive.rb', line 242 def addPartition(drive, partition) drive = deep_copy(drive) partition = deep_copy(partition) if AutoinstPartition.isPartition(partition) partitionList = Ops.get_list(drive, "partitions", []) # TODO: which constraints are on inserting? partitionList = Builtins.add(partitionList, partition) return Builtins.add(drive, "partitions", partitionList) else Builtins.y2error("No valid partition: '%1'", partition) end nil end |
- (Object) areEqual(d1, d2)
93 94 95 96 97 |
# File '../../src/modules/AutoinstDrive.rb', line 93 def areEqual(d1, d2) d1 = deep_copy(d1) d2 = deep_copy(d2) AutoinstCommon.areEqual(d1, d2) end |
- (Object) createTree(drive)
Create tree representation of drive for the tree widget.
top node and all partitions as children.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File '../../src/modules/AutoinstDrive.rb', line 158 def createTree(drive) drive = deep_copy(drive) partitions = Ops.get_list(drive, "partitions", []) partitionTerms = [] part_id = 0 driveRef = getNodeReference(drive) if Ops.greater_than(Builtins.size(partitions), 0) Builtins.foreach(partitions) do |p| partitionTerms = Builtins.add( partitionTerms, AutoinstPartition.createTree(p, driveRef, part_id) ) part_id = Ops.add(part_id, 1) end end createTreeNode(driveRef, getNodeName(drive, false), partitionTerms) end |
- (Object) Export(drive)
Export the DriveT to the generic map representation used by autoyast. Filters out our surrogate id.
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File '../../src/modules/AutoinstDrive.rb', line 369 def Export(drive) drive = deep_copy(drive) # get rid of id exportDrive = Builtins.remove(drive, "_id") # translate e.g. `all to "all" Ops.set( exportDrive, "use", symbol2string(Ops.get_symbol(exportDrive, "use", :Empty)) ) # let AutoinstPartition do it's own filtering Ops.set( exportDrive, "partitions", Builtins.maplist(Ops.get_list(exportDrive, "partitions", [])) do |part| AutoinstPartition.exportPartition(part) end ) deep_copy(exportDrive) end |
- (Object) getNextAvailablePartitionNumber(drive)
Return lowest partition number not already in use.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File '../../src/modules/AutoinstDrive.rb', line 212 def getNextAvailablePartitionNumber(drive) drive = deep_copy(drive) usedPartitionNumbers = [] # gather all used numbers Builtins.foreach(Ops.get_list(drive, "partitions", [])) do |part| partitionNumber = Ops.get_integer(part, "partition_nr", 999) if partitionNumber != 999 usedPartitionNumbers = Builtins.add( usedPartitionNumbers, partitionNumber ) end end newPartitionNumber = 1 # then look for the lowest number not used while Builtins.contains(usedPartitionNumbers, newPartitionNumber) newPartitionNumber = Ops.add(newPartitionNumber, 1) end newPartitionNumber end |
- (Object) getNodeName(drive, enableHTML)
Construct node name for display in tree.
Constructed names are of the form: "<device name> - drive,volgroup
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File '../../src/modules/AutoinstDrive.rb', line 123 def getNodeName(drive, enableHTML) drive = deep_copy(drive) nodeName = Ops.get_string(drive, "device", "") nodeName = Builtins.sformat("<b>%1</b>", nodeName) if enableHTML description = _(" - Drive") driveType = Ops.get_symbol(drive, "type", :CT_DISK) if driveType != :CT_DISK # volume group description = _(" - Volume group") description = Ops.add( Ops.add(description, ", "), removePrefix(symbol2string(driveType), "CT_") ) else # physical drive useTypeDesc = Ops.get_boolean(drive, "initialize", true) ? "initialize" : "reuse" if enableHTML description = Builtins.sformat( "%1 to be %2d", description, useTypeDesc ) else description = Builtins.sformat("%1 , %2", description, useTypeDesc) end end Ops.add(nodeName, description) end |
- (String) getNodeReference(drive)
Construct reference to drive for use in tree. The references are of the form: "drive,volgroup_<id>", e.g. "drive_1", or "volgroup_3"
107 108 109 110 111 112 113 |
# File '../../src/modules/AutoinstDrive.rb', line 107 def getNodeReference(drive) drive = deep_copy(drive) dev_id = Ops.get_integer(drive, "_id", 999) ref = "drive_" ref = "volgroup_" if Ops.get_symbol(drive, "type", :CT_DISK) != :CT_DISK Ops.add(ref, Builtins.tostring(dev_id)) end |
- (Object) getPartition(drive, idx)
Get partition identified by idx from drive.
CAUTION: Indexes may be invalidated by modifications of the partition list on a drive.
183 184 185 186 187 188 189 190 191 192 193 |
# File '../../src/modules/AutoinstDrive.rb', line 183 def getPartition(drive, idx) drive = deep_copy(drive) result = {} if isDrive(drive) partList = Ops.get_list(drive, "partitions", []) result = Ops.get(partList, idx, {}) else Builtins.y2error("Invalid drive: '%1'.", drive) end deep_copy(result) end |
- (Object) getPartitionCount(drive)
Returns number of partitions on spcified drive.
201 202 203 204 |
# File '../../src/modules/AutoinstDrive.rb', line 201 def getPartitionCount(drive) drive = deep_copy(drive) Builtins.size(Ops.get_list(drive, "partitions", [])) end |
- (Object) hasValidType(field, value)
89 90 91 92 |
# File '../../src/modules/AutoinstDrive.rb', line 89 def hasValidType(field, value) value = deep_copy(value) AutoinstCommon.hasValidType(@fields, field, value) end |
- (Object) isDrive(drive)
Convenience wrappers for more general object predicates
82 83 84 85 |
# File '../../src/modules/AutoinstDrive.rb', line 82 def isDrive(drive) drive = deep_copy(drive) AutoinstCommon.isValidObject(@fields, drive) end |
- (Object) isField(field)
86 87 88 |
# File '../../src/modules/AutoinstDrive.rb', line 86 def isField(field) AutoinstCommon.isValidField(@fields, field) end |
- (Object) isValidDiskType(type)
Determine if type is a valid drive type.
48 49 50 |
# File '../../src/modules/AutoinstDrive.rb', line 48 def isValidDiskType(type) Builtins.contains(@diskTypes, type) end |
- (Object) main
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File '../../src/modules/AutoinstDrive.rb', line 13 def main Yast.import "UI" Yast.include self, "autoinstall/types.rb" Yast.include self, "autoinstall/common.rb" Yast.include self, "autoinstall/tree.rb" Yast.import "AutoinstCommon" Yast.import "AutoinstPartition" textdomain "autoinst" # Structure of a drive, or volume group. @fields = { "_id" => 0, # Internal id; won't appear in XML "device" => "", # device name (e.g. "/dev/hda") "initialize" => true, # wipe out disk "partitions" => [], # list of partitions on this drive "type" => :CT_DISK, # type of drive, see diskTypes below "use" => :all, # `all, `linux, `free, or list of partition numbers to use "pesize" => "" } # size of physical extents (currently no GUI support for this setting) # Every drive created gets an id. @_id = 0 # List of allowd disk/drive types @diskTypes = [:CT_DISK, :CT_LVM, :CT_MD, :CT_NFS] end |
- (Object) new(name, type)
Constructor Constructs a new drive of type type with "device" set to name.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File '../../src/modules/AutoinstDrive.rb', line 68 def new(name, type) if !isValidDiskType(type) Builtins.y2warning( "Invalid disk type: '%1'. Defaulting to CT_DISK", type ) type = :CT_DISK end result = set(set(set(@fields, "device", name), "_id", @_id), "type", type) @_id = Ops.add(@_id, 1) deep_copy(result) end |
- (Object) parseDrive(drive)
Import a generic drive map and create DriveT from it. Called by AutoinstPartPlan::Import().
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File '../../src/modules/AutoinstDrive.rb', line 332 def parseDrive(drive) drive = deep_copy(drive) newDrive = new("auto", Ops.get_symbol(drive, "type", :CT_DISK)) newDrive = set( newDrive, "device", Ops.get_string(drive, "device", "auto") ) newDrive = set( newDrive, "initialize", Ops.get_boolean(drive, "initialize", true) ) newDrive = set( newDrive, "use", string2symbol(Ops.get_string(drive, "use", "all")) ) newDrive = set(newDrive, "pesize", Ops.get_string(drive, "pesize", "")) Builtins.foreach(Ops.get_list(drive, "partitions", [])) do |part| newPart = AutoinstPartition.parsePartition(part) if AutoinstPartition.isPartition(newPart) newDrive = addPartition(newDrive, newPart) else Builtins.y2error("Couldn't construct PartitionT from '%1'", part) end end deep_copy(newDrive) end |
- (Object) removePartition(drive, idx)
Remove partition from drive.
index).
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File '../../src/modules/AutoinstDrive.rb', line 300 def removePartition(drive, idx) drive = deep_copy(drive) if isDrive(drive) partitionList = Ops.get_list(drive, "partitions", []) if Ops.less_than(idx, Builtins.size(partitionList)) partitionList = Builtins.remove(partitionList, idx) return Builtins.add(drive, "partitions", partitionList) else Builtins.y2error( "Cannot remove partition '%1', index out of bounds. Drive has only '%2' partitions", idx, Builtins.size(partitionList) ) end else Builtins.y2error( "Cannot remove partition '%1' from invalid drive '%2'.", idx, drive ) end nil end |
- (Object) set(drive, field, value)
Set field on drive to value. Convenience wrapper for generic setter.
57 58 59 60 61 |
# File '../../src/modules/AutoinstDrive.rb', line 57 def set(drive, field, value) drive = deep_copy(drive) value = deep_copy(value) AutoinstCommon.set(@fields, drive, field, value) end |
- (Object) updatePartition(drive, idx, partition)
Update partition on drive.
index).
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File '../../src/modules/AutoinstDrive.rb', line 267 def updatePartition(drive, idx, partition) drive = deep_copy(drive) partition = deep_copy(partition) if isDrive(drive) if AutoinstPartition.isPartition(partition) partitionList = Ops.get_list(drive, "partitions", []) if Ops.less_than(idx, Builtins.size(partitionList)) Ops.set(partitionList, idx, partition) return Builtins.add(drive, "partitions", partitionList) else Builtins.y2error( "Index '%1' out of bounds. Drive has only '%2' partitions.", idx, Builtins.size(partitionList) ) end else Builtins.y2error("No valid partition: '%1'.", partition) end else Builtins.y2error("No valid drive '%1'.", drive) end deep_copy(drive) end |