Code Duplication    Length = 192-194 lines in 2 locations

gvm/protocols/gmpv7/gmpv7.py 2 locations

@@ 5496-5689 (lines=194) @@
5493
5494
        return self._send_xml_command(cmd)
5495
5496
    def modify_schedule(
5497
        self,
5498
        schedule_id: str,
5499
        *,
5500
        comment: Optional[str] = None,
5501
        name: Optional[str] = None,
5502
        first_time_minute: Optional[int] = None,
5503
        first_time_hour: Optional[int] = None,
5504
        first_time_day_of_month: Optional[int] = None,
5505
        first_time_month: Optional[int] = None,
5506
        first_time_year: Optional[int] = None,
5507
        duration: Optional[int] = None,
5508
        duration_unit: Optional[TimeUnit] = None,
5509
        period: Optional[int] = None,
5510
        period_unit: Optional[TimeUnit] = None,
5511
        timezone: Optional[str] = None
5512
    ) -> Any:
5513
        """Modifies an existing schedule.
5514
5515
        Arguments:
5516
            schedule_id: UUID of schedule to modify.
5517
            name: Name of the schedule
5518
            comment: Comment for the schedule
5519
            first_time_minute: First time minute the schedule will run. Must be
5520
                an integer >= 0.
5521
            first_time_hour: First time hour the schedule will run. Must be an
5522
                integer >= 0.
5523
            first_time_day_of_month: First time day of month the schedule will
5524
                run. Must be an integer > 0 <= 31.
5525
            first_time_month: First time month the schedule will run. Must be an
5526
                integer >= 1 <= 12.
5527
            first_time_year: First time year the schedule will run
5528
            duration: How long the Manager will run the scheduled task for until
5529
                it gets paused if not finished yet.
5530
            duration_unit: Unit of the duration. One of second, minute, hour,
5531
                day, week, month, year, decade. Required if duration is set.
5532
            period: How often the Manager will repeat the scheduled task. Must
5533
                be an integer > 0.
5534
            period_unit: Unit of the period. One of second, minute, hour, day,
5535
                week, month, year, decade. Required if period is set.
5536
            timezone: The timezone the schedule will follow
5537
5538
        Returns:
5539
            The response. See :py:meth:`send_command` for details.
5540
        """
5541
        if not schedule_id:
5542
            raise RequiredArgument(
5543
                function=self.modify_schedule.__name__, argument='schedule_id'
5544
            )
5545
5546
        cmd = XmlCommand("modify_schedule")
5547
        cmd.set_attribute("schedule_id", schedule_id)
5548
5549
        if comment:
5550
            cmd.add_element("comment", comment)
5551
5552
        if name:
5553
            cmd.add_element("name", name)
5554
5555
        if (
5556
            first_time_minute is not None
5557
            or first_time_hour is not None
5558
            or first_time_day_of_month is not None
5559
            or first_time_month is not None
5560
            or first_time_year is not None
5561
        ):
5562
5563
            if first_time_minute is None:
5564
                raise RequiredArgument(
5565
                    function=self.modify_schedule.__name__,
5566
                    argument='first_time_minute',
5567
                )
5568
            elif (
5569
                not isinstance(first_time_minute, numbers.Integral)
5570
                or first_time_minute < 0
5571
            ):
5572
                raise InvalidArgument(
5573
                    "first_time_minute argument of modify_schedule needs to be "
5574
                    "an integer greater or equal 0"
5575
                )
5576
5577
            if first_time_hour is None:
5578
                raise RequiredArgument(
5579
                    function=self.modify_schedule.__name__,
5580
                    argument='first_time_hour',
5581
                )
5582
            elif (
5583
                not isinstance(first_time_hour, numbers.Integral)
5584
                or first_time_hour < 0
5585
            ):
5586
                raise InvalidArgument(
5587
                    "first_time_hour argument of modify_schedule needs to be "
5588
                    "an integer greater or equal 0"
5589
                )
5590
5591
            if first_time_day_of_month is None:
5592
                raise RequiredArgument(
5593
                    function=self.modify_schedule.__name__,
5594
                    argument='first_time_day_of_month',
5595
                )
5596
            elif (
5597
                not isinstance(first_time_day_of_month, numbers.Integral)
5598
                or first_time_day_of_month < 1
5599
                or first_time_day_of_month > 31
5600
            ):
5601
                raise InvalidArgument(
5602
                    "first_time_day_of_month argument of modify_schedule needs "
5603
                    "to be an integer between 1 and 31"
5604
                )
5605
5606
            if first_time_month is None:
5607
                raise RequiredArgument(
5608
                    function=self.modify_schedule.__name__,
5609
                    argument='first_time_month',
5610
                )
5611
            elif (
5612
                not isinstance(first_time_month, numbers.Integral)
5613
                or first_time_month < 1
5614
                or first_time_month > 12
5615
            ):
5616
                raise InvalidArgument(
5617
                    "first_time_month argument of modify_schedule needs "
5618
                    "to be an integer between 1 and 12"
5619
                )
5620
5621
            if first_time_year is None:
5622
                raise RequiredArgument(
5623
                    function=self.modify_schedule.__name__,
5624
                    argument='first_time_year',
5625
                )
5626
            elif (
5627
                not isinstance(first_time_year, numbers.Integral)
5628
                or first_time_year < 1970
5629
            ):
5630
                raise InvalidArgument(
5631
                    "first_time_year argument of create_schedule needs "
5632
                    "to be an integer greater or equal 1970"
5633
                )
5634
5635
            _xmlftime = cmd.add_element("first_time")
5636
            _xmlftime.add_element("minute", str(first_time_minute))
5637
            _xmlftime.add_element("hour", str(first_time_hour))
5638
            _xmlftime.add_element("day_of_month", str(first_time_day_of_month))
5639
            _xmlftime.add_element("month", str(first_time_month))
5640
            _xmlftime.add_element("year", str(first_time_year))
5641
5642
        if duration is not None:
5643
            if not duration_unit:
5644
                raise RequiredArgument(
5645
                    function=self.modify_schedule.__name__,
5646
                    argument='duration_unit',
5647
                )
5648
5649
            if not isinstance(duration_unit, TimeUnit):
5650
                raise InvalidArgumentType(
5651
                    function=self.modify_schedule.__name__,
5652
                    argument='duration_unit',
5653
                    arg_type=TimeUnit.__name__,
5654
                )
5655
5656
            if not isinstance(duration, numbers.Integral) or duration < 1:
5657
                raise InvalidArgument(
5658
                    "duration argument must be an integer greater than 0"
5659
                )
5660
5661
            _xmlduration = cmd.add_element("duration", str(duration))
5662
            _xmlduration.add_element("unit", duration_unit.value)
5663
5664
        if period is not None:
5665
            if not period_unit:
5666
                raise RequiredArgument(
5667
                    function=self.modify_schedule.__name__,
5668
                    argument='period_unit',
5669
                )
5670
5671
            if not isinstance(period_unit, TimeUnit):
5672
                raise InvalidArgumentType(
5673
                    function=self.modify_schedule.__name__,
5674
                    argument='period_unit',
5675
                    arg_type=TimeUnit.__name__,
5676
                )
5677
5678
            if not isinstance(period, numbers.Integral) or period < 1:
5679
                raise InvalidArgument(
5680
                    "period argument must be an integer greater than 0"
5681
                )
5682
5683
            _xmlperiod = cmd.add_element("period", str(period))
5684
            _xmlperiod.add_element("unit", period_unit.value)
5685
5686
        if timezone:
5687
            cmd.add_element("timezone", timezone)
5688
5689
        return self._send_xml_command(cmd)
5690
5691
    def modify_setting(
5692
        self,
@@ 1549-1740 (lines=192) @@
1546
        cmd.add_element("copy", scanner_id)
1547
        return self._send_xml_command(cmd)
1548
1549
    def create_schedule(
1550
        self,
1551
        name: str,
1552
        *,
1553
        comment: Optional[str] = None,
1554
        first_time_minute: Optional[int] = None,
1555
        first_time_hour: Optional[int] = None,
1556
        first_time_day_of_month: Optional[int] = None,
1557
        first_time_month: Optional[int] = None,
1558
        first_time_year: Optional[int] = None,
1559
        duration: Optional[int] = None,
1560
        duration_unit: Optional[TimeUnit] = None,
1561
        period: Optional[int] = None,
1562
        period_unit: Optional[TimeUnit] = None,
1563
        timezone: Optional[str] = None
1564
    ) -> Any:
1565
        """Create a new schedule
1566
1567
        Arguments:
1568
            name: Name of the schedule
1569
            comment: Comment for the schedule
1570
            first_time_minute: First time minute the schedule will run. Must be
1571
                an integer >= 0.
1572
            first_time_hour: First time hour the schedule will run. Must be an
1573
                integer >= 0.
1574
            first_time_day_of_month: First time day of month the schedule will
1575
                run. Must be an integer > 0 <= 31.
1576
            first_time_month: First time month the schedule will run. Must be an
1577
                integer >= 1 <= 12.
1578
            first_time_year: First time year the schedule will run. Must be an
1579
                integer >= 1970.
1580
            duration: How long the Manager will run the scheduled task for until
1581
                it gets paused if not finished yet. Must be an integer > 0.
1582
            duration_unit: Unit of the duration. One of second,
1583
                minute, hour, day, week, month, year, decade. Required if
1584
                duration is set.
1585
            period: How often the Manager will repeat the
1586
                scheduled task. Must be an integer > 0.
1587
            period_unit: Unit of the period. One of second,
1588
                minute, hour, day, week, month, year, decade. Required if
1589
                period is set.
1590
            timezone: The timezone the schedule will follow
1591
1592
        Returns:
1593
            The response. See :py:meth:`send_command` for details.
1594
        """
1595
        if not name:
1596
            raise RequiredArgument(
1597
                function=self.create_schedule.__name__, argument='name'
1598
            )
1599
1600
        cmd = XmlCommand("create_schedule")
1601
        cmd.add_element("name", name)
1602
1603
        if comment:
1604
            cmd.add_element("comment", comment)
1605
1606
        if (
1607
            first_time_minute is not None
1608
            or first_time_hour is not None
1609
            or first_time_day_of_month is not None
1610
            or first_time_month is not None
1611
            or first_time_year is not None
1612
        ):
1613
1614
            if first_time_minute is None:
1615
                raise RequiredArgument(
1616
                    function=self.create_schedule.__name__,
1617
                    argument='first_time_minute',
1618
                )
1619
            elif (
1620
                not isinstance(first_time_minute, numbers.Integral)
1621
                or first_time_minute < 0
1622
            ):
1623
                raise InvalidArgument(
1624
                    "first_time_minute argument of create_schedule needs to be "
1625
                    "an integer greater or equal 0"
1626
                )
1627
1628
            if first_time_hour is None:
1629
                raise RequiredArgument(
1630
                    function=self.create_schedule.__name__,
1631
                    argument='first_time_hour',
1632
                )
1633
            elif (
1634
                not isinstance(first_time_hour, numbers.Integral)
1635
                or first_time_hour < 0
1636
            ):
1637
                raise InvalidArgument(
1638
                    "first_time_hour argument of create_schedule needs to be "
1639
                    "an integer greater or equal 0"
1640
                )
1641
1642
            if first_time_day_of_month is None:
1643
                raise RequiredArgument(
1644
                    function=self.create_schedule.__name__,
1645
                    argument='first_time_day_of_month',
1646
                )
1647
            elif (
1648
                not isinstance(first_time_day_of_month, numbers.Integral)
1649
                or first_time_day_of_month < 1
1650
                or first_time_day_of_month > 31
1651
            ):
1652
                raise InvalidArgument(
1653
                    "first_time_day_of_month argument of create_schedule needs "
1654
                    "to be an integer between 1 and 31"
1655
                )
1656
1657
            if first_time_month is None:
1658
                raise RequiredArgument(
1659
                    function=self.create_schedule.__name__,
1660
                    argument='first_time_month',
1661
                )
1662
            elif (
1663
                not isinstance(first_time_month, numbers.Integral)
1664
                or first_time_month < 1
1665
                or first_time_month > 12
1666
            ):
1667
                raise InvalidArgument(
1668
                    "first_time_month argument of create_schedule needs "
1669
                    "to be an integer between 1 and 12"
1670
                )
1671
1672
            if first_time_year is None:
1673
                raise RequiredArgument(
1674
                    function=self.create_schedule.__name__,
1675
                    argument='first_time_year',
1676
                )
1677
            elif (
1678
                not isinstance(first_time_year, numbers.Integral)
1679
                or first_time_year < 1970
1680
            ):
1681
                raise InvalidArgument(
1682
                    "first_time_year argument of create_schedule needs "
1683
                    "to be an integer greater or equal 1970"
1684
                )
1685
1686
            _xmlftime = cmd.add_element("first_time")
1687
            _xmlftime.add_element("minute", str(first_time_minute))
1688
            _xmlftime.add_element("hour", str(first_time_hour))
1689
            _xmlftime.add_element("day_of_month", str(first_time_day_of_month))
1690
            _xmlftime.add_element("month", str(first_time_month))
1691
            _xmlftime.add_element("year", str(first_time_year))
1692
1693
        if duration is not None:
1694
            if not duration_unit:
1695
                raise RequiredArgument(
1696
                    function=self.create_schedule.__name__,
1697
                    argument='duration_unit',
1698
                )
1699
1700
            if not isinstance(duration_unit, TimeUnit):
1701
                raise InvalidArgumentType(
1702
                    function=self.create_schedule.__name__,
1703
                    argument='duration_unit',
1704
                    arg_type=TimeUnit.__name__,
1705
                )
1706
1707
            if not isinstance(duration, numbers.Integral) or duration < 1:
1708
                raise InvalidArgument(
1709
                    "duration argument must be an integer greater than 0"
1710
                )
1711
1712
            _xmlduration = cmd.add_element("duration", str(duration))
1713
            _xmlduration.add_element("unit", duration_unit.value)
1714
1715
        if period is not None:
1716
            if not period_unit:
1717
                raise RequiredArgument(
1718
                    function=self.create_schedule.__name__,
1719
                    argument='period_unit',
1720
                )
1721
1722
            if not isinstance(period_unit, TimeUnit):
1723
                raise InvalidArgumentType(
1724
                    function=self.create_schedule.__name__,
1725
                    argument='period_unit',
1726
                    arg_type=TimeUnit.__name__,
1727
                )
1728
1729
            if not isinstance(period, numbers.Integral) or period < 0:
1730
                raise InvalidArgument(
1731
                    "period argument must be a positive integer"
1732
                )
1733
1734
            _xmlperiod = cmd.add_element("period", str(period))
1735
            _xmlperiod.add_element("unit", period_unit.value)
1736
1737
        if timezone:
1738
            cmd.add_element("timezone", timezone)
1739
1740
        return self._send_xml_command(cmd)
1741
1742
    def clone_schedule(self, schedule_id: str) -> Any:
1743
        """Clone an existing schedule