Code Duplication    Length = 180-184 lines in 2 locations

gvm/protocols/gmpv7.py 2 locations

@@ 5708-5891 (lines=184) @@
5705
5706
        return self._send_xml_command(cmd)
5707
5708
    def modify_schedule(
5709
        self,
5710
        schedule_id: str,
5711
        *,
5712
        comment: Optional[str] = None,
5713
        name: Optional[str] = None,
5714
        first_time_minute: Optional[int] = None,
5715
        first_time_hour: Optional[int] = None,
5716
        first_time_day_of_month: Optional[int] = None,
5717
        first_time_month: Optional[int] = None,
5718
        first_time_year: Optional[int] = None,
5719
        duration: Optional[int] = None,
5720
        duration_unit: Optional[TimeUnit] = None,
5721
        period: Optional[int] = None,
5722
        period_unit: Optional[TimeUnit] = None,
5723
        timezone: Optional[str] = None
5724
    ) -> Any:
5725
        """Modifies an existing schedule.
5726
5727
        Arguments:
5728
            schedule_id: UUID of schedule to modify.
5729
            name: Name of the schedule
5730
            comment: Comment for the schedule
5731
            first_time_minute: First time minute the schedule will run. Must be
5732
                an integer >= 0.
5733
            first_time_hour: First time hour the schedule will run. Must be an
5734
                integer >= 0.
5735
            first_time_day_of_month: First time day of month the schedule will
5736
                run. Must be an integer > 0 <= 31.
5737
            first_time_month: First time month the schedule will run. Must be an
5738
                integer >= 1 <= 12.
5739
            first_time_year: First time year the schedule will run
5740
            duration: How long the Manager will run the scheduled task for until
5741
                it gets paused if not finished yet.
5742
            duration_unit: Unit of the duration. One of second, minute, hour,
5743
                day, week, month, year, decade. Required if duration is set.
5744
            period: How often the Manager will repeat the scheduled task. Must
5745
                be an integer > 0.
5746
            period_unit: Unit of the period. One of second, minute, hour, day,
5747
                week, month, year, decade. Required if period is set.
5748
            timezone: The timezone the schedule will follow
5749
5750
        Returns:
5751
            The response. See :py:meth:`send_command` for details.
5752
        """
5753
        if not schedule_id:
5754
            raise RequiredArgument(
5755
                "modify_schedule requires a schedule_id" "argument"
5756
            )
5757
5758
        cmd = XmlCommand("modify_schedule")
5759
        cmd.set_attribute("schedule_id", schedule_id)
5760
5761
        if comment:
5762
            cmd.add_element("comment", comment)
5763
5764
        if name:
5765
            cmd.add_element("name", name)
5766
5767
        if (
5768
            first_time_minute is not None
5769
            or first_time_hour is not None
5770
            or first_time_day_of_month is not None
5771
            or first_time_month is not None
5772
            or first_time_year is not None
5773
        ):
5774
5775
            if first_time_minute is None:
5776
                raise RequiredArgument(
5777
                    "Setting first_time requires first_time_minute argument"
5778
                )
5779
            elif (
5780
                not isinstance(first_time_minute, numbers.Integral)
5781
                or first_time_minute < 0
5782
            ):
5783
                raise InvalidArgument(
5784
                    "first_time_minute argument of modify_schedule needs to be "
5785
                    "an integer greater or equal 0"
5786
                )
5787
5788
            if first_time_hour is None:
5789
                raise RequiredArgument(
5790
                    "Setting first_time requires first_time_hour argument"
5791
                )
5792
            elif (
5793
                not isinstance(first_time_hour, numbers.Integral)
5794
                or first_time_hour < 0
5795
            ):
5796
                raise InvalidArgument(
5797
                    "first_time_hour argument of modify_schedule needs to be "
5798
                    "an integer greater or equal 0"
5799
                )
5800
5801
            if first_time_day_of_month is None:
5802
                raise RequiredArgument(
5803
                    "Setting first_time requires first_time_day_of_month "
5804
                    "argument"
5805
                )
5806
            elif (
5807
                not isinstance(first_time_day_of_month, numbers.Integral)
5808
                or first_time_day_of_month < 1
5809
                or first_time_day_of_month > 31
5810
            ):
5811
                raise InvalidArgument(
5812
                    "first_time_day_of_month argument of modify_schedule needs "
5813
                    "to be an integer between 1 and 31"
5814
                )
5815
5816
            if first_time_month is None:
5817
                raise RequiredArgument(
5818
                    "Setting first_time requires first_time_month argument"
5819
                )
5820
            elif (
5821
                not isinstance(first_time_month, numbers.Integral)
5822
                or first_time_month < 1
5823
                or first_time_month > 12
5824
            ):
5825
                raise InvalidArgument(
5826
                    "first_time_month argument of modify_schedule needs "
5827
                    "to be an integer between 1 and 12"
5828
                )
5829
5830
            if first_time_year is None:
5831
                raise RequiredArgument(
5832
                    "Setting first_time requires first_time_year argument"
5833
                )
5834
            elif (
5835
                not isinstance(first_time_year, numbers.Integral)
5836
                or first_time_year < 1970
5837
            ):
5838
                raise InvalidArgument(
5839
                    "first_time_year argument of create_schedule needs "
5840
                    "to be an integer greater or equal 1970"
5841
                )
5842
5843
            _xmlftime = cmd.add_element("first_time")
5844
            _xmlftime.add_element("minute", str(first_time_minute))
5845
            _xmlftime.add_element("hour", str(first_time_hour))
5846
            _xmlftime.add_element("day_of_month", str(first_time_day_of_month))
5847
            _xmlftime.add_element("month", str(first_time_month))
5848
            _xmlftime.add_element("year", str(first_time_year))
5849
5850
        if duration is not None:
5851
            if not duration_unit:
5852
                raise RequiredArgument(
5853
                    "Setting duration requires duration_unit argument"
5854
                )
5855
5856
            if not isinstance(duration_unit, TimeUnit):
5857
                raise InvalidArgument(
5858
                    function="modify_schedule", argument="duration_unit"
5859
                )
5860
5861
            if not isinstance(duration, numbers.Integral) or duration < 1:
5862
                raise InvalidArgument(
5863
                    "duration argument must be an integer greater than 0"
5864
                )
5865
5866
            _xmlduration = cmd.add_element("duration", str(duration))
5867
            _xmlduration.add_element("unit", duration_unit.value)
5868
5869
        if period is not None:
5870
            if not period_unit:
5871
                raise RequiredArgument(
5872
                    "Setting period requires period_unit argument"
5873
                )
5874
5875
            if not isinstance(period_unit, TimeUnit):
5876
                raise InvalidArgument(
5877
                    function="modify_schedule", argument="period_unit"
5878
                )
5879
5880
            if not isinstance(period, numbers.Integral) or period < 1:
5881
                raise InvalidArgument(
5882
                    "period argument must be an integer greater than 0"
5883
                )
5884
5885
            _xmlperiod = cmd.add_element("period", str(period))
5886
            _xmlperiod.add_element("unit", period_unit.value)
5887
5888
        if timezone:
5889
            cmd.add_element("timezone", timezone)
5890
5891
        return self._send_xml_command(cmd)
5892
5893
    def modify_setting(
5894
        self,
@@ 2054-2233 (lines=180) @@
2051
        cmd.add_element("copy", scanner_id)
2052
        return self._send_xml_command(cmd)
2053
2054
    def create_schedule(
2055
        self,
2056
        name: str,
2057
        *,
2058
        comment: Optional[str] = None,
2059
        first_time_minute: Optional[int] = None,
2060
        first_time_hour: Optional[int] = None,
2061
        first_time_day_of_month: Optional[int] = None,
2062
        first_time_month: Optional[int] = None,
2063
        first_time_year: Optional[int] = None,
2064
        duration: Optional[int] = None,
2065
        duration_unit: Optional[TimeUnit] = None,
2066
        period: Optional[int] = None,
2067
        period_unit: Optional[TimeUnit] = None,
2068
        timezone: Optional[str] = None
2069
    ) -> Any:
2070
        """Create a new schedule
2071
2072
        Arguments:
2073
            name: Name of the schedule
2074
            comment: Comment for the schedule
2075
            first_time_minute: First time minute the schedule will run. Must be
2076
                an integer >= 0.
2077
            first_time_hour: First time hour the schedule will run. Must be an
2078
                integer >= 0.
2079
            first_time_day_of_month: First time day of month the schedule will
2080
                run. Must be an integer > 0 <= 31.
2081
            first_time_month: First time month the schedule will run. Must be an
2082
                integer >= 1 <= 12.
2083
            first_time_year: First time year the schedule will run. Must be an
2084
                integer >= 1970.
2085
            duration: How long the Manager will run the scheduled task for until
2086
                it gets paused if not finished yet. Must be an integer > 0.
2087
            duration_unit: Unit of the duration. One of second,
2088
                minute, hour, day, week, month, year, decade. Required if
2089
                duration is set.
2090
            period: How often the Manager will repeat the
2091
                scheduled task. Must be an integer > 0.
2092
            period_unit: Unit of the period. One of second,
2093
                minute, hour, day, week, month, year, decade. Required if
2094
                period is set.
2095
            timezone: The timezone the schedule will follow
2096
2097
        Returns:
2098
            The response. See :py:meth:`send_command` for details.
2099
        """
2100
        if not name:
2101
            raise RequiredArgument("create_schedule requires a name argument")
2102
2103
        cmd = XmlCommand("create_schedule")
2104
        cmd.add_element("name", name)
2105
2106
        if comment:
2107
            cmd.add_element("comment", comment)
2108
2109
        if (
2110
            first_time_minute is not None
2111
            or first_time_hour is not None
2112
            or first_time_day_of_month is not None
2113
            or first_time_month is not None
2114
            or first_time_year is not None
2115
        ):
2116
2117
            if first_time_minute is None:
2118
                raise RequiredArgument(
2119
                    "Setting first_time requires first_time_minute argument"
2120
                )
2121
            elif (
2122
                not isinstance(first_time_minute, numbers.Integral)
2123
                or first_time_minute < 0
2124
            ):
2125
                raise InvalidArgument(
2126
                    "first_time_minute argument of create_schedule needs to be "
2127
                    "an integer greater or equal 0"
2128
                )
2129
2130
            if first_time_hour is None:
2131
                raise RequiredArgument(
2132
                    "Setting first_time requires first_time_hour argument"
2133
                )
2134
            elif (
2135
                not isinstance(first_time_hour, numbers.Integral)
2136
                or first_time_hour < 0
2137
            ):
2138
                raise InvalidArgument(
2139
                    "first_time_hour argument of create_schedule needs to be "
2140
                    "an integer greater or equal 0"
2141
                )
2142
2143
            if first_time_day_of_month is None:
2144
                raise RequiredArgument(
2145
                    "Setting first_time requires first_time_day_of_month "
2146
                    "argument"
2147
                )
2148
            elif (
2149
                not isinstance(first_time_day_of_month, numbers.Integral)
2150
                or first_time_day_of_month < 1
2151
                or first_time_day_of_month > 31
2152
            ):
2153
                raise InvalidArgument(
2154
                    "first_time_day_of_month argument of create_schedule needs "
2155
                    "to be an integer between 1 and 31"
2156
                )
2157
2158
            if first_time_month is None:
2159
                raise RequiredArgument(
2160
                    "Setting first_time requires first_time_month argument"
2161
                )
2162
            elif (
2163
                not isinstance(first_time_month, numbers.Integral)
2164
                or first_time_month < 1
2165
                or first_time_month > 12
2166
            ):
2167
                raise InvalidArgument(
2168
                    "first_time_month argument of create_schedule needs "
2169
                    "to be an integer between 1 and 12"
2170
                )
2171
2172
            if first_time_year is None:
2173
                raise RequiredArgument(
2174
                    "Setting first_time requires first_time_year argument"
2175
                )
2176
            elif (
2177
                not isinstance(first_time_year, numbers.Integral)
2178
                or first_time_year < 1970
2179
            ):
2180
                raise InvalidArgument(
2181
                    "first_time_year argument of create_schedule needs "
2182
                    "to be an integer greater or equal 1970"
2183
                )
2184
2185
            _xmlftime = cmd.add_element("first_time")
2186
            _xmlftime.add_element("minute", str(first_time_minute))
2187
            _xmlftime.add_element("hour", str(first_time_hour))
2188
            _xmlftime.add_element("day_of_month", str(first_time_day_of_month))
2189
            _xmlftime.add_element("month", str(first_time_month))
2190
            _xmlftime.add_element("year", str(first_time_year))
2191
2192
        if duration is not None:
2193
            if not duration_unit:
2194
                raise RequiredArgument(
2195
                    "Setting duration requires duration_unit argument"
2196
                )
2197
2198
            if not isinstance(duration_unit, TimeUnit):
2199
                raise InvalidArgument(
2200
                    function="create_schedule", argument="duration_unit"
2201
                )
2202
2203
            if not isinstance(duration, numbers.Integral) or duration < 1:
2204
                raise InvalidArgument(
2205
                    "duration argument must be an integer greater than 0"
2206
                )
2207
2208
            _xmlduration = cmd.add_element("duration", str(duration))
2209
            _xmlduration.add_element("unit", duration_unit.value)
2210
2211
        if period is not None:
2212
            if not period_unit:
2213
                raise RequiredArgument(
2214
                    "Setting period requires period_unit argument"
2215
                )
2216
2217
            if not isinstance(period_unit, TimeUnit):
2218
                raise InvalidArgument(
2219
                    function="create_schedule", argument="period_unit"
2220
                )
2221
2222
            if not isinstance(period, numbers.Integral) or period < 0:
2223
                raise InvalidArgument(
2224
                    "period argument must be a positive integer"
2225
                )
2226
2227
            _xmlperiod = cmd.add_element("period", str(period))
2228
            _xmlperiod.add_element("unit", period_unit.value)
2229
2230
        if timezone:
2231
            cmd.add_element("timezone", timezone)
2232
2233
        return self._send_xml_command(cmd)
2234
2235
    def clone_schedule(self, schedule_id: str) -> Any:
2236
        """Clone an existing schedule