Code Duplication    Length = 149-153 lines in 2 locations

gvm/protocols/gmpv7.py 2 locations

@@ 1411-1559 (lines=149) @@
1408
        cmd.add_element("copy", scanner_id)
1409
        return self._send_xml_command(cmd)
1410
1411
    def create_schedule(
1412
        self,
1413
        name,
1414
        *,
1415
        comment=None,
1416
        first_time_minute=None,
1417
        first_time_hour=None,
1418
        first_time_day_of_month=None,
1419
        first_time_month=None,
1420
        first_time_year=None,
1421
        duration=None,
1422
        duration_unit=None,
1423
        period=None,
1424
        period_unit=None,
1425
        timezone=None,
1426
    ):
1427
        """Create a new schedule
1428
1429
        Arguments:
1430
            name (str): Name of the schedule
1431
            comment (str, optional): Comment for the schedule
1432
            first_time_minute (int, optional): First time minute the schedule
1433
                will run. Must be an integer >= 0.
1434
            first_time_hour (int, optional): First time hour the schedule
1435
                will run. Must be an integer >= 0.
1436
            first_time_day_of_month (int, optional): First time day of month the
1437
                schedule will run. Must be an integer > 0 <= 31.
1438
            first_time_month (int, optional): First time month the schedule
1439
                will run. Must be an integer >= 1 <= 12.
1440
            first_time_year (int, optional): First time year the schedule
1441
                will run. Must be an integer >= 1970.
1442
            duration (int, optional): How long the Manager will run the
1443
                scheduled task for until it gets paused if not finished yet.
1444
                Must be an integer > 0.
1445
            duration_unit (str, optional): Unit of the duration. One of second,
1446
                minute, hour, day, week, month, year, decade. Required if
1447
                duration is set.
1448
            period (int, optional): How often the Manager will repeat the
1449
                scheduled task. Must be an integer > 0.
1450
            period_unit (str, optional): Unit of the period. One of second,
1451
                minute, hour, day, week, month, year, decade. Required if
1452
                period is set.
1453
            timezone (str, optional): The timezone the schedule will follow
1454
1455
        Returns:
1456
            The response. See :py:meth:`send_command` for details.
1457
        """
1458
        if not name:
1459
            raise RequiredArgument("create_schedule requires a name argument")
1460
1461
        cmd = XmlCommand("create_schedule")
1462
        cmd.add_element("name", name)
1463
1464
        if comment:
1465
            cmd.add_element("comment", comment)
1466
1467
        if (
1468
            first_time_minute is not None
1469
            or first_time_hour is not None
1470
            or first_time_day_of_month is not None
1471
            or first_time_month is not None
1472
            or first_time_year is not None
1473
        ):
1474
1475
            if first_time_minute is None:
1476
                raise RequiredArgument(
1477
                    "Setting first_time requires first_time_minute argument"
1478
                )
1479
            elif (
1480
                not isinstance(first_time_minute, numbers.Integral)
1481
                or first_time_minute < 0
1482
            ):
1483
                raise InvalidArgument(
1484
                    "first_time_minute argument of create_schedule needs to be "
1485
                    "an integer greater or equal 0"
1486
                )
1487
1488
            if first_time_hour is None:
1489
                raise RequiredArgument(
1490
                    "Setting first_time requires first_time_hour argument"
1491
                )
1492
            elif (
1493
                not isinstance(first_time_hour, numbers.Integral)
1494
                or first_time_hour < 0
1495
            ):
1496
                raise InvalidArgument(
1497
                    "first_time_hour argument of create_schedule needs to be "
1498
                    "an integer greater or equal 0"
1499
                )
1500
1501
            if first_time_day_of_month is None:
1502
                raise RequiredArgument(
1503
                    "Setting first_time requires first_time_day_of_month "
1504
                    "argument"
1505
                )
1506
            elif (
1507
                not isinstance(first_time_day_of_month, numbers.Integral)
1508
                or first_time_day_of_month < 1
1509
                or first_time_day_of_month > 31
1510
            ):
1511
                raise InvalidArgument(
1512
                    "first_time_day_of_month argument of create_schedule needs "
1513
                    "to be an integer between 1 and 31"
1514
                )
1515
1516
            if first_time_month is None:
1517
                raise RequiredArgument(
1518
                    "Setting first_time requires first_time_month argument"
1519
                )
1520
            elif (
1521
                not isinstance(first_time_month, numbers.Integral)
1522
                or first_time_month < 1
1523
                or first_time_month > 12
1524
            ):
1525
                raise InvalidArgument(
1526
                    "first_time_month argument of create_schedule needs "
1527
                    "to be an integer between 1 and 12"
1528
                )
1529
1530
            if first_time_year is None:
1531
                raise RequiredArgument(
1532
                    "Setting first_time requires first_time_year argument"
1533
                )
1534
            elif (
1535
                not isinstance(first_time_year, numbers.Integral)
1536
                or first_time_year < 1970
1537
            ):
1538
                raise InvalidArgument(
1539
                    "first_time_year argument of create_schedule needs "
1540
                    "to be an integer greater or equal 1970"
1541
                )
1542
1543
            _xmlftime = cmd.add_element("first_time")
1544
            _xmlftime.add_element("minute", str(first_time_minute))
1545
            _xmlftime.add_element("hour", str(first_time_hour))
1546
            _xmlftime.add_element("day_of_month", str(first_time_day_of_month))
1547
            _xmlftime.add_element("month", str(first_time_month))
1548
            _xmlftime.add_element("year", str(first_time_year))
1549
1550
        if duration is not None:
1551
            if not duration_unit:
1552
                raise RequiredArgument(
1553
                    "Setting duration requires duration_unit argument"
1554
                )
1555
1556
            if not duration_unit in TIME_UNITS:
1557
                raise InvalidArgument(
1558
                    "duration_unit must be one of {units}. But {actual} has "
1559
                    "been passed".format(
1560
                        units=", ".join(TIME_UNITS), actual=duration_unit
1561
                    )
1562
                )
@@ 4956-5108 (lines=153) @@
4953
4954
        return self._send_xml_command(cmd)
4955
4956
    def modify_schedule(
4957
        self,
4958
        schedule_id,
4959
        *,
4960
        comment=None,
4961
        name=None,
4962
        first_time_minute=None,
4963
        first_time_hour=None,
4964
        first_time_day_of_month=None,
4965
        first_time_month=None,
4966
        first_time_year=None,
4967
        duration=None,
4968
        duration_unit=None,
4969
        period=None,
4970
        period_unit=None,
4971
        timezone=None,
4972
    ):
4973
        """Modifies an existing schedule.
4974
4975
        Arguments:
4976
            schedule_id (str): UUID of schedule to modify.
4977
            name (str, optional): Name of the schedule
4978
            comment (str, optional): Comment for the schedule
4979
            first_time_minute (int, optional): First time minute the schedule
4980
                will run. Must be an integer >= 0.
4981
            first_time_hour (int, optional): First time hour the schedule
4982
                will run. Must be an integer >= 0.
4983
            first_time_day_of_month (int, optional): First time day of month the
4984
                schedule will run. Must be an integer > 0 <= 31.
4985
            first_time_month (int, optional): First time month the schedule
4986
                will run. Must be an integer >= 1 <= 12.
4987
            first_time_year (int, optional): First time year the schedule
4988
                will run
4989
            duration (int, optional): How long the Manager will run the
4990
                scheduled task for until it gets paused if not finished yet.
4991
            duration_unit (str, optional): Unit of the duration. One of second,
4992
                minute, hour, day, week, month, year, decade. Required if
4993
                duration is set.
4994
            period (int, optional): How often the Manager will repeat the
4995
                scheduled task. Must be an integer > 0.
4996
            period_unit (str, optional): Unit of the period. One of second,
4997
                minute, hour, day, week, month, year, decade. Required if
4998
                period is set.
4999
            timezone (str, optional): The timezone the schedule will follow
5000
5001
        Returns:
5002
            The response. See :py:meth:`send_command` for details.
5003
        """
5004
        if not schedule_id:
5005
            raise RequiredArgument(
5006
                "modify_schedule requires a schedule_id" "argument"
5007
            )
5008
5009
        cmd = XmlCommand("modify_schedule")
5010
        cmd.set_attribute("schedule_id", schedule_id)
5011
5012
        if comment:
5013
            cmd.add_element("comment", comment)
5014
5015
        if name:
5016
            cmd.add_element("name", name)
5017
5018
        if (
5019
            first_time_minute is not None
5020
            or first_time_hour is not None
5021
            or first_time_day_of_month is not None
5022
            or first_time_month is not None
5023
            or first_time_year is not None
5024
        ):
5025
5026
            if first_time_minute is None:
5027
                raise RequiredArgument(
5028
                    "Setting first_time requires first_time_minute argument"
5029
                )
5030
            elif (
5031
                not isinstance(first_time_minute, numbers.Integral)
5032
                or first_time_minute < 0
5033
            ):
5034
                raise InvalidArgument(
5035
                    "first_time_minute argument of modify_schedule needs to be "
5036
                    "an integer greater or equal 0"
5037
                )
5038
5039
            if first_time_hour is None:
5040
                raise RequiredArgument(
5041
                    "Setting first_time requires first_time_hour argument"
5042
                )
5043
            elif (
5044
                not isinstance(first_time_hour, numbers.Integral)
5045
                or first_time_hour < 0
5046
            ):
5047
                raise InvalidArgument(
5048
                    "first_time_hour argument of modify_schedule needs to be "
5049
                    "an integer greater or equal 0"
5050
                )
5051
5052
            if first_time_day_of_month is None:
5053
                raise RequiredArgument(
5054
                    "Setting first_time requires first_time_day_of_month "
5055
                    "argument"
5056
                )
5057
            elif (
5058
                not isinstance(first_time_day_of_month, numbers.Integral)
5059
                or first_time_day_of_month < 1
5060
                or first_time_day_of_month > 31
5061
            ):
5062
                raise InvalidArgument(
5063
                    "first_time_day_of_month argument of modify_schedule needs "
5064
                    "to be an integer between 1 and 31"
5065
                )
5066
5067
            if first_time_month is None:
5068
                raise RequiredArgument(
5069
                    "Setting first_time requires first_time_month argument"
5070
                )
5071
            elif (
5072
                not isinstance(first_time_month, numbers.Integral)
5073
                or first_time_month < 1
5074
                or first_time_month > 12
5075
            ):
5076
                raise InvalidArgument(
5077
                    "first_time_month argument of modify_schedule needs "
5078
                    "to be an integer between 1 and 12"
5079
                )
5080
5081
            if first_time_year is None:
5082
                raise RequiredArgument(
5083
                    "Setting first_time requires first_time_year argument"
5084
                )
5085
            elif (
5086
                not isinstance(first_time_year, numbers.Integral)
5087
                or first_time_year < 1970
5088
            ):
5089
                raise InvalidArgument(
5090
                    "first_time_year argument of create_schedule needs "
5091
                    "to be an integer greater or equal 1970"
5092
                )
5093
5094
            _xmlftime = cmd.add_element("first_time")
5095
            _xmlftime.add_element("minute", str(first_time_minute))
5096
            _xmlftime.add_element("hour", str(first_time_hour))
5097
            _xmlftime.add_element("day_of_month", str(first_time_day_of_month))
5098
            _xmlftime.add_element("month", str(first_time_month))
5099
            _xmlftime.add_element("year", str(first_time_year))
5100
5101
        if duration is not None:
5102
            if not duration_unit:
5103
                raise RequiredArgument(
5104
                    "Setting duration requires duration_unit argument"
5105
                )
5106
5107
            if not duration_unit in TIME_UNITS:
5108
                raise InvalidArgument(
5109
                    "duration_unit must be one of {units} but {actual} has "
5110
                    "been passed".format(
5111
                        units=", ".join(TIME_UNITS), actual=duration_unit