def migrate_backends(self): """ Migrate the backends of the backend service one by one without deleting or recreating the backend service Args: backend_service_configs: the configs of the backend service """ if 'backends' not in self.backend_service.backend_service_configs: return None backends = self.backend_service.backend_service_configs['backends'] for i in range(len(backends)): backend = backends[i] migration_helper = SelfLinkExecutor( self.compute, backend['group'], self.network, self.subnetwork, self.preserve_instance_external_ip) backend_migration_handler = migration_helper.build_instance_group_migration_handler( ) # The backend type is not an instance group, then just ignore if backend_migration_handler == None: continue self.backend_migration_handlers.append(backend_migration_handler) print('Detaching: %s' % (backend['group'])) self.backend_service.detach_a_backend(backend['group']) print('Migrating: %s' % (backend['group'])) backend_migration_handler.network_migration() print('Reattaching: %s' % (backend['group'])) self.backend_service.reattach_all_backends() # wait for the first backend becoming healthy, # then continue migrate other backends if i == 0 and len(backends) > 1: self.backend_service.wait_for_backend_become_healthy( backend['group'])
def build_instance_group_migration_handlers(self): """ Use instance group's selfLinks to create a list of InstanceGroupMigrationHandler Returns: """ for selfLink in self.target_pool.attached_managed_instance_groups_selfLinks: executor = SelfLinkExecutor(self.compute, selfLink, self.network, self.subnetwork, self.preserve_instance_external_ip) try: instance_group_migration_handler = executor.build_instance_group_migration_handler( ) if instance_group_migration_handler != None: self.instance_group_migration_handlers.append( instance_group_migration_handler) except HttpError as e: if 'not found' in e._get_reason(): continue else: raise e