2 # Copyright Google, Martin J. Bligh <mbligh@google.com>, Jan 2009
5 from autotest_lib
.server
import frontend
8 old
= frontend
.AFE(web_server
='http://' + sys
.argv
[1])
9 new
= frontend
.AFE(web_server
='http://' + sys
.argv
[2])
11 hostname
= sys
.argv
[3]
12 print 'Migrating %s ...' % hostname
14 old_host
= old
.get_hosts(hostname
=hostname
)[0]
17 print "Usage: atest_migrate_host <old_server> <new_server> <hostname>"
24 new_host
= new
.create_host(hostname
=hostname
, locked
=True)
27 old_host_labels
= old_host
.get_labels()
28 for label
in old_host_labels
:
29 # Create any non-existant labels
30 if not new
.get_labels(name
=label
.name
):
32 new_label
= new
.create_label(name
=label
.name
,
33 platform
=label
.platform
,
34 only_if_needed
=label
.only_if_needed
)
35 # Add any missing labels to the machine
36 if not [l
for l
in new_host
.get_labels() if l
.name
== label
.name
]:
37 new_host
.add_labels([label
.name
])
40 old_host_acls
= [a
for a
in old_host
.get_acls() if a
.name
!= 'Everyone']
41 new_users
= [user
.login
for user
in new
.get_users()]
43 for acl
in old_host_acls
:
44 # Create any non-existant ACLs
45 new_acls
= new
.get_acls(name
=acl
.name
)
49 new_acl
= new
.create_acl(name
=acl
.name
, description
=acl
.description
)
50 # Add any users to the ACL that we can
51 for user
in acl
.users
:
53 new_acl
.add_users([user
])
55 print 'Skipping absent user %s' % user
56 # Add any missing ACLs to the machine
57 if not [a
for a
in new_host
.get_acls() if a
.name
== acl
.name
]:
58 new_host
.add_acl(acl
.name
)
61 if not old_host
.locked
:
62 new_host
.modify(locked
=False)
64 # Delete host from old server