original_docstring: Adds a new datastore version.
docstring: Adds a new datastore version.
docstring_tokens: Adds a new datastore version .
code: def create(self, req, body, tenant_id):
          """Adds a new datastore version."""
          context = req.environ[wsgi.CONTEXT_KEY]
          datastore_name = body['version']['datastore_name']
          version_name = body['version']['name']
          manager = body['version']['datastore_manager']
          image_id = body['version']['image']
          packages = body['version']['packages']
          if type(packages) is list:
              packages = ','.join(packages)
          active = body['version']['active']
          default = body['version']['default']
  
          LOG.info(_("Tenant: '%(tenant)s' is adding the datastore "
                     "version: '%(version)s' to datastore: '%(datastore)s'") %
                   {'tenant': tenant_id, 'version': version_name,
                    'datastore': datastore_name})
  
          client = remote.create_nova_client(context)
          try:
              client.images.get(image_id)
          except nova_exceptions.NotFound:
              raise exception.ImageNotFound(uuid=image_id)
  
          try:
              datastore = models.Datastore.load(datastore_name)
          except exception.DatastoreNotFound:
              # Create the datastore if datastore_name does not exists.
              LOG.info(_("Creating datastore %s") % datastore_name)
              datastore = models.DBDatastore()
              datastore.id = utils.generate_uuid()
              datastore.name = datastore_name
              datastore.save()
  
          try:
              models.DatastoreVersion.load(datastore, version_name)
              raise exception.DatastoreVersionAlreadyExists(name=version_name)
          except exception.DatastoreVersionNotFound:
              models.update_datastore_version(datastore.name, version_name,
                                              manager, image_id, packages,
                                              active)
  
          if default:
              models.update_datastore(datastore.name, version_name)
  
          return wsgi.Result(None, 202)
code_tokens: def create ( self , req , body , tenant_id ) : context = req . environ [ wsgi . CONTEXT_KEY ] datastore_name = body [ 'version' ] [ 'datastore_name' ] version_name = body [ 'version' ] [ 'name' ] manager = body [ 'version' ] [ 'datastore_manager' ] image_id = body [ 'version' ] [ 'image' ] packages = body [ 'version' ] [ 'packages' ] if type ( packages ) is list : packages = ',' . join ( packages ) active = body [ 'version' ] [ 'active' ] default = body [ 'version' ] [ 'default' ] LOG . info ( _ ( "Tenant: '%(tenant)s' is adding the datastore " "version: '%(version)s' to datastore: '%(datastore)s'" ) % { 'tenant' : tenant_id , 'version' : version_name , 'datastore' : datastore_name } ) client = remote . create_nova_client ( context ) try : client . images . get ( image_id ) except nova_exceptions . NotFound : raise exception . ImageNotFound ( uuid = image_id ) try : datastore = models . Datastore . load ( datastore_name ) except exception . DatastoreNotFound : LOG . info ( _ ( "Creating datastore %s" ) % datastore_name ) datastore = models . DBDatastore ( ) datastore . id = utils . generate_uuid ( ) datastore . name = datastore_name datastore . save ( ) try : models . DatastoreVersion . load ( datastore , version_name ) raise exception . DatastoreVersionAlreadyExists ( name = version_name ) except exception . DatastoreVersionNotFound : models . update_datastore_version ( datastore . name , version_name , manager , image_id , packages , active ) if default : models . update_datastore ( datastore . name , version_name ) return wsgi . Result ( None , 202 )
short_docstring: Adds a new datastore version.
short_docstring_tokens: Adds a new datastore version .
comment: """Adds a new datastore version."""$SEP$# Create the datastore if datastore_name does not exists.