Lines Matching full:role
8 create(hostname, role=None, note=None)
9 Create a server with given role, with status primary.
14 modify(hostname, role=None, status=None, note=None, delete=False,
16 Modify a server's role, status, note, or attribute:
17 1. Add role to a server. If the server is in primary status, proper actions
18 like service restart will be executed to enable the role.
19 2. Delete a role from a server. If the server is in primary status, proper
20 actions like service restart will be executed to disable the role.
23 or disable each role of the server.
42 def _add_role(server, role, action): argument
43 """Add a role to the server.
46 @param role: Role to be added to the server.
47 @param action: Execute actions after role or status is changed. Default to
50 @raise ServerActionError: If role is failed to be added.
52 server_models.validate(role=role)
53 if role in server.get_role_names():
55 'Server %s already has role %s.' % (server.hostname, role))
58 if not server_manager_utils.check_server(server.hostname, role):
60 'Server %s is not ready for role %s.' % (server.hostname, role))
62 if (role in server_models.ServerRole.ROLES_REQUIRE_UNIQUE_INSTANCE and
65 roles__role=role, status=server_models.Server.STATUS.PRIMARY)
68 'Role %s must be unique. Server %s already has role %s.' %
69 (role, servers[0].hostname, role))
71 server_models.ServerRole.objects.create(server=server, role=role)
73 # If needed, apply actions to enable the role for the server.
74 server_manager_actions.try_execute(server, [role], enable=True,
77 print 'Role %s is added to server %s.' % (role, server.hostname)
80 def _delete_role(server, role, action=False): argument
81 """Delete a role from the server.
84 @param role: Role to be deleted from the server.
85 @param action: Execute actions after role or status is changed. Default to
88 @raise ServerActionError: If role is failed to be deleted.
90 server_models.validate(role=role)
91 if role not in server.get_role_names():
93 'Server %s does not have role %s.' % (server.hostname, role))
96 server_manager_utils.warn_missing_role(role, server)
98 # Apply actions to disable the role for the server before the role is
100 server_manager_actions.try_execute(server, [role], enable=False,
103 print 'Deleting role %s from server %s...' % (role, server.hostname)
104 server.roles.get(role=role).delete()
106 # Apply actions to disable the role for the server after the role is
108 server_manager_actions.try_execute(server, [role], enable=False,
113 print ('Server %s has no role.')
115 print 'Role %s is deleted from server %s.' % (role, server.hostname)
123 @param action: Execute actions after role or status is changed. Default to
136 'Server %s has no role associated. Server must have a role to '
140 # the Autotest instance already has another server running an unique role.
142 # server with role scheduler should not be changed to status primary.
146 for role in unique_roles:
148 roles__role=role.role,
152 'Role %s must be unique. Server %s already has the '
153 'role.' % (role.role, servers[0].hostname))
156 # other value and the server is running a unique role across database, e.g.
159 for role in server.get_role_names():
160 server_manager_utils.warn_missing_role(role, server)
184 def create(hostname, role=None, note=None): argument
190 @param role: role of the new server, default to None.
195 server_models.validate(hostname=hostname, role=role)
199 server_models.ServerRole.objects.create(server=server, role=role)
220 for role in server.roles.all():
221 _delete_role(server, role.role)
228 def modify(hostname, role=None, status=None, delete=False, note=None, argument
233 @param role: Role to be added to the server.
235 @param delete: True to delete given role from the server, default to False.
239 @param action: Execute actions after role or status is changed. Default to
248 if role:
250 _add_role(server, role, action)
252 _delete_role(server, role, action)