Revision a0c3fea1
b/daemons/ganeti-noded | ||
---|---|---|
80 | 80 |
# the new block devices -------------------------- |
81 | 81 |
|
82 | 82 |
def perspective_blockdev_create(self, params): |
83 |
bdev_s, size, on_primary = params |
|
83 |
bdev_s, size, on_primary, info = params
|
|
84 | 84 |
bdev = objects.ConfigObject.Loads(bdev_s) |
85 | 85 |
if bdev is None: |
86 | 86 |
raise ValueError("can't unserialize data!") |
87 |
return backend.CreateBlockDevice(bdev, size, on_primary) |
|
88 |
|
|
87 |
return backend.CreateBlockDevice(bdev, size, on_primary, info) |
|
89 | 88 |
|
90 | 89 |
def perspective_blockdev_remove(self, params): |
91 | 90 |
bdev_s = params[0] |
92 | 91 |
bdev = objects.ConfigObject.Loads(bdev_s) |
93 | 92 |
return backend.RemoveBlockDevice(bdev) |
94 | 93 |
|
95 |
|
|
96 | 94 |
def perspective_blockdev_assemble(self, params): |
97 | 95 |
bdev_s, on_primary = params |
98 | 96 |
bdev = objects.ConfigObject.Loads(bdev_s) |
... | ... | |
100 | 98 |
raise ValueError("can't unserialize data!") |
101 | 99 |
return backend.AssembleBlockDevice(bdev, on_primary) |
102 | 100 |
|
103 |
|
|
104 | 101 |
def perspective_blockdev_shutdown(self, params): |
105 | 102 |
bdev_s = params[0] |
106 | 103 |
bdev = objects.ConfigObject.Loads(bdev_s) |
... | ... | |
108 | 105 |
raise ValueError("can't unserialize data!") |
109 | 106 |
return backend.ShutdownBlockDevice(bdev) |
110 | 107 |
|
111 |
|
|
112 | 108 |
def perspective_blockdev_addchild(self, params): |
113 | 109 |
bdev_s, ndev_s = params |
114 | 110 |
bdev = objects.ConfigObject.Loads(bdev_s) |
... | ... | |
117 | 113 |
raise ValueError("can't unserialize data!") |
118 | 114 |
return backend.MirrorAddChild(bdev, ndev) |
119 | 115 |
|
120 |
|
|
121 | 116 |
def perspective_blockdev_removechild(self, params): |
122 | 117 |
bdev_s, ndev_s = params |
123 | 118 |
bdev = objects.ConfigObject.Loads(bdev_s) |
b/lib/backend.py | ||
---|---|---|
534 | 534 |
return True |
535 | 535 |
|
536 | 536 |
|
537 |
def CreateBlockDevice(disk, size, on_primary): |
|
537 |
def CreateBlockDevice(disk, size, on_primary, info):
|
|
538 | 538 |
"""Creates a block device for an instance. |
539 | 539 |
|
540 | 540 |
Args: |
... | ... | |
578 | 578 |
device.SetSyncSpeed(constants.SYNC_SPEED) |
579 | 579 |
if on_primary or disk.OpenOnSecondary(): |
580 | 580 |
device.Open(force=True) |
581 |
|
|
582 |
device.SetInfo(info) |
|
583 |
|
|
581 | 584 |
physical_id = device.unique_id |
582 | 585 |
return physical_id |
583 | 586 |
|
b/lib/bdev.py | ||
---|---|---|
258 | 258 |
return min_percent, max_time, is_degraded |
259 | 259 |
|
260 | 260 |
|
261 |
def SetInfo(self, text): |
|
262 |
"""Update metadata with info text. |
|
263 |
|
|
264 |
Only supported for some device types. |
|
265 |
|
|
266 |
""" |
|
267 |
for child in self._children: |
|
268 |
child.SetInfo(text) |
|
269 |
|
|
270 |
|
|
261 | 271 |
def __repr__(self): |
262 | 272 |
return ("<%s: unique_id: %s, children: %s, %s:%s, %s>" % |
263 | 273 |
(self.__class__, self.unique_id, self._children, |
... | ... | |
477 | 487 |
return snap_name |
478 | 488 |
|
479 | 489 |
|
490 |
def SetInfo(self, text): |
|
491 |
"""Update metadata with info text. |
|
492 |
|
|
493 |
""" |
|
494 |
BlockDev.SetInfo(self, text) |
|
495 |
|
|
496 |
# Replace invalid characters |
|
497 |
text = re.sub('^[^A-Za-z0-9_+.]', '_', text) |
|
498 |
text = re.sub('[^-A-Za-z0-9_+.]', '_', text) |
|
499 |
|
|
500 |
# Only up to 128 characters are allowed |
|
501 |
text = text[:128] |
|
502 |
|
|
503 |
result = utils.RunCmd(["lvchange", "--addtag", text, |
|
504 |
self.dev_path]) |
|
505 |
if result.failed: |
|
506 |
raise errors.BlockDeviceError, ("Command: %s error: %s" % |
|
507 |
(result.cmd, result.fail_reason)) |
|
508 |
|
|
509 |
|
|
480 | 510 |
class MDRaid1(BlockDev): |
481 | 511 |
"""raid1 device implemented via md. |
482 | 512 |
|
b/lib/cmdlib.py | ||
---|---|---|
2253 | 2253 |
(instance.name, target_node)) |
2254 | 2254 |
|
2255 | 2255 |
|
2256 |
def _CreateBlockDevOnPrimary(cfg, node, device): |
|
2256 |
def _CreateBlockDevOnPrimary(cfg, node, device, info):
|
|
2257 | 2257 |
"""Create a tree of block devices on the primary node. |
2258 | 2258 |
|
2259 | 2259 |
This always creates all devices. |
... | ... | |
2261 | 2261 |
""" |
2262 | 2262 |
if device.children: |
2263 | 2263 |
for child in device.children: |
2264 |
if not _CreateBlockDevOnPrimary(cfg, node, child): |
|
2264 |
if not _CreateBlockDevOnPrimary(cfg, node, child, info):
|
|
2265 | 2265 |
return False |
2266 | 2266 |
|
2267 | 2267 |
cfg.SetDiskID(device, node) |
2268 |
new_id = rpc.call_blockdev_create(node, device, device.size, True) |
|
2268 |
new_id = rpc.call_blockdev_create(node, device, device.size, True, info)
|
|
2269 | 2269 |
if not new_id: |
2270 | 2270 |
return False |
2271 | 2271 |
if device.physical_id is None: |
... | ... | |
2273 | 2273 |
return True |
2274 | 2274 |
|
2275 | 2275 |
|
2276 |
def _CreateBlockDevOnSecondary(cfg, node, device, force): |
|
2276 |
def _CreateBlockDevOnSecondary(cfg, node, device, force, info):
|
|
2277 | 2277 |
"""Create a tree of block devices on a secondary node. |
2278 | 2278 |
|
2279 | 2279 |
If this device type has to be created on secondaries, create it and |
... | ... | |
2286 | 2286 |
force = True |
2287 | 2287 |
if device.children: |
2288 | 2288 |
for child in device.children: |
2289 |
if not _CreateBlockDevOnSecondary(cfg, node, child, force): |
|
2289 |
if not _CreateBlockDevOnSecondary(cfg, node, child, force, info):
|
|
2290 | 2290 |
return False |
2291 | 2291 |
|
2292 | 2292 |
if not force: |
2293 | 2293 |
return True |
2294 | 2294 |
cfg.SetDiskID(device, node) |
2295 |
new_id = rpc.call_blockdev_create(node, device, device.size, False) |
|
2295 |
new_id = rpc.call_blockdev_create(node, device, device.size, False, info)
|
|
2296 | 2296 |
if not new_id: |
2297 | 2297 |
return False |
2298 | 2298 |
if device.physical_id is None: |
... | ... | |
2394 | 2394 |
return disks |
2395 | 2395 |
|
2396 | 2396 |
|
2397 |
def _GetInstanceInfoText(instance): |
|
2398 |
return "originstname+%s" % instance.name |
|
2399 |
|
|
2400 |
|
|
2397 | 2401 |
def _CreateDisks(cfg, instance): |
2398 | 2402 |
"""Create all disks for an instance. |
2399 | 2403 |
|
... | ... | |
2406 | 2410 |
True or False showing the success of the creation process |
2407 | 2411 |
|
2408 | 2412 |
""" |
2413 |
info = _GetInstanceInfoText(instance) |
|
2414 |
|
|
2409 | 2415 |
for device in instance.disks: |
2410 | 2416 |
logger.Info("creating volume %s for instance %s" % |
2411 | 2417 |
(device.iv_name, instance.name)) |
2412 | 2418 |
#HARDCODE |
2413 | 2419 |
for secondary_node in instance.secondary_nodes: |
2414 |
if not _CreateBlockDevOnSecondary(cfg, secondary_node, device, False): |
|
2420 |
if not _CreateBlockDevOnSecondary(cfg, secondary_node, device, False, |
|
2421 |
info): |
|
2415 | 2422 |
logger.Error("failed to create volume %s (%s) on secondary node %s!" % |
2416 | 2423 |
(device.iv_name, device, secondary_node)) |
2417 | 2424 |
return False |
2418 | 2425 |
#HARDCODE |
2419 |
if not _CreateBlockDevOnPrimary(cfg, instance.primary_node, device): |
|
2426 |
if not _CreateBlockDevOnPrimary(cfg, instance.primary_node, device, info):
|
|
2420 | 2427 |
logger.Error("failed to create volume %s on primary!" % |
2421 | 2428 |
device.iv_name) |
2422 | 2429 |
return False |
... | ... | |
2854 | 2861 |
|
2855 | 2862 |
logger.Info("adding new mirror component on secondary") |
2856 | 2863 |
#HARDCODE |
2857 |
if not _CreateBlockDevOnSecondary(self.cfg, remote_node, new_drbd, False): |
|
2864 |
if not _CreateBlockDevOnSecondary(self.cfg, remote_node, new_drbd, False, |
|
2865 |
_GetInstanceInfoText(instance)): |
|
2858 | 2866 |
raise errors.OpExecError, ("Failed to create new component on secondary" |
2859 | 2867 |
" node %s" % remote_node) |
2860 | 2868 |
|
2861 | 2869 |
logger.Info("adding new mirror component on primary") |
2862 | 2870 |
#HARDCODE |
2863 |
if not _CreateBlockDevOnPrimary(self.cfg, instance.primary_node, new_drbd): |
|
2871 |
if not _CreateBlockDevOnPrimary(self.cfg, instance.primary_node, new_drbd, |
|
2872 |
_GetInstanceInfoText(instance)): |
|
2864 | 2873 |
# remove secondary dev |
2865 | 2874 |
self.cfg.SetDiskID(new_drbd, remote_node) |
2866 | 2875 |
rpc.call_blockdev_remove(remote_node, new_drbd) |
... | ... | |
3053 | 3062 |
logger.Info("adding new mirror component on secondary for %s" % |
3054 | 3063 |
dev.iv_name) |
3055 | 3064 |
#HARDCODE |
3056 |
if not _CreateBlockDevOnSecondary(cfg, remote_node, new_drbd, False): |
|
3065 |
if not _CreateBlockDevOnSecondary(cfg, remote_node, new_drbd, False, |
|
3066 |
_GetInstanceInfoText(instance)): |
|
3057 | 3067 |
raise errors.OpExecError, ("Failed to create new component on" |
3058 | 3068 |
" secondary node %s\n" |
3059 | 3069 |
"Full abort, cleanup manually!" % |
... | ... | |
3061 | 3071 |
|
3062 | 3072 |
logger.Info("adding new mirror component on primary") |
3063 | 3073 |
#HARDCODE |
3064 |
if not _CreateBlockDevOnPrimary(cfg, instance.primary_node, new_drbd): |
|
3074 |
if not _CreateBlockDevOnPrimary(cfg, instance.primary_node, new_drbd, |
|
3075 |
_GetInstanceInfoText(instance)): |
|
3065 | 3076 |
# remove secondary dev |
3066 | 3077 |
cfg.SetDiskID(new_drbd, remote_node) |
3067 | 3078 |
rpc.call_blockdev_remove(remote_node, new_drbd) |
b/lib/rpc.py | ||
---|---|---|
452 | 452 |
return c.getresult() |
453 | 453 |
|
454 | 454 |
|
455 |
def call_blockdev_create(node, bdev, size, on_primary): |
|
455 |
def call_blockdev_create(node, bdev, size, on_primary, info):
|
|
456 | 456 |
"""Request creation of a given block device. |
457 | 457 |
|
458 | 458 |
This is a single-node call. |
459 | 459 |
|
460 | 460 |
""" |
461 |
params = [bdev.Dumps(), size, on_primary] |
|
461 |
params = [bdev.Dumps(), size, on_primary, info]
|
|
462 | 462 |
c = Client("blockdev_create", params) |
463 | 463 |
c.connect(node) |
464 | 464 |
c.run() |
Also available in: Unified diff