Code Duplication    Length = 192-194 lines in 2 locations

gvm/protocols/gmpv7/gmpv7.py 2 locations

@@ 5341-5534 (lines=194) @@
5338
5339
        return self._send_xml_command(cmd)
5340
5341
    def modify_schedule(
5342
        self,
5343
        schedule_id: str,
5344
        *,
5345
        comment: Optional[str] = None,
5346
        name: Optional[str] = None,
5347
        first_time_minute: Optional[int] = None,
5348
        first_time_hour: Optional[int] = None,
5349
        first_time_day_of_month: Optional[int] = None,
5350
        first_time_month: Optional[int] = None,
5351
        first_time_year: Optional[int] = None,
5352
        duration: Optional[int] = None,
5353
        duration_unit: Optional[TimeUnit] = None,
5354
        period: Optional[int] = None,
5355
        period_unit: Optional[TimeUnit] = None,
5356
        timezone: Optional[str] = None
5357
    ) -> Any:
5358
        """Modifies an existing schedule.
5359
5360
        Arguments:
5361
            schedule_id: UUID of schedule to modify.
5362
            name: Name of the schedule
5363
            comment: Comment for the schedule
5364
            first_time_minute: First time minute the schedule will run. Must be
5365
                an integer >= 0.
5366
            first_time_hour: First time hour the schedule will run. Must be an
5367
                integer >= 0.
5368
            first_time_day_of_month: First time day of month the schedule will
5369
                run. Must be an integer > 0 <= 31.
5370
            first_time_month: First time month the schedule will run. Must be an
5371
                integer >= 1 <= 12.
5372
            first_time_year: First time year the schedule will run
5373
            duration: How long the Manager will run the scheduled task for until
5374
                it gets paused if not finished yet.
5375
            duration_unit: Unit of the duration. One of second, minute, hour,
5376
                day, week, month, year, decade. Required if duration is set.
5377
            period: How often the Manager will repeat the scheduled task. Must
5378
                be an integer > 0.
5379
            period_unit: Unit of the period. One of second, minute, hour, day,
5380
                week, month, year, decade. Required if period is set.
5381
            timezone: The timezone the schedule will follow
5382
5383
        Returns:
5384
            The response. See :py:meth:`send_command` for details.
5385
        """
5386
        if not schedule_id:
5387
            raise RequiredArgument(
5388
                function=self.modify_schedule.__name__, argument='schedule_id'
5389
            )
5390
5391
        cmd = XmlCommand("modify_schedule")
5392
        cmd.set_attribute("schedule_id", schedule_id)
5393
5394
        if comment:
5395
            cmd.add_element("comment", comment)
5396
5397
        if name:
5398
            cmd.add_element("name", name)
5399
5400
        if (
5401
            first_time_minute is not None
5402
            or first_time_hour is not None
5403
            or first_time_day_of_month is not None
5404
            or first_time_month is not None
5405
            or first_time_year is not None
5406
        ):
5407
5408
            if first_time_minute is None:
5409
                raise RequiredArgument(
5410
                    function=self.modify_schedule.__name__,
5411
                    argument='first_time_minute',
5412
                )
5413
            elif (
5414
                not isinstance(first_time_minute, numbers.Integral)
5415
                or first_time_minute < 0
5416
            ):
5417
                raise InvalidArgument(
5418
                    "first_time_minute argument of modify_schedule needs to be "
5419
                    "an integer greater or equal 0"
5420
                )
5421
5422
            if first_time_hour is None:
5423
                raise RequiredArgument(
5424
                    function=self.modify_schedule.__name__,
5425
                    argument='first_time_hour',
5426
                )
5427
            elif (
5428
                not isinstance(first_time_hour, numbers.Integral)
5429
                or first_time_hour < 0
5430
            ):
5431
                raise InvalidArgument(
5432
                    "first_time_hour argument of modify_schedule needs to be "
5433
                    "an integer greater or equal 0"
5434
                )
5435
5436
            if first_time_day_of_month is None:
5437
                raise RequiredArgument(
5438
                    function=self.modify_schedule.__name__,
5439
                    argument='first_time_day_of_month',
5440
                )
5441
            elif (
5442
                not isinstance(first_time_day_of_month, numbers.Integral)
5443
                or first_time_day_of_month < 1
5444
                or first_time_day_of_month > 31
5445
            ):
5446
                raise InvalidArgument(
5447
                    "first_time_day_of_month argument of modify_schedule needs "
5448
                    "to be an integer between 1 and 31"
5449
                )
5450
5451
            if first_time_month is None:
5452
                raise RequiredArgument(
5453
                    function=self.modify_schedule.__name__,
5454
                    argument='first_time_month',
5455
                )
5456
            elif (
5457
                not isinstance(first_time_month, numbers.Integral)
5458
                or first_time_month < 1
5459
                or first_time_month > 12
5460
            ):
5461
                raise InvalidArgument(
5462
                    "first_time_month argument of modify_schedule needs "
5463
                    "to be an integer between 1 and 12"
5464
                )
5465
5466
            if first_time_year is None:
5467
                raise RequiredArgument(
5468
                    function=self.modify_schedule.__name__,
5469
                    argument='first_time_year',
5470
                )
5471
            elif (
5472
                not isinstance(first_time_year, numbers.Integral)
5473
                or first_time_year < 1970
5474
            ):
5475
                raise InvalidArgument(
5476
                    "first_time_year argument of create_schedule needs "
5477
                    "to be an integer greater or equal 1970"
5478
                )
5479
5480
            _xmlftime = cmd.add_element("first_time")
5481
            _xmlftime.add_element("minute", str(first_time_minute))
5482
            _xmlftime.add_element("hour", str(first_time_hour))
5483
            _xmlftime.add_element("day_of_month", str(first_time_day_of_month))
5484
            _xmlftime.add_element("month", str(first_time_month))
5485
            _xmlftime.add_element("year", str(first_time_year))
5486
5487
        if duration is not None:
5488
            if not duration_unit:
5489
                raise RequiredArgument(
5490
                    function=self.modify_schedule.__name__,
5491
                    argument='duration_unit',
5492
                )
5493
5494
            if not isinstance(duration_unit, TimeUnit):
5495
                raise InvalidArgumentType(
5496
                    function=self.modify_schedule.__name__,
5497
                    argument='duration_unit',
5498
                    arg_type=TimeUnit.__name__,
5499
                )
5500
5501
            if not isinstance(duration, numbers.Integral) or duration < 1:
5502
                raise InvalidArgument(
5503
                    "duration argument must be an integer greater than 0"
5504
                )
5505
5506
            _xmlduration = cmd.add_element("duration", str(duration))
5507
            _xmlduration.add_element("unit", duration_unit.value)
5508
5509
        if period is not None:
5510
            if not period_unit:
5511
                raise RequiredArgument(
5512
                    function=self.modify_schedule.__name__,
5513
                    argument='period_unit',
5514
                )
5515
5516
            if not isinstance(period_unit, TimeUnit):
5517
                raise InvalidArgumentType(
5518
                    function=self.modify_schedule.__name__,
5519
                    argument='period_unit',
5520
                    arg_type=TimeUnit.__name__,
5521
                )
5522
5523
            if not isinstance(period, numbers.Integral) or period < 1:
5524
                raise InvalidArgument(
5525
                    "period argument must be an integer greater than 0"
5526
                )
5527
5528
            _xmlperiod = cmd.add_element("period", str(period))
5529
            _xmlperiod.add_element("unit", period_unit.value)
5530
5531
        if timezone:
5532
            cmd.add_element("timezone", timezone)
5533
5534
        return self._send_xml_command(cmd)
5535
5536
    def modify_setting(
5537
        self,
@@ 1497-1688 (lines=192) @@
1494
        cmd.add_element("copy", scanner_id)
1495
        return self._send_xml_command(cmd)
1496
1497
    def create_schedule(
1498
        self,
1499
        name: str,
1500
        *,
1501
        comment: Optional[str] = None,
1502
        first_time_minute: Optional[int] = None,
1503
        first_time_hour: Optional[int] = None,
1504
        first_time_day_of_month: Optional[int] = None,
1505
        first_time_month: Optional[int] = None,
1506
        first_time_year: Optional[int] = None,
1507
        duration: Optional[int] = None,
1508
        duration_unit: Optional[TimeUnit] = None,
1509
        period: Optional[int] = None,
1510
        period_unit: Optional[TimeUnit] = None,
1511
        timezone: Optional[str] = None
1512
    ) -> Any:
1513
        """Create a new schedule
1514
1515
        Arguments:
1516
            name: Name of the schedule
1517
            comment: Comment for the schedule
1518
            first_time_minute: First time minute the schedule will run. Must be
1519
                an integer >= 0.
1520
            first_time_hour: First time hour the schedule will run. Must be an
1521
                integer >= 0.
1522
            first_time_day_of_month: First time day of month the schedule will
1523
                run. Must be an integer > 0 <= 31.
1524
            first_time_month: First time month the schedule will run. Must be an
1525
                integer >= 1 <= 12.
1526
            first_time_year: First time year the schedule will run. Must be an
1527
                integer >= 1970.
1528
            duration: How long the Manager will run the scheduled task for until
1529
                it gets paused if not finished yet. Must be an integer > 0.
1530
            duration_unit: Unit of the duration. One of second,
1531
                minute, hour, day, week, month, year, decade. Required if
1532
                duration is set.
1533
            period: How often the Manager will repeat the
1534
                scheduled task. Must be an integer > 0.
1535
            period_unit: Unit of the period. One of second,
1536
                minute, hour, day, week, month, year, decade. Required if
1537
                period is set.
1538
            timezone: The timezone the schedule will follow
1539
1540
        Returns:
1541
            The response. See :py:meth:`send_command` for details.
1542
        """
1543
        if not name:
1544
            raise RequiredArgument(
1545
                function=self.create_schedule.__name__, argument='name'
1546
            )
1547
1548
        cmd = XmlCommand("create_schedule")
1549
        cmd.add_element("name", name)
1550
1551
        if comment:
1552
            cmd.add_element("comment", comment)
1553
1554
        if (
1555
            first_time_minute is not None
1556
            or first_time_hour is not None
1557
            or first_time_day_of_month is not None
1558
            or first_time_month is not None
1559
            or first_time_year is not None
1560
        ):
1561
1562
            if first_time_minute is None:
1563
                raise RequiredArgument(
1564
                    function=self.create_schedule.__name__,
1565
                    argument='first_time_minute',
1566
                )
1567
            elif (
1568
                not isinstance(first_time_minute, numbers.Integral)
1569
                or first_time_minute < 0
1570
            ):
1571
                raise InvalidArgument(
1572
                    "first_time_minute argument of create_schedule needs to be "
1573
                    "an integer greater or equal 0"
1574
                )
1575
1576
            if first_time_hour is None:
1577
                raise RequiredArgument(
1578
                    function=self.create_schedule.__name__,
1579
                    argument='first_time_hour',
1580
                )
1581
            elif (
1582
                not isinstance(first_time_hour, numbers.Integral)
1583
                or first_time_hour < 0
1584
            ):
1585
                raise InvalidArgument(
1586
                    "first_time_hour argument of create_schedule needs to be "
1587
                    "an integer greater or equal 0"
1588
                )
1589
1590
            if first_time_day_of_month is None:
1591
                raise RequiredArgument(
1592
                    function=self.create_schedule.__name__,
1593
                    argument='first_time_day_of_month',
1594
                )
1595
            elif (
1596
                not isinstance(first_time_day_of_month, numbers.Integral)
1597
                or first_time_day_of_month < 1
1598
                or first_time_day_of_month > 31
1599
            ):
1600
                raise InvalidArgument(
1601
                    "first_time_day_of_month argument of create_schedule needs "
1602
                    "to be an integer between 1 and 31"
1603
                )
1604
1605
            if first_time_month is None:
1606
                raise RequiredArgument(
1607
                    function=self.create_schedule.__name__,
1608
                    argument='first_time_month',
1609
                )
1610
            elif (
1611
                not isinstance(first_time_month, numbers.Integral)
1612
                or first_time_month < 1
1613
                or first_time_month > 12
1614
            ):
1615
                raise InvalidArgument(
1616
                    "first_time_month argument of create_schedule needs "
1617
                    "to be an integer between 1 and 12"
1618
                )
1619
1620
            if first_time_year is None:
1621
                raise RequiredArgument(
1622
                    function=self.create_schedule.__name__,
1623
                    argument='first_time_year',
1624
                )
1625
            elif (
1626
                not isinstance(first_time_year, numbers.Integral)
1627
                or first_time_year < 1970
1628
            ):
1629
                raise InvalidArgument(
1630
                    "first_time_year argument of create_schedule needs "
1631
                    "to be an integer greater or equal 1970"
1632
                )
1633
1634
            _xmlftime = cmd.add_element("first_time")
1635
            _xmlftime.add_element("minute", str(first_time_minute))
1636
            _xmlftime.add_element("hour", str(first_time_hour))
1637
            _xmlftime.add_element("day_of_month", str(first_time_day_of_month))
1638
            _xmlftime.add_element("month", str(first_time_month))
1639
            _xmlftime.add_element("year", str(first_time_year))
1640
1641
        if duration is not None:
1642
            if not duration_unit:
1643
                raise RequiredArgument(
1644
                    function=self.create_schedule.__name__,
1645
                    argument='duration_unit',
1646
                )
1647
1648
            if not isinstance(duration_unit, TimeUnit):
1649
                raise InvalidArgumentType(
1650
                    function=self.create_schedule.__name__,
1651
                    argument='duration_unit',
1652
                    arg_type=TimeUnit.__name__,
1653
                )
1654
1655
            if not isinstance(duration, numbers.Integral) or duration < 1:
1656
                raise InvalidArgument(
1657
                    "duration argument must be an integer greater than 0"
1658
                )
1659
1660
            _xmlduration = cmd.add_element("duration", str(duration))
1661
            _xmlduration.add_element("unit", duration_unit.value)
1662
1663
        if period is not None:
1664
            if not period_unit:
1665
                raise RequiredArgument(
1666
                    function=self.create_schedule.__name__,
1667
                    argument='period_unit',
1668
                )
1669
1670
            if not isinstance(period_unit, TimeUnit):
1671
                raise InvalidArgumentType(
1672
                    function=self.create_schedule.__name__,
1673
                    argument='period_unit',
1674
                    arg_type=TimeUnit.__name__,
1675
                )
1676
1677
            if not isinstance(period, numbers.Integral) or period < 0:
1678
                raise InvalidArgument(
1679
                    "period argument must be a positive integer"
1680
                )
1681
1682
            _xmlperiod = cmd.add_element("period", str(period))
1683
            _xmlperiod.add_element("unit", period_unit.value)
1684
1685
        if timezone:
1686
            cmd.add_element("timezone", timezone)
1687
1688
        return self._send_xml_command(cmd)
1689
1690
    def clone_schedule(self, schedule_id: str) -> Any:
1691
        """Clone an existing schedule