| @@ 1636-1686 (lines=51) @@ | ||
| 1633 | cmd.add_element("copy", schedule_id) |
|
| 1634 | return self._send_xml_command(cmd) |
|
| 1635 | ||
| 1636 | def create_tag( |
|
| 1637 | self, |
|
| 1638 | name, |
|
| 1639 | resource_id, |
|
| 1640 | resource_type, |
|
| 1641 | *, |
|
| 1642 | value=None, |
|
| 1643 | comment=None, |
|
| 1644 | active=None |
|
| 1645 | ): |
|
| 1646 | """Create a new tag |
|
| 1647 | ||
| 1648 | Arguments: |
|
| 1649 | name (str): Name of the tag. A full tag name consisting of namespace |
|
| 1650 | and predicate e.g. `foo:bar`. |
|
| 1651 | resource_id (str): ID of the resource the tag is to be attached to. |
|
| 1652 | resource_type (str): Entity type the tag is to be attached to |
|
| 1653 | value (str, optional): Value associated with the tag |
|
| 1654 | comment (str, optional): Comment for the tag |
|
| 1655 | active (boolean, optional): Whether the tag should be active |
|
| 1656 | ||
| 1657 | Returns: |
|
| 1658 | The response. See :py:meth:`send_command` for details. |
|
| 1659 | """ |
|
| 1660 | if not name: |
|
| 1661 | raise RequiredArgument("create_tag requires name argument") |
|
| 1662 | ||
| 1663 | if not resource_id: |
|
| 1664 | raise RequiredArgument("create_tag requires resource_id argument") |
|
| 1665 | ||
| 1666 | if not resource_type: |
|
| 1667 | raise RequiredArgument("create_tag requires resource_type argument") |
|
| 1668 | ||
| 1669 | cmd = XmlCommand("create_tag") |
|
| 1670 | cmd.add_element("name", name) |
|
| 1671 | _xmlresource = cmd.add_element( |
|
| 1672 | "resource", attrs={"id": str(resource_id)} |
|
| 1673 | ) |
|
| 1674 | _xmlresource.add_element("type", resource_type) |
|
| 1675 | ||
| 1676 | if comment: |
|
| 1677 | cmd.add_element("comment", comment) |
|
| 1678 | ||
| 1679 | if value: |
|
| 1680 | cmd.add_element("value", value) |
|
| 1681 | ||
| 1682 | if not active is None: |
|
| 1683 | if active: |
|
| 1684 | cmd.add_element("active", "1") |
|
| 1685 | else: |
|
| 1686 | cmd.add_element("active", "0") |
|
| 1687 | ||
| 1688 | return self._send_xml_command(cmd) |
|
| 1689 | ||
| @@ 5253-5306 (lines=54) @@ | ||
| 5250 | ||
| 5251 | return self._send_xml_command(cmd) |
|
| 5252 | ||
| 5253 | def modify_tag( |
|
| 5254 | self, |
|
| 5255 | tag_id, |
|
| 5256 | *, |
|
| 5257 | comment=None, |
|
| 5258 | name=None, |
|
| 5259 | value=None, |
|
| 5260 | active=None, |
|
| 5261 | resource_id=None, |
|
| 5262 | resource_type=None |
|
| 5263 | ): |
|
| 5264 | """Modifies an existing tag. |
|
| 5265 | ||
| 5266 | Arguments: |
|
| 5267 | tag_id (str): UUID of the tag. |
|
| 5268 | comment (str, optional): Comment to add to the tag. |
|
| 5269 | name (str, optional): Name of the tag. |
|
| 5270 | value (str, optional): Value of the tag. |
|
| 5271 | active (boolean, optional): Whether the tag is active. |
|
| 5272 | resource_id (str, optional): IDs of the resource to which to |
|
| 5273 | attach the tag. Required if resource_type is set. |
|
| 5274 | resource_type (str, optional): Type of the resource to which to |
|
| 5275 | attach the tag. Required if resource_id is set. |
|
| 5276 | ||
| 5277 | Returns: |
|
| 5278 | The response. See :py:meth:`send_command` for details. |
|
| 5279 | """ |
|
| 5280 | if not tag_id: |
|
| 5281 | raise RequiredArgument("modify_tag requires a tag_id element") |
|
| 5282 | ||
| 5283 | cmd = XmlCommand("modify_tag") |
|
| 5284 | cmd.set_attribute("tag_id", str(tag_id)) |
|
| 5285 | ||
| 5286 | if comment: |
|
| 5287 | cmd.add_element("comment", comment) |
|
| 5288 | ||
| 5289 | if name: |
|
| 5290 | cmd.add_element("name", name) |
|
| 5291 | ||
| 5292 | if value: |
|
| 5293 | cmd.add_element("value", value) |
|
| 5294 | ||
| 5295 | if active is not None: |
|
| 5296 | cmd.add_element("active", _to_bool(active)) |
|
| 5297 | ||
| 5298 | if resource_id or resource_type: |
|
| 5299 | if not resource_id: |
|
| 5300 | raise RequiredArgument( |
|
| 5301 | "modify_tag requires resource_id argument when " |
|
| 5302 | "resource_type is set" |
|
| 5303 | ) |
|
| 5304 | ||
| 5305 | if not resource_type: |
|
| 5306 | raise RequiredArgument( |
|
| 5307 | "modify_tag requires resource_type argument when " |
|
| 5308 | "resource_id is set" |
|
| 5309 | ) |
|