def create_volume(**attrs): """ Create a Volume. It will be owned by the calling user, or, if the caller is an admin, the user identified by the given email address. Required keyword arguments: email=str: The email of the user to own this Volume. name=str: The name of this volume. It must be unique. It is recommend that it be human-readable, so other users can request to join it. description=str: A human-readable description of the Volume's contents. blocksize=int The size of a block in this Volume. Each block will be cached as an HTTP object in the underlying Web caches, so it is probably best to pick block sizes between 4KB and 1MB or so. Optional keyword arguments: private=bool (default: True) If True, this volume will not be searchable, and users will not be able to request access to it. This value is True by default. archive=bool (default: False) If True, then there can be exactly one writer gateway for this volume. It will be read-only to every other Gateway. allow_anon=bool (default: false) If True, anonymous gateways can read this volume. Returns: On success, this method returns a Volume. On failure, it raises an exception. Authorization: An administrator can create an unlimited number of volumes. A user can only create as many as allowed by its max_volumes value. Remarks: In practice, Syndicate will generate two keyword arguments: 'volume_cert_b64' and 'cert_bundle_b64'. 'volume_cert_b64' is a serialized protobuf containing the above keywords, in an ms_pb2.ms_volume_metadata structure signed by the user that created the volume. 'cert_bundle_b64' is a serialized protobuf containing the new volume certificate bundle version vector, signed by the same user. """ return storage.create_volume(**attrs)
def createvolume(request): session = request.session username = session['login_email'] message = "" if request.method == "POST": # Validate input forms form = forms.CreateVolume(request.POST) if form.is_valid(): # attempt to create the volume # CREATE VOLUME kwargs = {} kwargs['name'] = form.cleaned_data['name'] kwargs['blocksize'] = int(form.cleaned_data['blocksize']) kwargs['description'] = form.cleaned_data['description'] kwargs['volume_secret'] = form.cleaned_data['password'] kwargs['private'] = form.cleaned_data['private'] try: volume_key = db.create_volume(username, **kwargs) volume = volume_key.get() except Exception, e: logging.exception(e) message = "Unable to create Volume '{}': {}".format( form.cleaned_data['name'], e.message) form = forms.CreateVolume() t = loader.get_template('createvolume.html') c = RequestContext(request, { 'username': username, 'form': form, 'message': message }) return HttpResponse(t.render(c)) now_sec, now_nsec = clock_gettime() rc = db.make_root(volume, volume.owner_id) session['new_change'] = "Your new volume is ready." session['next_url'] = '/syn/volume/myvolumes/' session['next_message'] = "Click here to see your volumes." return redirect('/syn/thanks/') else: # Prep returned form values (so they don't have to re-enter stuff) if 'name' in form.errors: oldname = "" else: oldname = request.POST['name'] if 'blocksize' in form.errors: oldblocksize = "" else: oldblocksize = request.POST['blocksize'] if 'description' in form.errors: olddescription = "" else: olddescription = request.POST['description'] # Prep error message message = "Invalid form entry: " for k, v in form.errors.items(): message = message + "\"" + k + "\"" + " -> " for m in v: message = message + m + " " # Give then the form again form = forms.CreateVolume( initial={ 'name': oldname, 'blocksize': oldblocksize, 'description': olddescription }) t = loader.get_template('createvolume.html') c = RequestContext(request, { 'username': username, 'form': form, 'message': message }) return HttpResponse(t.render(c))