コード例 #1
0
 def find_reference(self, instance_name, driver_files, deployment_location):
     openstack_location = None
     try:
         openstack_location = self.location_translator.from_deployment_location(
             deployment_location)
         inputs = {'instance_name': instance_name}
         template = self.__get_discover_template(driver_files)
         find_result = None
         try:
             discover_result = self.tosca_discovery_service.discover(
                 template, openstack_location, inputs)
             find_result = FindReferenceResult(
                 discover_result.discover_id,
                 outputs=discover_result.outputs)
         except NotDiscoveredError as e:
             pass  # Return empty result
         except ToscaValidationError as e:
             raise InvalidDriverFilesError(str(e)) from e
         return FindReferenceResponse(find_result)
     finally:
         if not self.resource_driver_config.keep_files:
             try:
                 logger.debug(
                     f'Attempting to remove driver files at {driver_files.root_path}'
                 )
                 driver_files.remove_all()
             except Exception as e:
                 logger.exception(
                     'Encountered an error whilst trying to clear out driver files directory {0}: {1}'
                     .format(driver_files.root_path, str(e)))
         if openstack_location != None:
             openstack_location.close()
コード例 #2
0
 def __get_heat_template_from_tosca(self, driver_files):
     if driver_files.has_file('tosca.yaml'):
         template_path = driver_files.get_file_path('tosca.yaml')
     elif driver_files.has_file('tosca.yml'):
         template_path = driver_files.get_file_path('tosca.yml')
     else:
         raise InvalidDriverFilesError(
             'Missing \'tosca.yaml\' or \'tosca.yml\' file')
     with open(template_path, 'r') as f:
         template = f.read()
     try:
         heat_template = self.heat_translator.generate_heat_template(
             template)
     except ToscaValidationError as e:
         raise InvalidDriverFilesError(str(e)) from e
     logger.debug('Translated Tosca template:\n%s\nto Heat template:\n%s',
                  template, heat_template)
     return heat_template
コード例 #3
0
 def __get_heat_template(self, driver_files):
     if driver_files.has_file('heat.yaml'):
         template_path = driver_files.get_file_path('heat.yaml')
     elif driver_files.has_file('heat.yml'):
         template_path = driver_files.get_file_path('heat.yml')
     else:
         raise InvalidDriverFilesError(
             'Missing \'heat.yaml\' or \'heat.yml\' file')
     with open(template_path, 'r') as f:
         heat_template = f.read()
     return heat_template
コード例 #4
0
 def __handle_create(self, driver_files, system_properties,
                     resource_properties, request_properties,
                     associated_topology, openstack_location):
     heat_driver = openstack_location.heat_driver
     stack_id = None
     if 'stack_id' in resource_properties:
         input_stack_id = resource_properties.get('stack_id')
         if input_stack_id != None and len(input_stack_id.strip(
         )) != 0 and input_stack_id.strip() != "0":
             try:
                 ##Check for valid stack
                 heat_driver.get_stack(input_stack_id.strip())
             except StackNotFoundError as e:
                 raise InfrastructureNotFoundError(str(e)) from e
             else:
                 stack_id = input_stack_id
     if stack_id is None:
         template_type = request_properties.get('template-type', None)
         if template_type is not None and template_type.upper(
         ) == TOSCA_TEMPLATE_TYPE.upper():
             heat_template = self.__get_heat_template_from_tosca(
                 driver_files)
         elif template_type is None or template_type.upper(
         ) == HEAT_TEMPLATE_TYPE.upper():
             heat_template = self.__get_heat_template(driver_files)
         else:
             raise InvalidDriverFilesError(
                 'Cannot create using template of type \'{0}\'. Must be one of: {1}'
                 .format(template_type,
                         [TOSCA_TEMPLATE_TYPE, HEAT_TEMPLATE_TYPE]))
         heat_input_util = openstack_location.get_heat_input_util()
         input_props = self.props_merger.merge(resource_properties,
                                               system_properties)
         heat_inputs = heat_input_util.filter_used_properties(
             heat_template, input_props)
         if 'resourceId' in system_properties and 'resourceName' in system_properties:
             stack_name = self.stack_name_creator.create(
                 system_properties['resourceId'],
                 system_properties['resourceName'])
         else:
             stack_name = 's' + str(uuid.uuid4())
         stack_id = heat_driver.create_stack(stack_name, heat_template,
                                             heat_inputs)
     request_id = self.__build_request_id(CREATE_REQUEST_PREFIX, stack_id)
     associated_topology = self.__build_associated_topology_response(
         stack_id)
     return LifecycleExecuteResponse(
         request_id, associated_topology=associated_topology)
コード例 #5
0
 def __handle_create(self, driver_files, system_properties,
                     resource_properties, request_properties,
                     associated_topology, openstack_location):
     heat_driver = openstack_location.heat_driver
     stack_id = None
     if 'stack_id' in resource_properties:
         input_stack_id = resource_properties.get('stack_id')
         if input_stack_id != None and len(input_stack_id.strip(
         )) != 0 and input_stack_id.strip() != "0":
             try:
                 ##Check for valid stack
                 heat_driver.get_stack(input_stack_id.strip())
             except StackNotFoundError as e:
                 raise InfrastructureNotFoundError(str(e)) from e
             else:
                 stack_id = input_stack_id
     if stack_id is None:
         kwargs = {}
         template_type = request_properties.get('template-type', None)
         if template_type == None:
             # Try and guess based on files
             # Heat to take precedence
             if driver_files.has_file('heat.yaml') or driver_files.has_file(
                     'heat.yml'):
                 template_type = HEAT_TEMPLATE_TYPE
             elif driver_files.has_file(
                     'tosca.yaml') or driver_files.has_file('tosca.yml'):
                 template_type = TOSCA_TEMPLATE_TYPE
             else:
                 # Default to Heat, there are no heat files but we'll let this fail later
                 template_type = HEAT_TEMPLATE_TYPE
         else:
             template_type = template_type.upper()
         if template_type == TOSCA_TEMPLATE_TYPE.upper():
             heat_template = self.__get_heat_template_from_tosca(
                 driver_files)
         elif template_type == HEAT_TEMPLATE_TYPE.upper():
             heat_template = self.__get_heat_template(driver_files)
             files = self.__gather_additional_heat_files(driver_files)
             if len(files) > 0:
                 kwargs['files'] = files
         else:
             raise InvalidDriverFilesError(
                 'Cannot create using template of type \'{0}\'. Must be one of: {1}'
                 .format(template_type,
                         [TOSCA_TEMPLATE_TYPE, HEAT_TEMPLATE_TYPE]))
         heat_input_util = openstack_location.get_heat_input_util()
         input_props = self.props_merger.merge(resource_properties,
                                               system_properties)
         heat_inputs = heat_input_util.filter_used_properties(
             heat_template, input_props)
         if 'resourceId' in system_properties and 'resourceName' in system_properties:
             stack_name = self.stack_name_creator.create(
                 system_properties['resourceId'],
                 system_properties['resourceName'])
         else:
             stack_name = 's' + str(uuid.uuid4())
         stack_id = heat_driver.create_stack(stack_name, heat_template,
                                             heat_inputs, **kwargs)
     request_id = self.__build_request_id(CREATE_REQUEST_PREFIX, stack_id)
     associated_topology = self.__build_associated_topology_response(
         stack_id)
     return LifecycleExecuteResponse(
         request_id, associated_topology=associated_topology)