def create_reservation(self, values): """Create reservation.""" pool = rp.ReservationPool() pool_name = str(uuid.uuid4()) pool_instance = pool.create(name=pool_name) reservation_values = { 'id': pool_name, 'lease_id': values['lease_id'], 'resource_id': pool_instance.id, 'resource_type': values['resource_type'], 'status': 'pending', } reservation = db_api.reservation_create(reservation_values) count_range = str(values['min']) + '-' + str(values['max']) host_values = { 'reservation_id': reservation['id'], 'resource_properties': values['resource_properties'], 'hypervisor_properties': values['hypervisor_properties'], 'count_range': count_range, 'status': 'pending', } db_api.host_reservation_create(host_values) host_ids = self._matching_hosts( values['hypervisor_properties'], values['resource_properties'], count_range, values['start_date'], values['end_date'], ) if not host_ids: raise manager_ex.NotEnoughHostsAvailable() for host_id in host_ids: db_api.host_allocation_create({'compute_host_id': host_id, 'reservation_id': reservation['id']})
def create_reservation(self, values): """Create reservation.""" pool = rp.ReservationPool() pool_name = str(uuid.uuid4()) pool_instance = pool.create(name=pool_name) reservation_values = { 'id': pool_name, 'lease_id': values['lease_id'], 'resource_id': pool_instance.id, 'resource_type': values['resource_type'], 'status': 'pending', } reservation = db_api.reservation_create(reservation_values) min_host = values['min'] max_host = values['max'] if not min_host: raise manager_ex.MissingParameter(param="min") if not max_host: raise manager_ex.MissingParameter(param="max") try: min_host = int(str(min_host)) except ValueError: raise manager_ex.MalformedParameter(param="min") try: max_host = int(str(max_host)) except ValueError: raise manager_ex.MalformedParameter(param="max") count_range = str(values['min']) + '-' + str(values['max']) host_values = { 'reservation_id': reservation['id'], 'resource_properties': values['resource_properties'], 'hypervisor_properties': values['hypervisor_properties'], 'count_range': count_range, 'status': 'pending', } db_api.host_reservation_create(host_values) host_ids = self._matching_hosts( values['hypervisor_properties'], values['resource_properties'], count_range, values['start_date'], values['end_date'], ) if not host_ids: pool.delete(pool_name) raise manager_ex.NotEnoughHostsAvailable() for host_id in host_ids: db_api.host_allocation_create({'compute_host_id': host_id, 'reservation_id': reservation['id']})
def create_reservation(self, values): """Create reservation.""" pool = rp.ReservationPool() pool_name = str(uuid.uuid4()) pool_instance = pool.create(name=pool_name) reservation_values = { 'id': pool_name, 'lease_id': values['lease_id'], 'resource_id': pool_instance.id, 'resource_type': values['resource_type'], 'status': 'pending', } reservation = db_api.reservation_create(reservation_values) count_range = str(values['min']) + '-' + str(values['max']) host_values = { 'reservation_id': reservation['id'], 'resource_properties': values['resource_properties'], 'hypervisor_properties': values['hypervisor_properties'], 'count_range': count_range, 'status': 'pending', } db_api.host_reservation_create(host_values) host_ids = self._matching_hosts( values['hypervisor_properties'], values['resource_properties'], count_range, values['start_date'], values['end_date'], ) if not host_ids: raise manager_ex.NotEnoughHostsAvailable() for host_id in host_ids: db_api.host_allocation_create({ 'compute_host_id': host_id, 'reservation_id': reservation['id'] })
def update_reservation(self, reservation_id, values): """Update reservation.""" reservation = db_api.reservation_get(reservation_id) lease = db_api.lease_get(reservation['lease_id']) pool = rp.ReservationPool() hosts_in_pool = pool.get_computehosts( reservation['resource_id']) if (values['start_date'] < lease['start_date'] or values['end_date'] > lease['end_date']): allocations = [] for allocation in db_api.host_allocation_get_all_by_values( reservation_id=reservation_id): full_periods = db_utils.get_full_periods( allocation['compute_host_id'], values['start_date'], values['end_date'], datetime.timedelta(seconds=1)) if lease['start_date'] < values['start_date']: max_start = values['start_date'] else: max_start = lease['start_date'] if lease['end_date'] < values['end_date']: min_end = lease['end_date'] else: min_end = values['end_date'] if not (len(full_periods) == 0 or (len(full_periods) == 1 and full_periods[0][0] == max_start and full_periods[0][1] == min_end)): allocations.append(allocation) if (hosts_in_pool and self.nova.hypervisors.get( self._get_hypervisor_from_name_or_id( allocation['compute_host_id']) ).__dict__['running_vms'] > 0): raise manager_ex.NotEnoughHostsAvailable() if allocations: host_reservation = ( db_api.host_reservation_get_by_reservation_id( reservation_id)) host_ids = self._matching_hosts( host_reservation['hypervisor_properties'], host_reservation['resource_properties'], str(len(allocations)) + '-' + str(len(allocations)), values['start_date'], values['end_date']) if not host_ids: raise manager_ex.NotEnoughHostsAvailable() if hosts_in_pool: old_hosts = [allocation['compute_host_id'] for allocation in allocations] pool.remove_computehost(reservation['resource_id'], old_hosts) for allocation in allocations: db_api.host_allocation_destroy(allocation['id']) for host_id in host_ids: db_api.host_allocation_create( {'compute_host_id': host_id, 'reservation_id': reservation_id}) if hosts_in_pool: host = db_api.host_get(host_id) pool.add_computehost(reservation['resource_id'], host['service_name'])