def resource_create(context, data_dict):
 model = context['model']
 user = context['user']
 package_id = _get_or_bust(data_dict, 'package_id')
 if (not data_dict.get('url')):
  data_dict['url'] = ''
 pkg_dict = _get_action('package_show')(dict(context, return_type='dict'), {'id': package_id})
 _check_access('resource_create', context, data_dict)
 for plugin in plugins.PluginImplementations(plugins.IResourceController):
  plugin.before_create(context, data_dict)
 if ('resources' not in pkg_dict):
  pkg_dict['resources'] = []
 upload = uploader.get_resource_uploader(data_dict)
 if ('mimetype' not in data_dict):
  if hasattr(upload, 'mimetype'):
   data_dict['mimetype'] = upload.mimetype
 if ('size' not in data_dict):
  if hasattr(upload, 'filesize'):
   data_dict['size'] = upload.filesize
 pkg_dict['resources'].append(data_dict)
 try:
  context['defer_commit'] = True
  context['use_cache'] = False
  _get_action('package_update')(context, pkg_dict)
  context.pop('defer_commit')
 except ValidationError as e:
  errors = e.error_dict['resources'][(-1)]
  raise ValidationError(errors)
 upload.upload(context['package'].resources[(-1)].id, uploader.get_max_resource_size())
 model.repo.commit()
 updated_pkg_dict = _get_action('package_show')(context, {'id': package_id})
 resource = updated_pkg_dict['resources'][(-1)]
 logic.get_action('resource_create_default_resource_views')({'model': context['model'], 'user': context['user'], 'ignore_auth': True}, {'resource': resource, 'package': updated_pkg_dict})
 for plugin in plugins.PluginImplementations(plugins.IResourceController):
  plugin.after_create(context, resource)
 return resource

def resource_create ( context , data_dict ) : model = context [ 'model' ] user = context [ 'user' ] package_id = _get_or_bust ( data_dict , 'package_id' ) if ( not data_dict . get ( 'url' ) ) : data_dict [ 'url' ] = '' pkg_dict = _get_action ( 'package_show' ) ( dict ( context , return_type = 'dict' ) , { 'id' : package_id } ) _check_access ( 'resource_create' , context , data_dict ) for plugin in plugins . PluginImplementations ( plugins . IResourceController ) : plugin . before_create ( context , data_dict ) if ( 'resources' not in pkg_dict ) : pkg_dict [ 'resources' ] = [ ] upload = uploader . get_resource_uploader ( data_dict ) if ( 'mimetype' not in data_dict ) : if hasattr ( upload , 'mimetype' ) : data_dict [ 'mimetype' ] = upload . mimetype if ( 'size' not in data_dict ) : if hasattr ( upload , 'filesize' ) : data_dict [ 'size' ] = upload . filesize pkg_dict [ 'resources' ] . append ( data_dict ) try : context [ 'defer_commit' ] = True context [ 'use_cache' ] = False _get_action ( 'package_update' ) ( context , pkg_dict ) context . pop ( 'defer_commit' ) except ValidationError as e : errors = e . error_dict [ 'resources' ] [ ( - 1 ) ] raise ValidationError ( errors ) upload . upload ( context [ 'package' ] . resources [ ( - 1 ) ] . id , uploader . get_max_resource_size ( ) ) model . repo . commit ( ) updated_pkg_dict = _get_action ( 'package_show' ) ( context , { 'id' : package_id } ) resource = updated_pkg_dict [ 'resources' ] [ ( - 1 ) ] logic . get_action ( 'resource_create_default_resource_views' ) ( { 'model' : context [ 'model' ] , 'user' : context [ 'user' ] , 'ignore_auth' : True } , { 'resource' : resource , 'package' : updated_pkg_dict } ) for plugin in plugins . PluginImplementations ( plugins . IResourceController ) : plugin . after_create ( context , resource ) return resource
create a resource via pcs command resource_id name for the resource resource_type resource type resource_options additional options for creating the resource cibfile use cibfile instead of the live cib for manipulation cli example: .