Passed
Push — master ( bd8417...61b038 )
by
unknown
03:43 queued 01:23
created

gvm.xml._GmpCommandFactory.create_alert_command()   C

Complexity

Conditions 11

Size

Total Lines 37
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 28
nop 8
dl 0
loc 37
rs 5.4
c 0
b 0
f 0

How to fix   Complexity    Many Parameters   

Complexity

Complex classes like gvm.xml._GmpCommandFactory.create_alert_command() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
# -*- coding: utf-8 -*-
0 ignored issues
show
coding-style introduced by
Too many lines in module (1857/1000)
Loading history...
2
# Copyright (C) 2018 Greenbone Networks GmbH
3
#
4
# SPDX-License-Identifier: GPL-3.0-or-later
5
#
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19
import defusedxml.lxml as secET
20
21
from lxml import etree
22
23
class XmlCommandElement:
24
25
    def __init__(self, element):
26
        self._element = element
27
28
    def add_element(self, name, text=None, attrs=None):
29
        node = etree.SubElement(self._element, name, attrib=attrs)
30
        node.text = text
31
        return XmlCommandElement(node)
32
33
    def set_attribute(self, name, value):
34
        self._element.set(name, value)
35
36
    def set_attributes(self, attrs):
37
        """Set several attributes at once.
38
39
        Arguments:
40
            attrs (dict): Attributes to be set on the element
41
        """
42
        for key, value in attrs.items():
43
            self._element.set(key, value)
44
45
    def append_xml_str(self, xml_text):
46
        """Append a xml element in string format."""
47
        node = secET.fromstring(xml_text)
48
        self._element.append(node)
49
50
    def to_string(self):
51
        return etree.tostring(self._element).decode('utf-8')
52
53
    def __str__(self):
54
        return self.to_string()
55
56
57
class XmlCommand(XmlCommandElement):
58
59
    def __init__(self, name):
60
        super().__init__(etree.Element(name))
61
62
63
class _GmpCommandFactory:
0 ignored issues
show
best-practice introduced by
Too many public methods (108/30)
Loading history...
64
65
    """Factory to create gmp - Greenbone Management Protocol - commands
66
    """
67
68
    def create_agent_command(self, installer, signature, name, comment='',
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
69
                             copy='', howto_install='', howto_use=''):
70
71
        cmd = XmlCommand('create_agent')
72
        cmd.add_element('installer', installer)
73
        cmd.add_element('signature', signature)
74
        cmd.add_element('name', name)
75
76
        if comment:
77
            cmd.add_element('comment', comment)
78
79
        if copy:
80
            cmd.add_element('copy', copy)
81
82
        if howto_install:
83
            cmd.add_element('howto_install', howto_install)
84
85
        if howto_use:
86
            cmd.add_element('howto_use', howto_use)
87
88
        return cmd.to_string()
89
90
    def create_alert_command(self, name, condition, event, method, filter_id='',
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (16/15).
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
91
                             copy='', comment=''):
92
93
        cmd = XmlCommand('create_alert')
94
        cmd.add_element('name', name)
95
96
        if len(condition) > 1:
97
            conditions = cmd.add_element('condition', condition[0])
98
            for value, key in condition[1].items():
99
                _data = conditions.add_element('data', value)
100
                _data.add_element('name', key)
101
102
        elif condition[0] == "Always":
103
            conditions = cmd.add_element('condition', condition[0])
104
105
        if len(event) > 1:
106
            events = cmd.add_element('event', event[0])
107
            for value, key in event[1].items():
108
                _data = events.add_element('data', value)
109
                _data.add_element('name', key)
110
111
        if len(method) > 1:
112
            methods = cmd.add_element('method', method[0])
113
            for value, key in method[1].items():
114
                _data = methods.add_element('data', value)
115
                _data.add_element('name', key)
116
117
        if filter_id:
118
            cmd.add_element('filter', attrs={'id': filter_id})
119
120
        if copy:
121
            cmd.add_element('copy', copy)
122
123
        if comment:
124
            cmd.add_element('comment', comment)
125
126
        return cmd.to_string()
127
128
    def create_asset_command(self, name, asset_type, comment=''):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
129
        if asset_type not in ('host', 'os'):
130
            raise ValueError('create_asset requires asset_type to be either '
131
                             'host or os')
132
        cmd = XmlCommand('create_asset')
133
        asset = cmd.add_element('asset')
134
        asset.add_element('type', asset_type)
135
        asset.add_element('name', name)
136
137
        if comment:
138
            asset.add_element('comment', comment)
139
140
        return cmd.to_string()
141
142
    def create_authenticate_command(self, username, password):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
143
        """Generates string for authentication on gvmd
144
145
        Creates the gmp authentication xml string.
146
        Inserts the username and password into it.
147
148
        Keyword Arguments:
149
            username {str} -- Username for GVM User
150
            password {str} -- Password for GVM User
151
        """
152
        cmd = XmlCommand('authenticate')
153
154
        credentials = cmd.add_element('credentials')
155
        credentials.add_element('username', username)
156
        credentials.add_element('password', password)
157
158
        return cmd.to_string()
159
160
    def create_config_command(self, copy_id, name):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
161
        """Generates xml string for create config on gvmd."""
162
        cmd = XmlCommand('create_config')
163
        cmd.add_element('copy', copy_id)
164
        cmd.add_element('name', name)
165
166
        return cmd.to_string()
167
168 View Code Duplication
    def create_credential_command(self, name, kwargs):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (22/15).
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
169
        """Generates xml string for create credential on gvmd."""
170
        cmd = XmlCommand('create_credential')
171
        cmd.add_element('name', name)
172
173
        comment = kwargs.get('comment', '')
174
        if comment:
175
            cmd.add_element('comment', comment)
176
177
        copy = kwargs.get('copy', '')
178
        if copy:
179
            cmd.add_element('copy', copy)
180
181
        allow_insecure = kwargs.get('allow_insecure', '')
182
        if allow_insecure:
183
            cmd.add_element('allow_insecure', allow_insecure)
184
185
        certificate = kwargs.get('certificate', '')
186
        if certificate:
187
            cmd.add_element('certificate', certificate)
188
189
        key = kwargs.get('key', '')
190
        if key:
191
            phrase = key['phrase']
192
            private = key['private']
193
            if not phrase:
194
                raise ValueError('create_credential requires a phrase element')
195
            if not private:
196
                raise ValueError('create_credential requires a '
197
                                 'private element')
198
199
            _xmlkey = cmd.add_element('key')
200
            _xmlkey.add_element('phrase', phrase)
201
            _xmlkey.add_element('private', private)
202
203
        login = kwargs.get('login', '')
204
        if login:
205
            cmd.add_element('login', login)
206
207
        password = kwargs.get('password', '')
208
        if password:
209
            cmd.add_element('password', password)
210
211
        auth_algorithm = kwargs.get('auth_algorithm', '')
212
        if auth_algorithm:
213
            if auth_algorithm not in ('md5', 'sha1'):
214
                raise ValueError('create_credential requires auth_algorithm '
215
                                 'to be either md5 or sha1')
216
            cmd.add_element('auth_algorithm', auth_algorithm)
217
218
        community = kwargs.get('community', '')
219
        if community:
220
            cmd.add_element('community', community)
221
222
        privacy = kwargs.get('privacy', '')
223
        if privacy:
224
            algorithm = privacy.algorithm
225
            if algorithm not in ('aes', 'des'):
226
                raise ValueError('create_credential requires algorithm '
227
                                 'to be either aes or des')
228
            p_password = privacy.password
229
            _xmlprivacy = cmd.add_element('privacy')
230
            _xmlprivacy.add_element('algorithm', algorithm)
231
            _xmlprivacy.add_element('password', p_password)
232
233
        cred_type = kwargs.get('type', '')
234
        if cred_type:
235
            if cred_type not in ('cc', 'snmp', 'up', 'usk'):
236
                raise ValueError('create_credential requires type '
237
                                 'to be either cc, snmp, up or usk')
238
            cmd.add_element('type', cred_type)
239
240
        return cmd.to_string()
241
242
    def create_group_command(self, name, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
243
        """Generates xml string for create group on gvmd."""
244
245
        cmd = XmlCommand('create_group')
246
        cmd.add_element('name', name)
247
248
        comment = kwargs.get('comment', '')
249
        if comment:
250
            cmd.add_element('comment', comment)
251
252
        copy = kwargs.get('copy', '')
253
        if copy:
254
            cmd.add_element('copy', copy)
255
256
        special = kwargs.get('special', '')
257
        if special:
258
            _xmlspecial = cmd.add_element('specials')
259
            _xmlspecial.add_element('full')
260
261
        users = kwargs.get('users', '')
262
        if users:
263
            cmd.add_element('users', users)
264
265
        return cmd.to_string()
266
267
    def create_note_command(self, text, nvt_oid, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
268
        """Generates xml string for create note on gvmd."""
269
270
        cmd = XmlCommand('create_note')
271
        cmd.add_element('text', text)
272
        cmd.add_element('nvt', attrs={"oid": nvt_oid})
273
274
        active = kwargs.get('active', '')
275
        if active:
276
            cmd.add_element('active', active)
277
278
        comment = kwargs.get('comment', '')
279
        if comment:
280
            cmd.add_element('comment', comment)
281
282
        copy = kwargs.get('copy', '')
283
        if copy:
284
            cmd.add_element('copy', copy)
285
286
        hosts = kwargs.get('hosts', '')
287
        if hosts:
288
            cmd.add_element('hosts', hosts)
289
290
        port = kwargs.get('port', '')
291
        if port:
292
            cmd.add_element('port', port)
293
294
        result_id = kwargs.get('result_id', '')
295
        if result_id:
296
            cmd.add_element('result', attrs={'id': result_id})
297
298
        severity = kwargs.get('severity', '')
299
        if severity:
300
            cmd.add_element('severity', severity)
301
302
        task_id = kwargs.get('task_id', '')
303
        if task_id:
304
            cmd.add_element('task', attrs={'id': task_id})
305
306
        threat = kwargs.get('threat', '')
307
        if threat:
308
            cmd.add_element('threat', threat)
309
310
        return cmd.to_string()
311
312
    def create_override_command(self, text, nvt_oid, kwargs):
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (17/15).
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
313
        """Generates xml string for create override on gvmd."""
314
315
        cmd = XmlCommand('create_override')
316
        cmd.add_element('text', text)
317
        cmd.add_element('nvt', attrs={'oid': nvt_oid})
318
319
        active = kwargs.get('active', '')
320
        if active:
321
            cmd.add_element('active', active)
322
323
        comment = kwargs.get('comment', '')
324
        if comment:
325
            cmd.add_element('comment', comment)
326
327
        copy = kwargs.get('copy', '')
328
        if copy:
329
            cmd.add_element('copy', copy)
330
331
        hosts = kwargs.get('hosts', '')
332
        if hosts:
333
            cmd.add_element('hosts', hosts)
334
335
        port = kwargs.get('port', '')
336
        if port:
337
            cmd.add_element('port', port)
338
339
        result_id = kwargs.get('result_id', '')
340
        if result_id:
341
            cmd.add_element('result', attrs={'id': result_id})
342
343
        severity = kwargs.get('severity', '')
344
        if severity:
345
            cmd.add_element('severity', severity)
346
347
        new_severity = kwargs.get('new_severity', '')
348
        if new_severity:
349
            cmd.add_element('new_severity', new_severity)
350
351
        task_id = kwargs.get('task_id', '')
352
        if task_id:
353
            cmd.add_element('task', attrs={'id': task_id})
354
355
        threat = kwargs.get('threat', '')
356
        if threat:
357
            cmd.add_element('threat', threat)
358
359
        new_threat = kwargs.get('new_threat', '')
360
        if new_threat:
361
            cmd.add_element('new_threat', new_threat)
362
363
        return cmd.to_string()
364
365
    def create_permission_command(self, name, subject_id, type, kwargs):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
366
        # pretty(gmp.create_permission('get_version',
367
        # 'cc9cac5e-39a3-11e4-abae-406186ea4fc5', 'role'))
368
        # libs.gvm_connection.GMPError: Error in NAME
369
        # TODO: Research why!!
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
370
371
        if not name:
372
            raise ValueError('create_permission requires a name element')
373
        if not subject_id:
374
            raise ValueError('create_permission requires a subject_id element')
375
        if type not in ('user', 'group', 'role'):
376
            raise ValueError('create_permission requires type '
377
                             'to be either user, group or role')
378
379
        cmd = XmlCommand('create_permission')
380
        cmd.add_element('name', name)
381
        _xmlsubject = cmd.add_element('subject', attrs={'id': subject_id})
382
        _xmlsubject.add_element('type', type)
383
384
        comment = kwargs.get('comment', '')
385
        if comment:
386
            cmd.add_element('comment', comment)
387
388
        copy = kwargs.get('copy', '')
389
        if copy:
390
            cmd.add_element('copy', copy)
391
392
        resource = kwargs.get('resource', '')
393
        if resource:
394
            resource_id = resource.id
395
            resource_type = resource.type
396
            _xmlresource = cmd.add_element('resource',
397
                                           attrs={'id': resource_id})
398
            _xmlresource.add_element('type', resource_type)
399
400
        return cmd.to_string()
401
402
    def create_port_list_command(self, name, port_range, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
403
        """Generates xml string for create port list on gvmd."""
404
        if not name:
405
            raise ValueError('create_port_list requires a name element')
406
        if not port_range:
407
            raise ValueError('create_port_list requires a port_range element')
408
409
        cmd = XmlCommand('create_port_list')
410
        cmd.add_element('name', name)
411
        cmd.add_element('port_range', port_range)
412
413
        comment = kwargs.get('comment', '')
414
        if comment:
415
            cmd.add_element('comment', comment)
416
417
        copy = kwargs.get('copy', '')
418
        if copy:
419
            cmd.add_element('copy', copy)
420
421
        return cmd.to_string()
422
423
    def create_port_range_command(self, port_list_id, start, end, type,
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
424
                                  comment=''):
425
        """Generates xml string for create port range on gvmd."""
426
427
        if not port_list_id:
428
            raise ValueError('create_port_range requires '
429
                             'a port_list_id element')
430
        if not type:
431
            raise ValueError('create_port_range requires a type element')
432
433
        cmd = XmlCommand('create_port_range')
434
        cmd.add_element('port_list', attrs={'id': port_list_id})
435
        cmd.add_element('start', start)
436
        cmd.add_element('end', end)
437
        cmd.add_element('type', type)
438
439
        if comment:
440
            cmd.add_element('comment', comment)
441
442
        return cmd.to_string()
443
444
    def create_report_command(self, report_xml_string, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
445
        """Generates xml string for create report on gvmd."""
446
447
        if not report_xml_string:
448
            raise ValueError('create_report requires a report')
449
450
        task_id = kwargs.get('task_id', '')
451
        task_name = kwargs.get('task_name', '')
452
453
        cmd = XmlCommand('create_report')
454
        comment = kwargs.get('comment', '')
455
        if task_id:
456
            cmd.add_element('task', attrs={'id': task_id})
457
        elif task_name:
458
            _xmltask = cmd.add_element('task')
459
            _xmltask.add_element('name', task_name)
460
            if comment:
461
                _xmltask.add_element('comment', comment)
462
        else:
463
            raise ValueError('create_report requires an id or name for a task')
464
465
        in_assets = kwargs.get('in_assets', '')
466
        if in_assets:
467
            cmd.add_element('in_assets', in_assets)
468
469
        cmd.append_xml_str(report_xml_string)
470
471
        return cmd.to_string()
472
473
    def create_role_command(self, name, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
474
        """Generates xml string for create role on gvmd."""
475
476
        if not name:
477
            raise ValueError('create_role requires a name element')
478
479
        cmd = XmlCommand('create_role')
480
        cmd.add_element('name', name)
481
482
        comment = kwargs.get('comment', '')
483
        if comment:
484
            cmd.add_element('comment', comment)
485
486
        copy = kwargs.get('copy', '')
487
        if copy:
488
            cmd.add_element('copy', copy)
489
490
        users = kwargs.get('users', '')
491
        if users:
492
            cmd.add_element('users', users)
493
494
        return cmd.to_string()
495
496
    def create_scanner_command(self, name, host, port, type, ca_pub,
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
497
                               credential_id, kwargs):
498
        """Generates xml string for create scanner on gvmd."""
499
        if not name:
500
            raise ValueError('create_scanner requires a name element')
501
        if not host:
502
            raise ValueError('create_scanner requires a host element')
503
        if not port:
504
            raise ValueError('create_scanner requires a port element')
505
        if not type:
506
            raise ValueError('create_scanner requires a type element')
507
        if not ca_pub:
508
            raise ValueError('create_scanner requires a ca_pub element')
509
        if not credential_id:
510
            raise ValueError('create_scanner requires a credential_id element')
511
512
        cmd = XmlCommand('create_scanner')
513
        cmd.add_element('name', name)
514
        cmd.add_element('host', host)
515
        cmd.add_element('port', port)
516
        cmd.add_element('type', type)
517
        cmd.add_element('ca_pub', ca_pub)
518
        cmd.add_element('credential', attrs={'id': str(credential_id)})
519
520
        comment = kwargs.get('comment', '')
521
        if comment:
522
            cmd.add_element('comment', comment)
523
524
        copy = kwargs.get('copy', '')
525
        if copy:
526
            cmd.add_element('copy', copy)
527
528
        return cmd.to_string()
529
530 View Code Duplication
    def create_schedule_command(self, name, kwargs):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (19/15).
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
531
        """Generates xml string for create schedule on gvmd."""
532
        if not name:
533
            raise ValueError('create_schedule requires a name element')
534
535
        cmd = XmlCommand('create_schedule')
536
        cmd.add_element('name', name)
537
538
        comment = kwargs.get('comment', '')
539
        if comment:
540
            cmd.add_element('comment', comment)
541
542
        copy = kwargs.get('copy', '')
543
        if copy:
544
            cmd.add_element('copy', copy)
545
546
        first_time = kwargs.get('first_time', '')
547
        if first_time:
548
            first_time_minute = first_time['minute']
549
            first_time_hour = first_time['hour']
550
            first_time_day_of_month = first_time['day_of_month']
551
            first_time_month = first_time['month']
552
            first_time_year = first_time['year']
553
554
            _xmlftime = cmd.add_element('first_time')
555
            _xmlftime.add_element('minute', first_time_minute)
556
            _xmlftime.add_element('hour', str(first_time_hour))
557
            _xmlftime.add_element('day_of_month', str(first_time_day_of_month))
558
            _xmlftime.add_element('month', str(first_time_month))
559
            _xmlftime.add_element('year', str(first_time_year))
560
561
        duration = kwargs.get('duration', '')
562
        if len(duration) > 1:
563
            _xmlduration = cmd.add_element('duration', str(duration[0]))
564
            _xmlduration.add_element('unit', str(duration[1]))
565
566
        period = kwargs.get('period', '')
567
        if len(period) > 1:
568
            _xmlperiod = cmd.add_element('period', str(period[0]))
569
            _xmlperiod.add_element('unit', str(period[1]))
570
571
        timezone = kwargs.get('timezone', '')
572
        if timezone:
573
            cmd.add_element('timezone', str(timezone))
574
575
        return cmd.to_string()
576
577
    def create_tag_command(self, name, resource_id, resource_type, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
578
        """Generates xml string for create tag on gvmd."""
579
580
        cmd = XmlCommand('create_tag')
581
        cmd.add_element('name', name)
582
        _xmlresource = cmd.add_element('resource',
583
                                       attrs={'id': str(resource_id)})
584
        _xmlresource.add_element('type', resource_type)
585
586
        comment = kwargs.get('comment', '')
587
        if comment:
588
            cmd.add_element('comment', comment)
589
590
        copy = kwargs.get('copy', '')
591
        if copy:
592
            cmd.add_element('copy', copy)
593
594
        value = kwargs.get('value', '')
595
        if value:
596
            cmd.add_element('value', value)
597
598
        active = kwargs.get('active', '')
599
        if active:
600
            cmd.add_element('active', active)
601
602
        return cmd.to_string()
603
604
    def create_task_command(self, name, config_id, target_id, scanner_id,
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
605
                            alert_ids=None, comment=''):
606
        """Generates xml string for create task on gvmd."""
607
608
        if alert_ids is None:
609
            alert_ids = []
610
        cmd = XmlCommand('create_task')
611
        cmd.add_element('name', name)
612
        cmd.add_element('comment', comment)
613
        cmd.add_element('config', attrs={'id': config_id})
614
        cmd.add_element('target', attrs={'id': target_id})
615
        cmd.add_element('scanner', attrs={'id': scanner_id})
616
617
        #if given the alert_id is wrapped and integrated suitably as xml
618
        if len(alert_ids) > 0:
619
            if isinstance(alert_ids, str):
620
                #if a single id is given as a string wrap it into a list
621
                alert_ids = [alert_ids]
622
            if isinstance(alert_ids, list):
623
                #parse all given alert id's
624
                for alert in alert_ids:
625
                    cmd.add_element('alert', attrs={'id': str(alert)})
626
627
        return cmd.to_string()
628
629
    def create_user_command(self, name, password, copy='', hosts_allow='0',
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
630
                            ifaces_allow='0', role_ids=(), hosts=None,
631
                            ifaces=None):
632
        """Generates xml string for create user on gvmd."""
633
        cmd = XmlCommand('create_user')
634
        cmd.add_element('name', name)
635
636
        if copy:
637
            cmd.add_element('copy', copy)
638
639
        if password:
640
            cmd.add_element('password', password)
641
642
        if hosts is not None:
643
            cmd.add_element('hosts', hosts, attrs={'allow': str(hosts_allow)})
644
645
        if ifaces is not None:
646
            cmd.add_element('ifaces', ifaces,
647
                            attrs={'allow': str(ifaces_allow)})
648
649
        if len(role_ids) > 0:
650
            for role in role_ids:
651
                cmd.add_element('role', attrs={'allow': str(role)})
652
653
        return cmd.to_string()
654
655
    def modify_agent_command(self, agent_id, name='', comment=''):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
656
        """Generates xml string for modify agent on gvmd."""
657
        if not agent_id:
658
            raise ValueError('modify_agent requires an agent_id element')
659
660
        cmd = XmlCommand('modify_agent')
661
        cmd.set_attribute('agent_id', str(agent_id))
662
        if name:
663
            cmd.add_element('name', name)
664
        if comment:
665
            cmd.add_element('comment', comment)
666
667
        return cmd.to_string()
668
669
    def modify_alert_command(self, alert_id, kwargs):
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (17/15).
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
670
        """Generates xml string for modify alert on gvmd."""
671
672
        if not alert_id:
673
            raise ValueError('modify_alert requires an agent_id element')
674
675
        cmd = XmlCommand('modify_alert')
676
        cmd.set_attribute('alert_id', str(alert_id))
677
678
        name = kwargs.get('name', '')
679
        if name:
680
            cmd.add_element('name', name)
681
682
        comment = kwargs.get('comment', '')
683
        if comment:
684
            cmd.add_element('comment', comment)
685
686
        filter_id = kwargs.get('filter_id', '')
687
        if filter_id:
688
            cmd.add_element('filter', attrs={'id': filter_id})
689
690
        event = kwargs.get('event', '')
691
        if len(event) > 1:
692
            _xmlevent = cmd.add_element('event', event[0])
693
            for value, key in event[1].items():
694
                _xmldata = _xmlevent.add_element('data', value)
695
                _xmldata.add_element('name', key)
696
697
        condition = kwargs.get('condition', '')
698
        if len(condition) > 1:
699
            _xmlcond = cmd.add_element('condition', condition[0])
700
            for value, key in condition[1].items():
701
                _xmldata = _xmlcond.add_element('data', value)
702
                _xmldata.add_element('name', key)
703
704
        method = kwargs.get('method', '')
705
        if len(method) > 1:
706
            _xmlmethod = cmd.add_element('method', method[0])
707
            for value, key in method[1].items():
708
                _xmldata = _xmlmethod.add_element('data', value)
709
                _xmldata.add_element('name', key)
710
711
        return cmd.to_string()
712
713
    def modify_asset_command(self, asset_id, comment):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
714
        """Generates xml string for modify asset on gvmd."""
715
        cmd = XmlCommand('modify_asset')
716
        cmd.set_attribute('asset_id', asset_id)
717
        cmd.add_element('comment', comment)
718
        return cmd.to_string()
719
720
    def modify_auth_command(self, group_name, auth_conf_settings):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
721
        """Generates xml string for modify auth on gvmd."""
722
        if not group_name:
723
            raise ValueError('modify_auth requires a group element '
724
                             'with a name attribute')
725
        if not auth_conf_settings:
726
            raise ValueError('modify_auth requires '
727
                             'an auth_conf_settings element')
728
        cmd = XmlCommand('modify_auth')
729
        _xmlgroup = cmd.add_element('group', attrs={'name': str(group_name)})
730
731
        for key, value in auth_conf_settings.items():
732
            _xmlauthconf = _xmlgroup.add_element('auth_conf_setting')
733
            _xmlauthconf.add_element('key', key)
734
            _xmlauthconf.add_element('value', value)
735
736
        return cmd.to_string()
737
738
    def modify_config_command(self, selection, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
739
        """Generates xml string for modify config on gvmd."""
740
        if selection not in ('nvt_pref', 'sca_pref',
741
                             'family_selection', 'nvt_selection'):
742
            raise ValueError('selection must be one of nvt_pref, sca_pref, '
743
                             'family_selection or nvt_selection')
744
        config_id = kwargs.get('config_id')
745
746
        cmd = XmlCommand('modify_config')
747
        cmd.set_attribute('config_id', str(config_id))
748
749
        if selection in 'nvt_pref':
750
            nvt_oid = kwargs.get('nvt_oid')
751
            name = kwargs.get('name')
752
            value = kwargs.get('value')
753
            _xmlpref = cmd.add_element('preference')
754
            _xmlpref.add_element('nvt', attrs={'oid': nvt_oid})
755
            _xmlpref.add_element('name', name)
756
            _xmlpref.add_element('value', value)
757
758
        elif selection in 'nvt_selection':
759
            nvt_oid = kwargs.get('nvt_oid')
760
            family = kwargs.get('family')
761
            _xmlnvtsel = cmd.add_element('nvt_selection')
762
            _xmlnvtsel.add_element('family', family)
763
764
            if isinstance(nvt_oid, list):
765
                for nvt in nvt_oid:
766
                    _xmlnvtsel.add_element('nvt', attrs={'oid': nvt})
767
            else:
768
                _xmlnvtsel.add_element('nvt', attrs={'oid': nvt_oid})
769
770
        elif selection in 'family_selection':
771
            family = kwargs.get('family')
772
            _xmlfamsel = cmd.add_element('family_selection')
773
            _xmlfamsel.add_element('growing', '1')
774
            _xmlfamily = _xmlfamsel.add_element('family')
775
            _xmlfamily.add_element('name', family)
776
            _xmlfamily.add_element('all', '1')
777
            _xmlfamily.add_element('growing', '1')
778
        else:
779
            raise NotImplementedError
780
781
        return cmd.to_string()
782
783 View Code Duplication
    def modify_credential_command(self, credential_id, kwargs):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (22/15).
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
784
        """Generates xml string for modify credential on gvmd."""
785
        if not credential_id:
786
            raise ValueError('modify_credential requires '
787
                             'a credential_id attribute')
788
789
        cmd = XmlCommand('modify_credential')
790
        cmd.set_attribute('credential_id', credential_id)
791
792
        comment = kwargs.get('comment', '')
793
        if comment:
794
            cmd.add_element('comment', comment)
795
796
        name = kwargs.get('name', '')
797
        if name:
798
            cmd.add_element('name', name)
799
800
        allow_insecure = kwargs.get('allow_insecure', '')
801
        if allow_insecure:
802
            cmd.add_element('allow_insecure', allow_insecure)
803
804
        certificate = kwargs.get('certificate', '')
805
        if certificate:
806
            cmd.add_element('certificate', certificate)
807
808
        key = kwargs.get('key', '')
809
        if key:
810
            phrase = key['phrase']
811
            private = key['private']
812
            if not phrase:
813
                raise ValueError('modify_credential requires a phrase element')
814
            if not private:
815
                raise ValueError('modify_credential requires '
816
                                 'a private element')
817
            _xmlkey = cmd.add_element('key')
818
            _xmlkey.add_element('phrase', phrase)
819
            _xmlkey.add_element('private', private)
820
821
        login = kwargs.get('login', '')
822
        if login:
823
            cmd.add_element('login', login)
824
825
        password = kwargs.get('password', '')
826
        if password:
827
            cmd.add_element('password', password)
828
829
        auth_algorithm = kwargs.get('auth_algorithm', '')
830
        if auth_algorithm:
831
            if auth_algorithm not in ('md5', 'sha1'):
832
                raise ValueError('modify_credential requires auth_algorithm '
833
                                 'to be either md5 or sha1')
834
            cmd.add_element('auth_algorithm', auth_algorithm)
835
836
        community = kwargs.get('community', '')
837
        if community:
838
            cmd.add_element('community', community)
839
840
        privacy = kwargs.get('privacy', '')
841
        if privacy:
842
            algorithm = privacy.algorithm
843
            if algorithm not in ('aes', 'des'):
844
                raise ValueError('modify_credential requires algorithm '
845
                                 'to be either aes or des')
846
            p_password = privacy.password
847
            _xmlprivacy = cmd.add_element('privacy')
848
            _xmlprivacy.add_element('algorithm', algorithm)
849
            _xmlprivacy.add_element('password', p_password)
850
851
        cred_type = kwargs.get('type', '')
852
        if cred_type:
853
            if cred_type not in ('cc', 'snmp', 'up', 'usk'):
854
                raise ValueError('modify_credential requires type '
855
                                 'to be either cc, snmp, up or usk')
856
            cmd.add_element('type', cred_type)
857
858
        return cmd.to_string()
859
860
    def modify_filter_command(self, filter_id, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
861
        """Generates xml string for modify filter on gvmd."""
862
        if not filter_id:
863
            raise ValueError('modify_filter requires a filter_id attribute')
864
865
        cmd = XmlCommand('modify_filter')
866
        cmd.set_attribute('filter_id', filter_id)
867
868
        comment = kwargs.get('comment', '')
869
        if comment:
870
            cmd.add_element('comment', comment)
871
872
        name = kwargs.get('name', '')
873
        if name:
874
            cmd.add_element('name', name)
875
876
        copy = kwargs.get('copy', '')
877
        if copy:
878
            cmd.add_element('copy', copy)
879
880
        term = kwargs.get('term', '')
881
        if term:
882
            cmd.add_element('term', term)
883
884
        filter_type = kwargs.get('type', '')
885
        if filter_type:
886
            if filter_type not in ('cc', 'snmp', 'up', 'usk'):
887
                raise ValueError('modify_filter requires type '
888
                                 'to be either cc, snmp, up or usk')
889
            cmd.add_element('type', filter_type)
890
891
        return cmd.to_string()
892
893 View Code Duplication
    def modify_group_command(self, group_id, kwargs):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
894
        """Generates xml string for modify group on gvmd."""
895
        if not group_id:
896
            raise ValueError('modify_group requires a group_id attribute')
897
898
        cmd = XmlCommand('modify_group')
899
        cmd.set_attribute('group_id', group_id)
900
901
        comment = kwargs.get('comment', '')
902
        if comment:
903
            cmd.add_element('comment', comment)
904
905
        name = kwargs.get('name', '')
906
        if name:
907
            cmd.add_element('name', name)
908
909
        users = kwargs.get('users', '')
910
        if users:
911
            cmd.add_element('users', users)
912
913
        return cmd.to_string()
914
915
    def modify_note_command(self, note_id, text, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
916
        """Generates xml string for modify note on gvmd."""
917
        if not note_id:
918
            raise ValueError('modify_note requires a note_id attribute')
919
        if not text:
920
            raise ValueError('modify_note requires a text element')
921
922
        cmd = XmlCommand('modify_note')
923
        cmd.set_attribute('note_id', note_id)
924
        cmd.add_element('text', text)
925
926
        active = kwargs.get('active', '')
927
        if active:
928
            cmd.add_element('active', active)
929
930
        hosts = kwargs.get('hosts', '')
931
        if hosts:
932
            cmd.add_element('hosts', hosts)
933
934
        port = kwargs.get('port', '')
935
        if port:
936
            cmd.add_element('port', port)
937
938
        result_id = kwargs.get('result_id', '')
939
        if result_id:
940
            cmd.add_element('result', attrs={'id': result_id})
941
942
        severity = kwargs.get('severity', '')
943
        if severity:
944
            cmd.add_element('severity', severity)
945
946
        task_id = kwargs.get('task_id', '')
947
        if task_id:
948
            cmd.add_element('task', attrs={'id': task_id})
949
950
        threat = kwargs.get('threat', '')
951
        if threat:
952
            cmd.add_element('threat', threat)
953
954
        return cmd.to_string()
955
956
    def modify_override_command(self, override_id, text, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
957
        """Generates xml string for modify override on gvmd."""
958
        cmd = XmlCommand('modify_override')
959
        cmd.set_attribute('override_id', override_id)
960
        cmd.add_element('text', text)
961
962
        active = kwargs.get('active', '')
963
        if active:
964
            cmd.add_element('active', active)
965
966
        hosts = kwargs.get('hosts', '')
967
        if hosts:
968
            cmd.add_element('hosts', hosts)
969
970
        port = kwargs.get('port', '')
971
        if port:
972
            cmd.add_element('port', port)
973
974
        result_id = kwargs.get('result_id', '')
975
        if result_id:
976
            cmd.add_element('result', attrs={'id': result_id})
977
978
        severity = kwargs.get('severity', '')
979
        if severity:
980
            cmd.add_element('severity', severity)
981
982
        new_severity = kwargs.get('new_severity', '')
983
        if new_severity:
984
            cmd.add_element('new_severity', new_severity)
985
986
        task_id = kwargs.get('task_id', '')
987
        if task_id:
988
            cmd.add_element('task', attrs={'id': task_id})
989
990
        threat = kwargs.get('threat', '')
991
        if threat:
992
            cmd.add_element('threat', threat)
993
994
        new_threat = kwargs.get('new_threat', '')
995
        if new_threat:
996
            cmd.add_element('new_threat', new_threat)
997
998
        return cmd.to_string()
999
1000
    def modify_permission_command(self, permission_id, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1001
        """Generates xml string for modify permission on gvmd."""
1002
        if not permission_id:
1003
            raise ValueError('modify_permission requires '
1004
                             'a permission_id element')
1005
1006
        cmd = XmlCommand('modify_permission')
1007
        cmd.set_attribute('permission_id', permission_id)
1008
1009
        comment = kwargs.get('comment', '')
1010
        if comment:
1011
            cmd.add_element('comment', comment)
1012
1013
        name = kwargs.get('name', '')
1014
        if name:
1015
            cmd.add_element('name', name)
1016
1017
        resource = kwargs.get('resource', '')
1018
        if resource:
1019
            resource_id = resource['id']
1020
            resource_type = resource['type']
1021
            _xmlresource = cmd.add_element('resource',
1022
                                           attrs={'id': resource_id})
1023
            _xmlresource.add_element('type', resource_type)
1024
1025
        subject = kwargs.get('subject', '')
1026
        if subject:
1027
            subject_id = subject['id']
1028
            subject_type = subject['type']
1029
            _xmlsubject = cmd.add_element('subject', attrs={'id': subject_id})
1030
            _xmlsubject.add_element('type', subject_type)
1031
1032
        return cmd.to_string()
1033
1034
    def modify_port_list_command(self, port_list_id, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1035
        """Generates xml string for modify port list on gvmd."""
1036
        if not port_list_id:
1037
            raise ValueError('modify_port_list requires '
1038
                             'a port_list_id attribute')
1039
        cmd = XmlCommand('modify_port_list')
1040
        cmd.set_attribute('port_list_id', port_list_id)
1041
1042
        comment = kwargs.get('comment', '')
1043
        if comment:
1044
            cmd.add_element('comment', comment)
1045
1046
        name = kwargs.get('name', '')
1047
        if name:
1048
            cmd.add_element('name', name)
1049
1050
        return cmd.to_string()
1051
1052
    def modify_report_command(self, report_id, comment):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1053
        """Generates xml string for modify report on gvmd."""
1054
        cmd = XmlCommand('modify_report')
1055
        cmd.set_attribute('report_id', report_id)
1056
        cmd.add_element('comment', comment)
1057
        return cmd.to_string()
1058
1059
    def modify_report_format_command(self, report_format_id, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1060
        """Generates xml string for modify report format on gvmd."""
1061
        if len(kwargs) < 1:
1062
            raise Exception('modify_report_format: Missing parameter')
1063
1064
        cmd = XmlCommand('modify_report_format')
1065
        cmd.set_attribute('report_format_id', report_format_id)
1066
1067
        active = kwargs.get('active', '')
1068
        if active:
1069
            cmd.add_element('active', active)
1070
1071
        name = kwargs.get('name', '')
1072
        if name:
1073
            cmd.add_element('name', name)
1074
1075
        summary = kwargs.get('summary', '')
1076
        if summary:
1077
            cmd.add_element('summary', summary)
1078
1079
        param = kwargs.get('param', '')
1080
        if param:
1081
            p_name = param[0]
1082
            p_value = param[1]
1083
            _xmlparam = cmd.add_element('param')
1084
            _xmlparam.add_element('name', p_name)
1085
            _xmlparam.add_element('value', p_value)
1086
1087
        return cmd.to_string()
1088
1089 View Code Duplication
    def modify_role_command(self, role_id, kwargs):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1090
        """Generates xml string for modify role on gvmd."""
1091
        if not role_id:
1092
            raise ValueError('modify_role requires a role_id element')
1093
1094
        cmd = XmlCommand('modify_role')
1095
        cmd.set_attribute('role_id', role_id)
1096
1097
        comment = kwargs.get('comment', '')
1098
        if comment:
1099
            cmd.add_element('comment', comment)
1100
1101
        name = kwargs.get('name', '')
1102
        if name:
1103
            cmd.add_element('name', name)
1104
1105
        users = kwargs.get('users', '')
1106
        if users:
1107
            cmd.add_element('users', users)
1108
1109
        return cmd.to_string()
1110
1111
    def modify_scanner_command(self, scanner_id, host, port, scanner_type,
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1112
                               kwargs):
1113
        """Generates xml string for modify scanner on gvmd."""
1114
        if not scanner_id:
1115
            raise ValueError('modify_scanner requires a scanner_id element')
1116
        if not host:
1117
            raise ValueError('modify_scanner requires a host element')
1118
        if not port:
1119
            raise ValueError('modify_scanner requires a port element')
1120
        if not scanner_type:
1121
            raise ValueError('modify_scanner requires a type element')
1122
1123
        cmd = XmlCommand('modify_scanner')
1124
        cmd.set_attribute('scanner_id', scanner_id)
1125
        cmd.add_element('host', host)
1126
        cmd.add_element('port', port)
1127
        cmd.add_element('type', scanner_type)
1128
1129
        comment = kwargs.get('comment', '')
1130
        if comment:
1131
            cmd.add_element('comment', comment)
1132
1133
        name = kwargs.get('name', '')
1134
        if name:
1135
            cmd.add_element('name', name)
1136
1137
        ca_pub = kwargs.get('ca_pub', '')
1138
        if ca_pub:
1139
            cmd.add_element('ca_pub', ca_pub)
1140
1141
        credential_id = kwargs.get('credential_id', '')
1142
        if credential_id:
1143
            cmd.add_element('credential', attrs={'id': str(credential_id)})
1144
1145
        return cmd.to_string()
1146
1147 View Code Duplication
    def modify_schedule_command(self, schedule_id, kwargs):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (19/15).
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1148
        """Generates xml string for modify schedule on gvmd."""
1149
        if not schedule_id:
1150
            raise ValueError('modify_schedule requires a schedule_id element')
1151
1152
        cmd = XmlCommand('modify_schedule')
1153
        cmd.set_attribute('schedule_id', schedule_id)
1154
        comment = kwargs.get('comment', '')
1155
        if comment:
1156
            cmd.add_element('comment', comment)
1157
1158
        name = kwargs.get('name', '')
1159
        if name:
1160
            cmd.add_element('name', name)
1161
1162
        first_time = kwargs.get('first_time', '')
1163
        if first_time:
1164
            first_time_minute = first_time['minute']
1165
            first_time_hour = first_time['hour']
1166
            first_time_day_of_month = first_time['day_of_month']
1167
            first_time_month = first_time['month']
1168
            first_time_year = first_time['year']
1169
1170
            _xmlftime = cmd.add_element('first_time')
1171
            _xmlftime.add_element('minute', str(first_time_minute))
1172
            _xmlftime.add_element('hour', str(first_time_hour))
1173
            _xmlftime.add_element('day_of_month', str(first_time_day_of_month))
1174
            _xmlftime.add_element('month', str(first_time_month))
1175
            _xmlftime.add_element('year', str(first_time_year))
1176
1177
        duration = kwargs.get('duration', '')
1178
        if len(duration) > 1:
1179
            _xmlduration = cmd.add_element('duration', str(duration[0]))
1180
            _xmlduration.add_element('unit', str(duration[1]))
1181
1182
        period = kwargs.get('period', '')
1183
        if len(period) > 1:
1184
            _xmlperiod = cmd.add_element('period', str(period[0]))
1185
            _xmlperiod.add_element('unit', str(period[1]))
1186
1187
        timezone = kwargs.get('timezone', '')
1188
        if timezone:
1189
            cmd.add_element('timezone', str(timezone))
1190
1191
        return cmd.to_string()
1192
1193
    def modify_setting_command(self, setting_id, name, value):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1194
        """Generates xml string for modify setting format on gvmd."""
1195
        cmd = XmlCommand('modify_setting')
1196
        cmd.set_attribute('setting_id', setting_id)
1197
        cmd.add_element('name', name)
1198
        cmd.add_element('value', value)
1199
1200
        return cmd.to_string()
1201
1202
    def modify_tag_command(self, tag_id, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1203
        """Generates xml string for modify tag on gvmd."""
1204
        if not tag_id:
1205
            raise ValueError('modify_tag requires a tag_id element')
1206
1207
        cmd = XmlCommand('modify_tag')
1208
        cmd.set_attribute('tag_id', str(tag_id))
1209
1210
        comment = kwargs.get('comment', '')
1211
        if comment:
1212
            cmd.add_element('comment', comment)
1213
1214
        name = kwargs.get('name', '')
1215
        if name:
1216
            cmd.add_element('name', name)
1217
1218
        value = kwargs.get('value', '')
1219
        if value:
1220
            cmd.add_element('value', value)
1221
1222
        active = kwargs.get('active', '')
1223
        if active:
1224
            cmd.add_element('active', value)
1225
1226
        resource = kwargs.get('resource', '')
1227
        if resource:
1228
            resource_id = resource['id']
1229
            resource_type = resource['type']
1230
            _xmlresource = cmd.add_element('resource',
1231
                                           attrs={'resource_id': resource_id})
1232
            _xmlresource.add_element('type', resource_type)
1233
1234
        return cmd.to_string()
1235
1236
    def modify_target_command(self, target_id, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1237
        """Generates xml string for modify target on gvmd."""
1238
        if not target_id:
1239
            raise ValueError('modify_target requires a target_id element')
1240
1241
        cmd = XmlCommand('modify_target')
1242
        cmd.set_attribute('target_id', target_id)
1243
1244
        comment = kwargs.get('comment', '')
1245
        if comment:
1246
            cmd.add_element('comment', comment)
1247
1248
        name = kwargs.get('name', '')
1249
        if name:
1250
            cmd.add_element('name', name)
1251
1252
        hosts = kwargs.get('hosts', '')
1253
        if hosts:
1254
            cmd.add_element('hosts', hosts)
1255
1256
        copy = kwargs.get('copy', '')
1257
        if copy:
1258
            cmd.add_element('copy', copy)
1259
1260
        exclude_hosts = kwargs.get('exclude_hosts', '')
1261
        if exclude_hosts:
1262
            cmd.add_element('exclude_hosts', exclude_hosts)
1263
1264
        alive_tests = kwargs.get('alive_tests', '')
1265
        if alive_tests:
1266
            cmd.add_element('alive_tests', alive_tests)
1267
1268
        reverse_lookup_only = kwargs.get('reverse_lookup_only', '')
1269
        if reverse_lookup_only:
1270
            cmd.add_element('reverse_lookup_only', reverse_lookup_only)
1271
1272
        reverse_lookup_unify = kwargs.get('reverse_lookup_unify', '')
1273
        if reverse_lookup_unify:
1274
            cmd.add_element('reverse_lookup_unify', reverse_lookup_unify)
1275
1276
        port_range = kwargs.get('port_range', '')
1277
        if port_range:
1278
            cmd.add_element('port_range', port_range)
1279
1280
        port_list = kwargs.get('port_list', '')
1281
        if port_list:
1282
            cmd.add_element('port_list', attrs={'id': str(port_list)})
1283
1284
        return cmd.to_string()
1285
1286
    def modify_task_command(self, task_id, kwargs):
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (22/15).
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1287
        """Generates xml string for modify task on gvmd."""
1288
        if not task_id:
1289
            raise ValueError('modify_task requires a task_id element')
1290
1291
        cmd = XmlCommand('modify_task')
1292
        cmd.set_attribute('task_id', task_id)
1293
1294
        name = kwargs.get('name', '')
1295
        if name:
1296
            cmd.add_element('name', name)
1297
1298
        comment = kwargs.get('comment', '')
1299
        if comment:
1300
            cmd.add_element('comment', comment)
1301
1302
        target_id = kwargs.get('target_id', '')
1303
        if target_id:
1304
            cmd.add_element('target', attrs={'id': target_id})
1305
1306
        scanner = kwargs.get('scanner', '')
1307
        if scanner:
1308
            cmd.add_element('scanner', attrs={'id': scanner})
1309
1310
        schedule_periods = kwargs.get('schedule_periods', '')
1311
        if schedule_periods:
1312
            cmd.add_element('schedule_periods', str(schedule_periods))
1313
1314
        schedule = kwargs.get('schedule', '')
1315
        if schedule:
1316
            cmd.add_element('schedule', attrs={'id': str(schedule)})
1317
1318
        alert = kwargs.get('alert', '')
1319
        if alert:
1320
            cmd.add_element('alert', attrs={'id': str(alert)})
1321
1322
        observers = kwargs.get('observers', '')
1323
        if observers:
1324
            cmd.add_element('observers', str(observers))
1325
1326
        preferences = kwargs.get('preferences', '')
1327
        if preferences:
1328
            _xmlprefs = cmd.add_element('preferences')
1329
            for n in range(len(preferences["scanner_name"])):
0 ignored issues
show
Coding Style Naming introduced by
Variable name "n" doesn't conform to '[a-z_][a-z0-9_]+$' pattern ('[a-z_][a-z0-9_]+$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1330
                preferences_scanner_name = preferences["scanner_name"][n]
1331
                preferences_value = preferences["value"][n]
1332
                _xmlpref = _xmlprefs.add_element('preference')
1333
                _xmlpref.add_element('scanner_name', preferences_scanner_name)
1334
                _xmlpref.add_element('value', preferences_value)
1335
1336
        file = kwargs.get('file', '')
1337
        if file:
1338
            file_name = file['name']
1339
            file_action = file['action']
1340
            if file_action != "update" and file_action != "remove":
0 ignored issues
show
Unused Code introduced by
Consider merging these comparisons with "in" to "file_action not in ('update', 'remove')"
Loading history...
1341
                raise ValueError('action can only be "update" or "remove"!')
1342
            cmd.add_element('file', attrs={'name': file_name,
1343
                                           'action': file_action})
1344
1345
        return cmd.to_string()
1346
1347
    def modify_user_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1348
        """Generates xml string for modify user on gvmd."""
1349
        user_id = kwargs.get('user_id', '')
1350
        name = kwargs.get('name', '')
1351
1352
        if not user_id and not name:
1353
            raise ValueError('modify_user requires '
1354
                             'either a user_id or a name element')
1355
1356
        cmd = XmlCommand('modify_user')
1357
        cmd.set_attribute('user_id', str(user_id))
1358
1359
        new_name = kwargs.get('new_name', '')
1360
        if new_name:
1361
            cmd.add_element('new_name', new_name)
1362
1363
        password = kwargs.get('password', '')
1364
        if password:
1365
            cmd.add_element('password', password)
1366
1367
        role_ids = kwargs.get('role_ids', '')
1368
        if len(role_ids) > 0:
1369
            for role in role_ids:
1370
                cmd.add_element('role', attrs={'id': str(role)})
1371
1372
        hosts = kwargs.get('hosts', '')
1373
        hosts_allow = kwargs.get('hosts_allow', '')
1374
        if hosts or hosts_allow:
1375
            cmd.add_element('hosts', hosts, attrs={'allow': str(hosts_allow)})
1376
1377
        ifaces = kwargs.get('ifaces', '')
1378
        ifaces_allow = kwargs.get('ifaces_allow', '')
1379
        if ifaces or ifaces_allow:
1380
            cmd.add_element('ifaces', ifaces,
1381
                            attrs={'allow': str(ifaces_allow)})
1382
1383
        sources = kwargs.get('sources', '')
1384
        if sources:
1385
            cmd.add_element('sources', sources)
1386
1387
        return cmd.to_string()
1388
1389
    def delete_agent_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1390
        """Generates xml string for delete agent on gvmd"""
1391
        cmd = XmlCommand('delete_agent')
1392
        for key, value in kwargs.items():
1393
            cmd.set_attribute(key, value)
1394
1395
        return cmd.to_string()
1396
1397
    def delete_alert_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1398
        """Generates xml string for delete alert on gvmd"""
1399
        cmd = XmlCommand('delete_alert')
1400
        for key, value in kwargs.items():
1401
            cmd.set_attribute(key, value)
1402
1403
        return cmd.to_string()
1404
1405
    def delete_asset_command(self, asset_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1406
        """Generates xml string for delete asset on gvmd"""
1407
        cmd = XmlCommand('delete_asset')
1408
        cmd.set_attribute('asset_id', asset_id)
1409
        cmd.set_attribute('ultimate', ultimate)
1410
1411
        return cmd.to_string()
1412
1413
    def delete_config_command(self, config_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1414
        """Generates xml string for delete config on gvmd"""
1415
        cmd = XmlCommand('delete_config')
1416
        cmd.set_attribute('config_id', config_id)
1417
        cmd.set_attribute('ultimate', ultimate)
1418
1419
        return cmd.to_string()
1420
1421
    def delete_credential_command(self, credential_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1422
        """Generates xml string for delete credential on gvmd"""
1423
        cmd = XmlCommand('delete_credential')
1424
        cmd.set_attribute('credential_id', credential_id)
1425
        cmd.set_attribute('ultimate', ultimate)
1426
        return cmd.to_string()
1427
1428
    def delete_filter_command(self, filter_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1429
        """Generates xml string for delete filter on gvmd"""
1430
        cmd = XmlCommand('delete_filter')
1431
        cmd.set_attribute('filter_id', filter_id)
1432
        cmd.set_attribute('ultimate', ultimate)
1433
1434
        return cmd.to_string()
1435
1436
    def delete_group_command(self, group_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1437
        """Generates xml string for delete group on gvmd"""
1438
        cmd = XmlCommand('delete_group')
1439
        cmd.set_attribute('group_id', group_id)
1440
        cmd.set_attribute('ultimate', ultimate)
1441
1442
        return cmd.to_string()
1443
1444
    def delete_note_command(self, note_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1445
        """Generates xml string for delete note on gvmd"""
1446
        cmd = XmlCommand('delete_note')
1447
        cmd.set_attribute('note_id', note_id)
1448
        cmd.set_attribute('ultimate', ultimate)
1449
1450
        return cmd.to_string()
1451
1452
    def delete_override_command(self, override_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1453
        """Generates xml string for delete override on gvmd"""
1454
        cmd = XmlCommand('delete_override')
1455
        cmd.set_attribute('override_id', override_id)
1456
        cmd.set_attribute('ultimate', ultimate)
1457
1458
        return cmd.to_string()
1459
1460
    def delete_permission_command(self, permission_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1461
        """Generates xml string for delete permission on gvmd"""
1462
        cmd = XmlCommand('delete_permission')
1463
        cmd.set_attribute('permission_id', permission_id)
1464
        cmd.set_attribute('ultimate', ultimate)
1465
1466
        return cmd.to_string()
1467
1468
    def delete_port_list_command(self, port_list_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1469
        """Generates xml string for delete port on gvmd"""
1470
        cmd = XmlCommand('delete_port_list')
1471
        cmd.set_attribute('port_list_id', port_list_id)
1472
        cmd.set_attribute('ultimate', ultimate)
1473
1474
        return cmd.to_string()
1475
1476
    def delete_port_range_command(self, port_range_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1477
        """Generates xml string for delete port on gvmd"""
1478
        cmd = XmlCommand('delete_port_range')
1479
        cmd.set_attribute('port_range_id', port_range_id)
1480
1481
        return cmd.to_string()
1482
1483
    def delete_report_command(self, report_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1484
        """Generates xml string for delete report on gvmd"""
1485
        cmd = XmlCommand('delete_report')
1486
        cmd.set_attribute('report_id', report_id)
1487
1488
        return cmd.to_string()
1489
1490
    def delete_report_format_command(self, report_format_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1491
        """Generates xml string for delete report on gvmd"""
1492
        cmd = XmlCommand('delete_report_format')
1493
        cmd.set_attribute('report_format_id', report_format_id)
1494
        cmd.set_attribute('ultimate', ultimate)
1495
1496
        return cmd.to_string()
1497
1498
    def delete_role_command(self, role_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1499
        """Generates xml string for delete role on gvmd"""
1500
        cmd = XmlCommand('delete_role')
1501
        cmd.set_attribute('role_id', role_id)
1502
        cmd.set_attribute('ultimate', ultimate)
1503
1504
        return cmd.to_string()
1505
1506
    def delete_scanner_command(self, scanner_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1507
        """Generates xml string for delete scanner on gvmd"""
1508
        cmd = XmlCommand('delete_scanner')
1509
        cmd.set_attribute('scanner_id', scanner_id)
1510
        cmd.set_attribute('ultimate', ultimate)
1511
1512
        return cmd.to_string()
1513
1514
    def delete_schedule_command(self, schedule_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1515
        """Generates xml string for delete schedule on gvmd"""
1516
        # if self.ask_yes_or_no('Are you sure to delete this schedule? '):
1517
        cmd = XmlCommand('delete_schedule')
1518
        cmd.set_attribute('schedule_id', schedule_id)
1519
        cmd.set_attribute('ultimate', ultimate)
1520
1521
        return cmd.to_string()
1522
1523
    def delete_tag_command(self, tag_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1524
        """Generates xml string for delete tag on gvmd"""
1525
        cmd = XmlCommand('delete_tag')
1526
        cmd.set_attribute('tag_id', tag_id)
1527
        cmd.set_attribute('ultimate', ultimate)
1528
1529
        return cmd.to_string()
1530
1531
    def delete_target_command(self, target_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1532
        """Generates xml string for delete target on gvmd"""
1533
        cmd = XmlCommand('delete_target')
1534
        cmd.set_attribute('target_id', target_id)
1535
        cmd.set_attribute('ultimate', ultimate)
1536
1537
        return cmd.to_string()
1538
1539
    def delete_task_command(self, task_id, ultimate=0):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1540
        """Generates xml string for delete task on gvmd"""
1541
        cmd = XmlCommand('delete_task')
1542
        cmd.set_attribute('task_id', task_id)
1543
        cmd.set_attribute('ultimate', ultimate)
1544
1545
        return cmd.to_string()
1546
1547
    def delete_user_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1548
        """Generates xml string for delete user on gvmd"""
1549
        cmd = XmlCommand('delete_user')
1550
1551
        user_id = kwargs.get('user_id', '')
1552
        if user_id:
1553
            cmd.set_attribute('user_id', user_id)
1554
1555
        name = kwargs.get('name', '')
1556
        if name:
1557
            cmd.set_attribute('name', name)
1558
1559
        inheritor_id = kwargs.get('inheritor_id', '')
1560
        if inheritor_id:
1561
            cmd.set_attribute('inheritor_id', inheritor_id)
1562
1563
        inheritor_name = kwargs.get('inheritor_name', '')
1564
        if inheritor_name:
1565
            cmd.set_attribute('inheritor_name', inheritor_name)
1566
1567
        return cmd.to_string()
1568
1569
    def describe_auth_command(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1570
        """Generates xml string for describe auth on gvmd"""
1571
        cmd = XmlCommand('describe_auth')
1572
        return cmd.to_string()
1573
1574
    def empty_trashcan_command(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1575
        """Generates xml string for empty trashcan on gvmd"""
1576
        cmd = XmlCommand('empty_trashcan')
1577
        return cmd.to_string()
1578
1579
    def get_agents_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1580
        """Generates xml string for get agents on gvmd."""
1581
        cmd = XmlCommand('get_agents')
1582
        cmd.set_attributes(kwargs)
1583
        return cmd.to_string()
1584
1585
    def get_aggregates_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1586
        """Generates xml string for get aggregates on gvmd."""
1587
        cmd = XmlCommand('get_aggregates')
1588
        cmd.set_attributes(kwargs)
1589
        return cmd.to_string()
1590
1591
    def get_alerts_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1592
        """Generates xml string for get alerts on gvmd."""
1593
        cmd = XmlCommand('get_alerts')
1594
        cmd.set_attributes(kwargs)
1595
        return cmd.to_string()
1596
1597
    def get_assets_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1598
        """Generates xml string for get assets on gvmd."""
1599
        cmd = XmlCommand('get_assets')
1600
        cmd.set_attributes(kwargs)
1601
        return cmd.to_string()
1602
1603
    def get_credentials_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1604
        """Generates xml string for get credentials on gvmd."""
1605
        cmd = XmlCommand('get_credentials')
1606
        cmd.set_attributes(kwargs)
1607
        return cmd.to_string()
1608
1609
    def get_configs_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1610
        """Generates xml string for get configs on gvmd."""
1611
        cmd = XmlCommand('get_configs')
1612
        cmd.set_attributes(kwargs)
1613
        return cmd.to_string()
1614
1615
    def get_feeds_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1616
        """Generates xml string for get feeds on gvmd."""
1617
        cmd = XmlCommand('get_feeds')
1618
        cmd.set_attributes(kwargs)
1619
        return cmd.to_string()
1620
1621
    def get_filters_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1622
        """Generates xml string for get filters on gvmd."""
1623
        cmd = XmlCommand('get_filters')
1624
        cmd.set_attributes(kwargs)
1625
        return cmd.to_string()
1626
1627
    def get_groups_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1628
        """Generates xml string for get groups on gvmd."""
1629
        cmd = XmlCommand('get_groups')
1630
        cmd.set_attributes(kwargs)
1631
        return cmd.to_string()
1632
1633
    def get_info_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1634
        """Generates xml string for get info on gvmd."""
1635
        cmd = XmlCommand('get_info')
1636
        cmd.set_attributes(kwargs)
1637
        return cmd.to_string()
1638
1639
    def get_notes_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1640
        """Generates xml string for get notes on gvmd."""
1641
        cmd = XmlCommand('get_notes')
1642
        cmd.set_attributes(kwargs)
1643
        return cmd.to_string()
1644
1645
    def get_nvts_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1646
        """Generates xml string for get nvts on gvmd."""
1647
        cmd = XmlCommand('get_nvts')
1648
        cmd.set_attributes(kwargs)
1649
        return cmd.to_string()
1650
1651
    def get_nvt_families_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1652
        """Generates xml string for get nvt on gvmd."""
1653
        cmd = XmlCommand('get_nvt_families')
1654
        cmd.set_attributes(kwargs)
1655
        return cmd.to_string()
1656
1657
    def get_overrides_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1658
        """Generates xml string for get overrides on gvmd."""
1659
        cmd = XmlCommand('get_overrides')
1660
        cmd.set_attributes(kwargs)
1661
        return cmd.to_string()
1662
1663
    def get_permissions_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1664
        """Generates xml string for get permissions on gvmd."""
1665
        cmd = XmlCommand('get_permissions')
1666
        cmd.set_attributes(kwargs)
1667
        return cmd.to_string()
1668
1669
    def get_port_lists_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1670
        """Generates xml string for get port on gvmd."""
1671
        cmd = XmlCommand('get_port_lists')
1672
        cmd.set_attributes(kwargs)
1673
        return cmd.to_string()
1674
1675
    def get_preferences_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1676
        """Generates xml string for get preferences on gvmd."""
1677
        cmd = XmlCommand('get_preferences')
1678
        cmd.set_attributes(kwargs)
1679
        return cmd.to_string()
1680
1681
    def get_reports_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1682
        """Generates xml string for get reports on gvmd."""
1683
        cmd = XmlCommand('get_reports')
1684
        cmd.set_attributes(kwargs)
1685
        return cmd.to_string()
1686
1687
    def get_report_formats_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1688
        """Generates xml string for get report on gvmd."""
1689
        cmd = XmlCommand('get_report_formats')
1690
        cmd.set_attributes(kwargs)
1691
        return cmd.to_string()
1692
1693
    def get_results_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1694
        """Generates xml string for get results on gvmd."""
1695
        cmd = XmlCommand('get_results')
1696
        cmd.set_attributes(kwargs)
1697
        return cmd.to_string()
1698
1699
    def get_roles_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1700
        """Generates xml string for get roles on gvmd."""
1701
        cmd = XmlCommand('get_roles')
1702
        cmd.set_attributes(kwargs)
1703
        return cmd.to_string()
1704
1705
    def get_scanners_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1706
        """Generates xml string for get scanners on gvmd."""
1707
        cmd = XmlCommand('get_scanners')
1708
        cmd.set_attributes(kwargs)
1709
        return cmd.to_string()
1710
1711
    def get_schedules_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1712
        """Generates xml string for get schedules on gvmd."""
1713
        cmd = XmlCommand('get_schedules')
1714
        cmd.set_attributes(kwargs)
1715
        return cmd.to_string()
1716
1717
    def get_settings_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1718
        """Generates xml string for get settings on gvmd."""
1719
        cmd = XmlCommand('get_settings')
1720
        cmd.set_attributes(kwargs)
1721
        return cmd.to_string()
1722
1723
    def get_system_reports_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1724
        """Generates xml string for get system on gvmd."""
1725
        cmd = XmlCommand('get_system')
1726
        cmd.set_attributes(kwargs)
1727
        return cmd.to_string()
1728
1729
    def get_tags_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1730
        """Generates xml string for get tags on gvmd."""
1731
        cmd = XmlCommand('get_tags')
1732
        cmd.set_attributes(kwargs)
1733
        return cmd.to_string()
1734
1735
    def get_targets_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1736
        """Generates xml string for get targets on gvmd."""
1737
        cmd = XmlCommand('get_targets')
1738
        cmd.set_attributes(kwargs)
1739
        return cmd.to_string()
1740
1741
    def get_tasks_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1742
        """Generates xml string for get tasks on gvmd."""
1743
        cmd = XmlCommand('get_tasks')
1744
        cmd.set_attributes(kwargs)
1745
        return cmd.to_string()
1746
1747
    def get_users_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1748
        """Generates xml string for get users on gvmd."""
1749
        cmd = XmlCommand('get_users')
1750
        cmd.set_attributes(kwargs)
1751
        return cmd.to_string()
1752
1753
    def get_version_command(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1754
        """Generates xml string for get version on gvmd."""
1755
        cmd = XmlCommand('get_version')
1756
        return cmd.to_string()
1757
1758
    def help_command(self, kwargs):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1759
        """Generates xml string for help on gvmd."""
1760
        cmd = XmlCommand('help')
1761
        cmd.set_attributes(kwargs)
1762
        return cmd.to_string()
1763
1764
    def move_task_command(self, task_id, slave_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1765
        """Generates xml string for move task on gvmd."""
1766
        cmd = XmlCommand('move_task')
1767
        cmd.set_attribute('task_id', task_id)
1768
        cmd.set_attribute('slave_id', slave_id)
1769
        return cmd.to_string()
1770
1771
    def restore_command(self, entity_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1772
        """Generates xml string for restore on gvmd."""
1773
        cmd = XmlCommand('restore')
1774
        cmd.set_attribute('id', entity_id)
1775
        return cmd.to_string()
1776
1777
    def resume_task_command(self, task_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1778
        """Generates xml string for resume task on gvmd."""
1779
        cmd = XmlCommand('resume_task')
1780
        cmd.set_attribute('task_id', task_id)
1781
        return cmd.to_string()
1782
1783
    def start_task_command(self, task_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1784
        """Generates xml string for start task on gvmd."""
1785
        cmd = XmlCommand('start_task')
1786
        cmd.set_attribute('task_id', task_id)
1787
        return cmd.to_string()
1788
1789
    def stop_task_command(self, task_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1790
        """Generates xml string for stop task on gvmd."""
1791
        cmd = XmlCommand('stop_task')
1792
        cmd.set_attribute('task_id', task_id)
1793
        return cmd.to_string()
1794
1795
    def sync_cert_command(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1796
        """Generates xml string for sync cert on gvmd."""
1797
        cmd = XmlCommand('sync_cert')
1798
        return cmd.to_string()
1799
1800
    def sync_config_command(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1801
        """Generates xml string for sync config on gvmd."""
1802
        cmd = XmlCommand('sync_config')
1803
        return cmd.to_string()
1804
1805
    def sync_feed_command(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1806
        """Generates xml string for sync feed on gvmd."""
1807
        cmd = XmlCommand('sync_feed')
1808
        return cmd.to_string()
1809
1810
    def sync_scap_command(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1811
        """Generates xml string for sync scap on gvmd."""
1812
        cmd = XmlCommand('sync_scap')
1813
        return cmd.to_string()
1814
1815
    def test_alert_command(self, alert_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1816
        """Generates xml string for test alert on gvmd."""
1817
        cmd = XmlCommand('test_alert')
1818
        cmd.set_attribute('alert_id', alert_id)
1819
        return cmd.to_string()
1820
1821
    def verify_agent_command(self, agent_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1822
        """Generates xml string for verify agent on gvmd."""
1823
        cmd = XmlCommand('verify_agent')
1824
        cmd.set_attribute('agent_id', agent_id)
1825
        return cmd.to_string()
1826
1827
    def verify_report_format_command(self, report_format_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1828
        """Generates xml string for verify report format on gvmd."""
1829
        cmd = XmlCommand('verify_report_format')
1830
        cmd.set_attribute('report_format_id', report_format_id)
1831
        return cmd.to_string()
1832
1833
    def verify_scanner_command(self, scanner_id):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
1834
        """Generates xml string for verify scanner on gvmd."""
1835
        cmd = XmlCommand('verify_scanner')
1836
        cmd.set_attribute('scanner_id', scanner_id)
1837
        return cmd.to_string()
1838
1839
1840
def pretty_print(xml):
1841
    """Prints beautiful XML-Code
1842
1843
    This function gets an object of list<lxml.etree._Element>
1844
    or directly a lxml element.
1845
    Print it with good readable format.
1846
1847
    Arguments:
1848
        xml: List<lxml.etree.Element> or directly a lxml element
1849
    """
1850
    if isinstance(xml, list):
1851
        for item in xml:
1852
            if etree.iselement(item):
1853
                print(etree.tostring(item, pretty_print=True).decode('utf-8'))
1854
            else:
1855
                print(item)
1856
    elif etree.iselement(xml):
1857
        print(etree.tostring(xml, pretty_print=True).decode('utf-8'))
1858