"Fossies" - the Fresh Open Source Software Archive

Member "solum-12.0.0/solum/api/handlers/infrastructure_handler.py" (30 Mar 2022, 2762 Bytes) of package /linux/misc/openstack/solum-12.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "infrastructure_handler.py" see the Fossies "Dox" file reference documentation.

    1 # Copyright 2014 - Numergy
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
    4 # not use this file except in compliance with the License. You may obtain
    5 # a copy of the License at
    6 #
    7 #      http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 # Unless required by applicable law or agreed to in writing, software
   10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   12 # License for the specific language governing permissions and limitations
   13 # under the License.
   14 
   15 from oslo_utils import uuidutils
   16 
   17 from solum.api.handlers import handler
   18 from solum.common import catalog
   19 from solum.common import clients
   20 from solum import objects
   21 
   22 
   23 class InfrastructureStackHandler(handler.Handler):
   24     """Fulfills a request on the infrastructure stack resource."""
   25 
   26     def get(self, id):
   27         """Return a stack."""
   28         return objects.registry.InfrastructureStack.get_by_uuid(
   29             self.context, id)
   30 
   31     def update(self, id, data):
   32         """Modify a stack."""
   33         updated = objects.registry.InfrastructureStack.update_and_save(
   34             self.context, id, data)
   35         return updated
   36 
   37     def delete(self, id):
   38         """Delete a stack."""
   39         db_obj = objects.registry.InfrastructureStack.get_by_uuid(
   40             self.context, id)
   41         db_obj.destroy(self.context)
   42 
   43     def create(self, data):
   44         """Create a new stack.
   45 
   46         Create a new infrastructure stack by using Heat. Note that a zaqar
   47         queue is created and will be consumed by solum-infra-guestagent.
   48         """
   49         db_obj = objects.registry.InfrastructureStack()
   50         db_obj.update(data)
   51         db_obj.uuid = uuidutils.generate_uuid()
   52         db_obj.user_id = self.context.user
   53         db_obj.project_id = self.context.tenant
   54 
   55         self._create_zaqar_queue(db_obj.uuid)
   56         db_obj.heat_stack_id = self._deploy_infra(data.get('image_id'))
   57 
   58         db_obj.create(self.context)
   59         return db_obj
   60 
   61     def _create_zaqar_queue(self, queue_name):
   62         osc = clients.OpenStackClients(self.context)
   63         osc.zaqar().queue(queue_name)
   64 
   65     def _deploy_infra(self, image_id):
   66         osc = clients.OpenStackClients(self.context)
   67 
   68         parameters = {'image': image_id}
   69 
   70         template = catalog.get('templates', 'infra')
   71 
   72         created_stack = osc.heat().stacks.create(stack_name='infra',
   73                                                  template=template,
   74                                                  parameters=parameters)
   75         return created_stack['stack']['id']
   76 
   77     def get_all(self):
   78         """Return all stacks, based on the query provided."""
   79         return objects.registry.InfrastructureStackList.get_all(self.context)