def __estimate_image_transfer_time(self, lease, bandwidth): config = get_config() force_transfer_time = config.get("force-imagetransfer-time") if force_transfer_time != None: return force_transfer_time else: return estimate_transfer_time(lease.software.image_size, bandwidth)
def estimate_migration_time(self, lease): migration = get_config().get("migration") if migration == constants.MIGRATE_YES: vmrr = lease.get_last_vmrr() images_in_pnode = dict([(pnode,0) for pnode in set(vmrr.nodes.values())]) for (vnode,pnode) in vmrr.nodes.items(): images_in_pnode[pnode] += lease.software.image_size max_to_transfer = max(images_in_pnode.values()) bandwidth = self.resourcepool.info.get_migration_bandwidth() return estimate_transfer_time(max_to_transfer, bandwidth) elif migration == constants.MIGRATE_YES_NOTRANSFER: return TimeDelta(seconds=0)
def estimate_migration_time(self, lease): migration = get_config().get("migration") if migration == constants.MIGRATE_YES: vmrr = lease.get_last_vmrr() images_in_pnode = dict([(pnode, 0) for pnode in set(vmrr.nodes.values())]) for (vnode, pnode) in vmrr.nodes.items(): images_in_pnode[pnode] += lease.software.image_size max_to_transfer = max(images_in_pnode.values()) bandwidth = self.resourcepool.info.get_migration_bandwidth() return estimate_transfer_time(max_to_transfer, bandwidth) elif migration == constants.MIGRATE_YES_NOTRANSFER: return TimeDelta(seconds=0)
def schedule_migration(self, lease, vmrr, nexttime): if type(lease.software) == UnmanagedSoftwareEnvironment: return [] # This code is the same as the one in vm_scheduler # Should be factored out last_vmrr = lease.get_last_vmrr() vnode_mappings = self.resourcepool.get_disk_image_mappings(lease) vnode_migrations = dict([(vnode, (vnode_mappings[vnode], vmrr.nodes[vnode])) for vnode in vmrr.nodes if vnode_mappings[vnode] != vmrr.nodes[vnode]]) mustmigrate = False for vnode in vnode_migrations: if vnode_migrations[vnode][0] != vnode_migrations[vnode][1]: mustmigrate = True break if not mustmigrate: return [] if get_config().get("migration") == constants.MIGRATE_YES_NOTRANSFER: start = nexttime end = nexttime res = {} migr_rr = DiskImageMigrationResourceReservation(lease, start, end, res, vmrr, vnode_migrations) migr_rr.state = ResourceReservation.STATE_SCHEDULED return [migr_rr] # Figure out what migrations can be done simultaneously migrations = [] while len(vnode_migrations) > 0: pnodes = set() migration = {} for vnode in vnode_migrations: origin = vnode_migrations[vnode][0] dest = vnode_migrations[vnode][1] if not origin in pnodes and not dest in pnodes: migration[vnode] = vnode_migrations[vnode] pnodes.add(origin) pnodes.add(dest) for vnode in migration: del vnode_migrations[vnode] migrations.append(migration) # Create migration RRs start = max(last_vmrr.post_rrs[-1].end, nexttime) bandwidth = self.resourcepool.info.get_migration_bandwidth() migr_rrs = [] for m in migrations: mb_per_physnode = {} for vnode, (pnode_from, pnode_to) in m.items(): mb_per_physnode[pnode_from] = mb_per_physnode.setdefault(pnode_from, 0) + lease.software.image_size max_mb_to_migrate = max(mb_per_physnode.values()) migr_time = estimate_transfer_time(max_mb_to_migrate, bandwidth) end = start + migr_time res = {} for (origin,dest) in m.values(): resorigin = Capacity([constants.RES_NETOUT]) resorigin.set_quantity(constants.RES_NETOUT, bandwidth) resdest = Capacity([constants.RES_NETIN]) resdest.set_quantity(constants.RES_NETIN, bandwidth) res[origin] = self.slottable.create_resource_tuple_from_capacity(resorigin) res[dest] = self.slottable.create_resource_tuple_from_capacity(resdest) migr_rr = DiskImageMigrationResourceReservation(lease, start, start + migr_time, res, vmrr, m) migr_rr.state = ResourceReservation.STATE_SCHEDULED migr_rrs.append(migr_rr) start = end return migr_rrs
def schedule_migration(self, lease, vmrr, nexttime): if type(lease.software) == UnmanagedSoftwareEnvironment: return [] # This code is the same as the one in vm_scheduler # Should be factored out last_vmrr = lease.get_last_vmrr() vnode_migrations = dict([(vnode, (last_vmrr.nodes[vnode], vmrr.nodes[vnode])) for vnode in vmrr.nodes]) mustmigrate = False for vnode in vnode_migrations: if vnode_migrations[vnode][0] != vnode_migrations[vnode][1]: mustmigrate = True break if not mustmigrate: return [] if get_config().get("migration") == constants.MIGRATE_YES_NOTRANSFER: start = nexttime end = nexttime res = {} migr_rr = DiskImageMigrationResourceReservation( lease, start, end, res, vmrr, vnode_migrations) migr_rr.state = ResourceReservation.STATE_SCHEDULED return [migr_rr] # Figure out what migrations can be done simultaneously migrations = [] while len(vnode_migrations) > 0: pnodes = set() migration = {} for vnode in vnode_migrations: origin = vnode_migrations[vnode][0] dest = vnode_migrations[vnode][1] if not origin in pnodes and not dest in pnodes: migration[vnode] = vnode_migrations[vnode] pnodes.add(origin) pnodes.add(dest) for vnode in migration: del vnode_migrations[vnode] migrations.append(migration) # Create migration RRs start = max(last_vmrr.post_rrs[-1].end, nexttime) bandwidth = self.resourcepool.info.get_migration_bandwidth() migr_rrs = [] for m in migrations: mb_to_migrate = lease.software.image_size * len(m.keys()) migr_time = estimate_transfer_time(mb_to_migrate, bandwidth) end = start + migr_time res = {} for (origin, dest) in m.values(): resorigin = Capacity([constants.RES_NETOUT]) resorigin.set_quantity(constants.RES_NETOUT, bandwidth) resdest = Capacity([constants.RES_NETIN]) resdest.set_quantity(constants.RES_NETIN, bandwidth) res[origin] = self.slottable.create_resource_tuple_from_capacity( resorigin) res[dest] = self.slottable.create_resource_tuple_from_capacity( resdest) migr_rr = DiskImageMigrationResourceReservation( lease, start, start + migr_time, res, vmrr, m) migr_rr.state = ResourceReservation.STATE_SCHEDULED migr_rrs.append(migr_rr) start = end return migr_rrs