Revision 5c947f38 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
3506 | 3506 |
if not rpc.call_export_remove(node, instance.name): |
3507 | 3507 |
logger.Error("could not remove older export for instance %s" |
3508 | 3508 |
" on node %s" % (instance.name, node)) |
3509 |
|
|
3510 |
|
|
3511 |
class TagsLU(NoHooksLU): |
|
3512 |
"""Generic tags LU. |
|
3513 |
|
|
3514 |
This is an abstract class which is the parent of all the other tags LUs. |
|
3515 |
|
|
3516 |
""" |
|
3517 |
def CheckPrereq(self): |
|
3518 |
"""Check prerequisites. |
|
3519 |
|
|
3520 |
""" |
|
3521 |
if self.op.kind == constants.TAG_CLUSTER: |
|
3522 |
self.target = self.cfg.GetClusterInfo() |
|
3523 |
elif self.op.kind == constants.TAG_NODE: |
|
3524 |
name = self.cfg.ExpandNodeName(self.op.name) |
|
3525 |
if name is None: |
|
3526 |
raise errors.OpPrereqError, ("Invalid node name (%s)" % |
|
3527 |
(self.op.name,)) |
|
3528 |
self.op.name = name |
|
3529 |
self.target = self.cfg.GetNodeInfo(name) |
|
3530 |
elif self.op.kind == constants.TAG_INSTANCE: |
|
3531 |
name = self.cfg.ExpandInstanceName(name) |
|
3532 |
if name is None: |
|
3533 |
raise errors.OpPrereqError, ("Invalid instance name (%s)" % |
|
3534 |
(self.op.name,)) |
|
3535 |
self.op.name = name |
|
3536 |
self.target = self.cfg.GetInstanceInfo(name) |
|
3537 |
else: |
|
3538 |
raise errors.OpPrereqError, ("Wrong tag type requested (%s)" % |
|
3539 |
str(self.op.kind)) |
|
3540 |
|
|
3541 |
|
|
3542 |
class LUGetTags(TagsLU): |
|
3543 |
"""Returns the tags of a given object. |
|
3544 |
|
|
3545 |
""" |
|
3546 |
_OP_REQP = ["kind", "name"] |
|
3547 |
|
|
3548 |
def Exec(self, feedback_fn): |
|
3549 |
"""Returns the tag list. |
|
3550 |
|
|
3551 |
""" |
|
3552 |
return self.target.GetTags() |
|
3553 |
|
|
3554 |
|
|
3555 |
class LUAddTag(TagsLU): |
|
3556 |
"""Sets a tag on a given object. |
|
3557 |
|
|
3558 |
""" |
|
3559 |
_OP_REQP = ["kind", "name", "tag"] |
|
3560 |
|
|
3561 |
def CheckPrereq(self): |
|
3562 |
"""Check prerequisites. |
|
3563 |
|
|
3564 |
This checks the type and length of the tag name and value. |
|
3565 |
|
|
3566 |
""" |
|
3567 |
TagsLU.CheckPrereq(self) |
|
3568 |
objects.TaggableObject.ValidateTag(self.op.tag) |
|
3569 |
|
|
3570 |
def Exec(self, feedback_fn): |
|
3571 |
"""Sets the tag. |
|
3572 |
|
|
3573 |
""" |
|
3574 |
try: |
|
3575 |
self.target.AddTag(self.op.tag) |
|
3576 |
except errors.TagError, err: |
|
3577 |
raise errors.OpExecError, ("Error while setting tag: %s" % str(err)) |
|
3578 |
try: |
|
3579 |
self.cfg.Update(self.target) |
|
3580 |
except errors.ConfigurationError: |
|
3581 |
raise errors.OpRetryError, ("There has been a modification to the" |
|
3582 |
" config file and the operation has been" |
|
3583 |
" aborted. Please retry.") |
|
3584 |
|
|
3585 |
|
|
3586 |
class LUDelTag(TagsLU): |
|
3587 |
"""Delete a tag from a given object. |
|
3588 |
|
|
3589 |
""" |
|
3590 |
_OP_REQP = ["kind", "name", "tag"] |
|
3591 |
|
|
3592 |
def CheckPrereq(self): |
|
3593 |
"""Check prerequisites. |
|
3594 |
|
|
3595 |
This checks that we have the given tag. |
|
3596 |
|
|
3597 |
""" |
|
3598 |
TagsLU.CheckPrereq(self) |
|
3599 |
objects.TaggableObject.ValidateTag(self.op.tag) |
|
3600 |
if self.op.tag not in self.target.GetTags(): |
|
3601 |
raise errors.OpPrereqError, ("Tag not found") |
|
3602 |
|
|
3603 |
def Exec(self, feedback_fn): |
|
3604 |
"""Remove the tag from the object. |
|
3605 |
|
|
3606 |
""" |
|
3607 |
self.target.RemoveTag(self.op.tag) |
|
3608 |
try: |
|
3609 |
self.cfg.Update(self.target) |
|
3610 |
except errors.ConfigurationError: |
|
3611 |
raise errors.OpRetryError, ("There has been a modification to the" |
|
3612 |
" config file and the operation has been" |
|
3613 |
" aborted. Please retry.") |
Also available in: Unified diff