@@ -90,13 +90,16 @@ def get_hypervisor_free_memory(self):
9090 xe host-compute-free-memory host=$h;done" )
9191
9292 # Get overview of VMs and their memory
93- def get_vms_with_memory_from_hypervisor (self ):
93+ def get_vms_with_memory_from_hypervisor (self , grep_for = None ):
9494 try :
95+ grep_command = ""
96+ if grep_for is not None :
97+ grep_command = "| grep %s" % grep_for
9598 return self .run_local_command ("xe vm-list resident-on=$(xe host-list params=uuid \
9699 name-label=$HOSTNAME --minimal) \
97100 params=name-label,memory-static-max is-control-domain=false |\
98101 tr '\\ n' ' ' | sed 's/name-label/\\ n/g' | \
99- awk {'print $4 \" ,\" $8'} | sed '/^,$/d'" )
102+ awk {'print $4 \" ,\" $8'} | sed '/^,$/d'" + grep_command )
100103 except :
101104 return False
102105
@@ -126,7 +129,7 @@ def get_hypervisor_with_most_free_memory(self):
126129 return sorted (self .poolmember .items (),key = lambda x :x [1 ]['memory_free' ],reverse = True )[:1 ][0 ][1 ]
127130
128131 # Generate migration plan
129- def generate_migration_plan (self ):
132+ def generate_migration_plan (self , grep_for = None ):
130133 # Make sure host is disabled
131134 if self .is_host_enabled () is not False :
132135 print "Error: Host should be disabled first."
@@ -140,7 +143,7 @@ def generate_migration_plan(self):
140143 # Generate migration plan
141144 migration_cmds = ""
142145 if self .vmlist == False :
143- self .vmlist = self .get_vms_with_memory_from_hypervisor ()
146+ self .vmlist = self .get_vms_with_memory_from_hypervisor (grep_for )
144147
145148 vmlist_iter = self .vmlist .split ('\n ' )
146149
@@ -170,9 +173,9 @@ def generate_migration_plan(self):
170173 return migration_cmds
171174
172175 # Execute migration plan
173- def execute_migration_plan (self ):
176+ def execute_migration_plan (self , grep_for = None ):
174177 try :
175- migration_cmds = self .generate_migration_plan ()
178+ migration_cmds = self .generate_migration_plan (grep_for )
176179 if migration_cmds == False :
177180 return False
178181 return self .run_local_command ("nohup echo \" " + migration_cmds + "\" | \
@@ -214,9 +217,18 @@ def pool_ha_check(self):
214217 print "Note: Running in DRY-run mode, not executing. Use --exec to execute."
215218 print "Note: Calculating migration plan.."
216219 print "Note: This is the migration plan:"
217- print x .generate_migration_plan ()
220+ print "Instances (threads = %s)" % str (x .threads )
221+ print x .generate_migration_plan ("i-" )
222+ x .threads = 1
223+ x .vmlist = False
224+ print "Routers (threads = %s)" % str (x .threads )
225+ print x .generate_migration_plan ("r-" )
218226 sys .exit (0 )
219227
228+ print "Note: Executing migration plan using " + str (x .threads ) + " threads.."
229+ print x .execute_migration_plan ("i-" )
230+ x .threads = 1
231+ x .vmlist = False
220232 print "Note: Executing migration plan using " + str (x .threads ) + " threads.."
221233 print x .execute_migration_plan ()
222234
0 commit comments