Esempio n. 1
0
    def delete_computehost(self, host_id):
        host = db_api.host_get(host_id)
        if not host:
            raise manager_ex.HostNotFound(host=host_id)

        with trusts.create_ctx_from_trust(host['trust_id']):
            # TODO(sbauza):
            #  - Check if no leases having this host scheduled
            inventory = nova_inventory.NovaInventory()
            servers = inventory.get_servers_per_host(
                host['hypervisor_hostname'])
            if servers:
                raise manager_ex.HostHavingServers(
                    host=host['hypervisor_hostname'], servers=servers)

            try:
                pool = rp.ReservationPool()
                pool.remove_computehost(self.freepool_name,
                                        host['service_name'])
                # NOTE(sbauza): Extracapabilities will be destroyed thanks to
                #  the DB FK.
                db_api.host_destroy(host_id)
            except db_ex.ClimateDBException:
                # Nothing so bad, but we need to advert the admin
                # he has to rerun
                raise manager_ex.CantRemoveHost(host=host_id,
                                                pool=self.freepool_name)
Esempio n. 2
0
    def delete_computehost(self, host_id):
        host = db_api.host_get(host_id)
        if not host:
            raise manager_ex.HostNotFound(host=host_id)

        with trusts.create_ctx_from_trust(host['trust_id']):
            # TODO(sbauza):
            #  - Check if no leases having this host scheduled
            inventory = nova_inventory.NovaInventory()
            servers = inventory.get_servers_per_host(
                host['hypervisor_hostname'])
            if servers:
                raise manager_ex.HostHavingServers(
                    host=host['hypervisor_hostname'], servers=servers)

            try:
                pool = rp.ReservationPool()
                pool.remove_computehost(self.freepool_name,
                                        host['service_name'])
                # NOTE(sbauza): Extracapabilities will be destroyed thanks to
                #  the DB FK.
                db_api.host_destroy(host_id)
            except db_ex.ClimateDBException:
                # Nothing so bad, but we need to advert the admin
                # he has to rerun
                raise manager_ex.CantRemoveHost(host=host_id,
                                                pool=self.freepool_name)
Esempio n. 3
0
 def get_computehost(self, host_id):
     host = db_api.host_get(host_id)
     extra_capabilities = self._get_extra_capabilities(host_id)
     if host is not None and extra_capabilities:
         res = host.copy()
         res.update(extra_capabilities)
         return res
     else:
         return host
Esempio n. 4
0
 def get_computehost(self, host_id):
     host = db_api.host_get(host_id)
     extra_capabilities = self._get_extra_capabilities(host_id)
     if host is not None and extra_capabilities:
         res = host.copy()
         res.update(extra_capabilities)
         return res
     else:
         return host
Esempio n. 5
0
 def on_start(self, resource_id):
     """Add the hosts in the pool."""
     reservations = db_api.reservation_get_all_by_values(
         resource_id=resource_id)
     for reservation in reservations:
         pool = rp.ReservationPool()
         for allocation in db_api.host_allocation_get_all_by_values(
                 reservation_id=reservation['id']):
             host = db_api.host_get(allocation['compute_host_id'])
             pool.add_computehost(reservation['resource_id'],
                                  host['service_name'])
Esempio n. 6
0
 def on_start(self, resource_id):
     """Add the hosts in the pool."""
     reservations = db_api.reservation_get_all_by_values(
         resource_id=resource_id)
     for reservation in reservations:
         pool = rp.ReservationPool()
         for allocation in db_api.host_allocation_get_all_by_values(
                 reservation_id=reservation['id']):
             host = db_api.host_get(allocation['compute_host_id'])
             pool.add_computehost(reservation['resource_id'],
                                  host['service_name'])
Esempio n. 7
0
 def delete_computehost(self, host_id):
     # TODO(sbauza):
     #  - Check if no leases having this host scheduled
     servers = self.inventory.get_servers_per_host(host_id)
     if servers:
         raise manager_exceptions.HostHavingServers(host=host_id,
                                                    servers=servers)
     host = db_api.host_get(host_id)
     if not host:
         raise manager_exceptions.HostNotFound(host=host_id)
     try:
         self.pool.remove_computehost(self.freepool_name,
                                      host['hypervisor_hostname'])
         # NOTE(sbauza): Extracapabilities will be destroyed thanks to
         #  the DB FK.
         db_api.host_destroy(host_id)
     except RuntimeError:
         # Nothing so bad, but we need to advert the admin he has to rerun
         raise manager_exceptions.CantRemoveHost(host=host_id,
                                                 pool=self.freepool_name)
Esempio n. 8
0
 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'])
Esempio n. 9
0
 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'])