Lines Matching full:server
6 """This module provides utility functions to help managing servers in server
25 from autotest_lib.frontend.server import models as server_models
30 """Exception raised when action on server failed.
40 'SERVER', 'use_server_db', default=False, type=bool)
44 """Post a warning if Autotest instance has no other primary server with
48 @param exclude_server: Server to be excluded from search for role.
50 servers = server_models.Server.objects.filter(
52 status=server_models.Server.STATUS.PRIMARY).exclude(
55 message = ('WARNING! There will be no server with role %s after it\'s '
56 'removed from server %s. Autotest will not function '
57 'normally without any server in role %s.' %
65 @param hostname: hostname of the server.
66 @param role: Role of server, default to None.
67 @param status: Status of server, default to None.
69 @return: A list of server objects with given role and status.
78 return list(server_models.Server.objects.filter(**filters))
94 @param servers: Sequence of Server instances.
97 return '\n'.join(str(server) for server in servers)
103 @param servers: Sequence of Server instances.
107 for server in servers:
108 if server.date_modified is None:
111 date_modified = str(server.date_modified)
112 attributes = {k: v for k, v in server.attributes.values_list(
114 server_dicts.append({'hostname': server.hostname,
115 'status': server.status,
116 'roles': server.get_role_names(),
117 'date_created': str(server.date_created),
119 'note': server.note,
127 @param servers: Sequence of Server instances.
134 """Confirm server with given hostname is ready to be primary of given role.
136 If the server is a backup and failed to be verified for the role, remove
140 @param hostname: hostname of the server.
142 @return: True if server can be verified for the given role, otherwise
145 # TODO(dshi): Add more logic to confirm server is ready for the role.
146 # For now, the function just checks if server is ssh-able.
151 print('Failed to check server %s, error: %s' %
157 """Decorator to check if server with given hostname exists in the database.
159 @param exist: Set to True to confirm server exists in the database, raise
161 server exists in database. Default is True.
163 @raise ServerActionError: If `exist` is True and server does not exist in
164 the database, or `exist` is False and server exists
173 """Decorator to check if server exists.
175 If exist is set to True, raise ServerActionError is server with
176 given hostname is not found in server database.
177 If exist is set to False, raise ServerActionError is server with
178 given hostname is found in server database.
186 server = server_models.Server.objects.get(hostname=hostname)
188 server = None
190 if not exist and server:
191 raise ServerActionError('Server %s already exists.' %
193 if exist and not server:
194 raise ServerActionError('Server %s does not exist in the '
196 if server:
197 kwargs['server'] = server
209 status=server_models.Server.STATUS.PRIMARY)
213 def delete_attribute(server, attribute): argument
216 @param server: An object of server_models.Server.
217 @param attribute: Name of an attribute of the server.
219 attributes = server.attributes.filter(attribute=attribute)
221 raise ServerActionError('Server %s does not have attribute %s' %
222 (server.hostname, attribute))
224 print('Attribute %s is deleted from server %s.' % (attribute,
225 server.hostname))
228 def change_attribute(server, attribute, value): argument
229 """Change the value of an attribute of the server.
231 @param server: An object of server_models.Server.
232 @param attribute: Name of an attribute of the server.
233 @param value: Value of the attribute of the server.
239 server=server, attribute=attribute)
241 raise ServerActionError('Attribute %s for Server %s already has '
243 (attribute, server.hostname, value))
248 print('Attribute `%s` of server %s is changed from %s to %s.' %
249 (attribute, server.hostname, old_value, value))
252 server=server, attribute=attribute, value=value)
253 print('Attribute `%s` of server %s is set to %s.' %
254 (attribute, server.hostname, value))
263 status=server_models.Server.STATUS.PRIMARY)
268 """Confirm a given server has the given role, and its status is primary.
270 @param hostname: hostname of the server.
279 servers = get_servers(role=role, status=server_models.Server.STATUS.PRIMARY)
280 for server in servers:
281 if hostname == utils.normalize_hostname(server.hostname):
283 raise ServerActionError('Server %s does not have role of %s running in '