Skip to content
This repository has been archived by the owner on Jul 15, 2020. It is now read-only.

Latest commit

 

History

History
115 lines (83 loc) · 3.33 KB

README.textile

File metadata and controls

115 lines (83 loc) · 3.33 KB

Rails Swift Cloud Storage Usage Demo

A simple rails application demonstrating the access of Swift File Storage from within an instance running on a cloud foundry installation.

Introduction

When using cloud foundry services(mysql, postgresql, swift, …), user credentials are provided as environment variables to the application instances.
These credentials are stored within VCAP_SERVICES. An application can parse these credentials to access the desired services.
This application demonstrates the usage scenario of accessing a Swift File Storage with the credentials provided by the cf_swift_service.

Code Walkthrough

  • SwiftController (app/controllers/swift_controller.rb)
    • test_swift: performs the test defined in the SwiftTest class (see below)
    • read_environment: prints out the environment variables visible to the application
  • Swift::Storage (lib/swift/storage.rb)
    • wrapper around the fog gem API
    • create/delete directories on a swift instance
    • upload/download/delete files from/to a swift instance
    • create temporary urls
    • set directories to private/public
  • Swift::SwiftTest
    • performs the actual test (perform_test)
    • generates a hash containing test outputs
    • the test consists of 2 steps:
      • create public and private test directories (create_private_test_directory, create_public_test_directory)
      • upload one example file to each directory (upload_example_file_1, upload_example_file_2)

Anynines deployment
For installing the test application you have to bind a mysql and a swift service instance to the application.

$> cf push
Name> swift

Instances> 1

1: 64M
2: 128M
3: 256M
4: 512M
5: 1G
Memory Limit> 2

Creating swift… OK

1: swift
2: none
Subdomain> swift

1: de.a9sapp.eu
2: none
Domain> de.a9sapp.eu

Binding swift.de.a9sapp.eu to swift… OK

Create services for application?> y

1: mongodb 2.0
2: mysql 5.5
3: postgresql 9.0
4: rabbitmq 2.8
5: redis 2.2
6: swift 1.0
What kind?> 6

Name?> swift-15f97

1: free: free plan
Which plan?> 1

Creating service swift-15f97… OK
Binding swift-15f97 to swift… OK
Create another service?> y

1: mongodb 2.0
2: mysql 5.5
3: postgresql 9.0
4: rabbitmq 2.8
5: redis 2.2
6: swift 1.0
What kind?> 2

Name?> mysql-f1300

1: 100: Shared server, shared VM, 1MB memory, 10MB storage, 10 connections
Which plan?> 1

Creating service mysql-f1300… OK
Binding mysql-f1300 to swift… OK
Create another service?> n

Bind other services to application?> n

Save configuration?> n

Uploading swift… OK
…..
1/1 instances: 1 running
OK

Local execution

At first you have to create a tenant with the according rights on your Swift Installation.
To be able to execute the application from outside a cloud foundry installation, you have to specify the VCAP_SERVICES environment variable at startup (exchange the dummies with your credentials):

VCAP_SERVICES=‘{"swift-1.0":[{"name":“swift-50e83”,“label”:“swift-1.0”,“plan”:“free”,“credentials”:{"name":“name”,“authentication_uri”:“https://auth.example.com:5000/v2.0/”,“user_name”:“user_name”,“user_id”:“user_id”,“password”:“password”,“tenant_name”:“tenant_name”,“tenant_id”:“tenant_id”,“availability_zone”:“nova”,“authentication_version”:"v2"}}]}’ rails s

Test the example application
Show the environment variables controller:
/swift/read_environment

Execute the Swift storage tests and show the outputs:
/swift/test_swift