Debian Codegraph @

ansible_collections/theforeman/foreman/plugins/modules/bookmark.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # (c) 2019 Bernhard Hopfenmüller (ATIX AG)
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 from __future__ import absolute_import, division, print_function
19 __metaclass__ = type
20
21
22 DOCUMENTATION = '''
23 ---
24 module: bookmark
25 version_added: 1.0.0
26 short_description: Manage Bookmarks
27 description:
28 - "Manage Bookmark Entities"
29 author:
30 - "Bernhard Hopfenmueller (@Fobhep) ATIX AG"
31 - "Christoffer Reijer (@ephracis) Basalt AB"
32 options:
33 name:
34 description:
35 - Name of the bookmark
36 required: true
37 type: str
38 controller:
39 description:
40 - Controller for the bookmark
41 required: true
42 type: str
43 public:
44 description:
45 - Make bookmark available for all users
46 required: false
47 default: true
48 type: bool
49 query:
50 description:
51 - Query of the bookmark
52 type: str
53 extends_documentation_fragment:
54 - theforeman.foreman.foreman
55 - theforeman.foreman.foreman.entity_state_with_defaults
56 '''
57
58 EXAMPLES = '''
59 - name: "Create a Bookmark"
60 theforeman.foreman.bookmark:
61 username: "admin"
62 password: "changeme"
63 server_url: "https://foreman.example.com"
64 name: "recent"
65 controller: "job_invocations"
66 query: "started_at > '24 hours ago'"
67 state: present_with_defaults
68
69 - name: "Update a Bookmark"
70 theforeman.foreman.bookmark:
71 username: "admin"
72 password: "changeme"
73 server_url: "https://foreman.example.com"
74 name: "recent"
75 controller: "job_invocations"
76 query: "started_at > '12 hours ago'"
77 state: present
78
79 - name: "Delete a Bookmark"
80 theforeman.foreman.bookmark:
81 username: "admin"
82 password: "changeme"
83 server_url: "https://foreman.example.com"
84 name: "recent"
85 controller: "job_invocations"
86 state: absent
87 '''
88
89 RETURN = '''
90 entity:
91 description: Final state of the affected entities grouped by their type.
92 returned: success
93 type: dict
94 contains:
95 bookmarks:
96 description: List of bookmarks.
97 type: list
98 elements: dict
99 contains:
100 id:
101 description: Database id of the bookmark.
102 type: int
103 name:
104 description: Name of the bookmark.
105 type: str
106 controller:
107 description: Controller, the query is performed on.
108 type: str
109 query:
110 description: Query to be performed on the controller.
111 type: str
112 public:
113 description: Publicity of the bookmark.
114 type: bool
115 owner_type:
116 description: Class of the owner entity.
117 type: str
118 owner_id:
119 description: Database id of the owner entity.
120 type: int
121 '''
122
123 from ansible_collections.theforeman.foreman.plugins.module_utils.foreman_helper import ForemanEntityAnsibleModule
124
125
126 class ForemanBookmarkModule(ForemanEntityAnsibleModule):
127 pass
128
129
130 def main():
131 module = ForemanBookmarkModule(
132 foreman_spec=dict(
133 name=dict(required=True),
134 controller=dict(required=True),
135 public=dict(default='true', type='bool'),
136 query=dict(),
137 ),
138 argument_spec=dict(
139 state=dict(default='present', choices=['present_with_defaults', 'present', 'absent']),
140 ),
141 required_if=[
142 ['state', 'present', ['query']],
143 ['state', 'present_with_defaults', ['query']],
144 ],
145 )
146
147 with module.api_connection():
148 module.set_entity('entity', module.find_resource(
149 'bookmarks',
150 search='name="{0}",controller="{1}"'.format(module.foreman_params['name'], module.foreman_params['controller']),
151 failsafe=True,
152 ))
153 module.run()
154
155
156 if __name__ == '__main__':
157 main()