1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
# SPDX-FileCopyrightText: 2024 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
from typing import Optional
from gvm.errors import RequiredArgument
from gvm.protocols.core import Request
from gvm.utils import to_bool
from gvm.xml import XmlCommand
from .._entity_id import EntityID
class OperatingSystems:
@classmethod
def delete_operating_system(
cls,
operating_system_id: EntityID,
) -> Request:
"""Deletes an existing operating system
Args:
operating_system_id: UUID of the single operating_system to delete.
"""
if not operating_system_id:
raise RequiredArgument(
function=cls.delete_operating_system.__name__,
argument="operating_system_id",
)
cmd = XmlCommand("delete_asset")
cmd.set_attribute("asset_id", str(operating_system_id))
return cmd
@staticmethod
def get_operating_systems(
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
details: Optional[bool] = None,
) -> Request:
"""Request a list of operating systems
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
details: Whether to include additional information (e.g. tags)
"""
cmd = XmlCommand("get_assets")
cmd.set_attribute("type", "os")
cmd.add_filter(filter_string, filter_id)
if details is not None:
cmd.set_attribute("details", to_bool(details))
return cmd
@classmethod
def get_operating_system(
cls, operating_system_id: EntityID, *, details: Optional[bool] = None
) -> Request:
"""Request a single operating system
Args:
operating_system_id: UUID of an existing operating_system
details: Whether to include additional information (e.g. tags)
"""
cmd = XmlCommand("get_assets")
if not operating_system_id:
raise RequiredArgument(
function=cls.get_operating_system.__name__,
argument="operating_system_id",
)
cmd.set_attribute("asset_id", str(operating_system_id))
cmd.set_attribute("type", "os")
if details is not None:
cmd.set_attribute("details", to_bool(details))
return cmd
@classmethod
def modify_operating_system(
cls, operating_system_id: EntityID, *, comment: Optional[str] = None
) -> Request:
"""Modifies an existing operating system.
Args:
operating_system_id: UUID of the operating_system to be modified.
comment: Comment for the operating_system. Not passing a comment
arguments clears the comment for this operating system.
"""
if not operating_system_id:
raise RequiredArgument(
function=cls.modify_operating_system.__name__,
argument="operating_system_id",
)
cmd = XmlCommand("modify_asset")
cmd.set_attribute("asset_id", str(operating_system_id))
if not comment:
comment = ""
cmd.add_element("comment", comment)
return cmd
|