Code Duplication    Length = 51-54 lines in 2 locations

gvm/protocols/gmpv7.py 2 locations

@@ 1617-1667 (lines=51) @@
1614
        cmd.add_element("copy", schedule_id)
1615
        return self._send_xml_command(cmd)
1616
1617
    def create_tag(
1618
        self,
1619
        name,
1620
        resource_id,
1621
        resource_type,
1622
        *,
1623
        value=None,
1624
        comment=None,
1625
        active=None,
1626
    ):
1627
        """Create a new tag
1628
1629
        Arguments:
1630
            name (str): Name of the tag. A full tag name consisting of namespace
1631
                and predicate e.g. `foo:bar`.
1632
            resource_id (str): ID of the resource  the tag is to be attached to.
1633
            resource_type (str): Entity type the tag is to be attached to
1634
            value (str, optional): Value associated with the tag
1635
            comment (str, optional): Comment for the tag
1636
            active (boolean, optional): Whether the tag should be active
1637
1638
        Returns:
1639
            The response. See :py:meth:`send_command` for details.
1640
        """
1641
        if not name:
1642
            raise RequiredArgument("create_tag requires name argument")
1643
1644
        if not resource_id:
1645
            raise RequiredArgument("create_tag requires resource_id argument")
1646
1647
        if not resource_type:
1648
            raise RequiredArgument("create_tag requires resource_type argument")
1649
1650
        cmd = XmlCommand("create_tag")
1651
        cmd.add_element("name", name)
1652
        _xmlresource = cmd.add_element(
1653
            "resource", attrs={"id": str(resource_id)}
1654
        )
1655
        _xmlresource.add_element("type", resource_type)
1656
1657
        if comment:
1658
            cmd.add_element("comment", comment)
1659
1660
        if value:
1661
            cmd.add_element("value", value)
1662
1663
        if not active is None:
1664
            if active:
1665
                cmd.add_element("active", "1")
1666
            else:
1667
                cmd.add_element("active", "0")
1668
1669
        return self._send_xml_command(cmd)
1670
@@ 5181-5234 (lines=54) @@
5178
5179
        return self._send_xml_command(cmd)
5180
5181
    def modify_tag(
5182
        self,
5183
        tag_id,
5184
        *,
5185
        comment=None,
5186
        name=None,
5187
        value=None,
5188
        active=None,
5189
        resource_id=None,
5190
        resource_type=None,
5191
    ):
5192
        """Modifies an existing tag.
5193
5194
        Arguments:
5195
            tag_id (str): UUID of the tag.
5196
            comment (str, optional): Comment to add to the tag.
5197
            name (str, optional): Name of the tag.
5198
            value (str, optional): Value of the tag.
5199
            active (boolean, optional): Whether the tag is active.
5200
            resource_id (str, optional): IDs of the resource to which to
5201
                attach the tag. Required if resource_type is set.
5202
            resource_type (str, optional): Type of the resource to which to
5203
                attach the tag. Required if resource_id is set.
5204
5205
        Returns:
5206
            The response. See :py:meth:`send_command` for details.
5207
        """
5208
        if not tag_id:
5209
            raise RequiredArgument("modify_tag requires a tag_id element")
5210
5211
        cmd = XmlCommand("modify_tag")
5212
        cmd.set_attribute("tag_id", str(tag_id))
5213
5214
        if comment:
5215
            cmd.add_element("comment", comment)
5216
5217
        if name:
5218
            cmd.add_element("name", name)
5219
5220
        if value:
5221
            cmd.add_element("value", value)
5222
5223
        if active is not None:
5224
            cmd.add_element("active", _to_bool(active))
5225
5226
        if resource_id or resource_type:
5227
            if not resource_id:
5228
                raise RequiredArgument(
5229
                    "modify_tag requires resource_id argument when "
5230
                    "resource_type is set"
5231
                )
5232
5233
            if not resource_type:
5234
                raise RequiredArgument(
5235
                    "modify_tag requires resource_type argument when "
5236
                    "resource_id is set"
5237
                )