Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions engine/conf/tornado.conf.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Welcome to JuliaBox. We hope you will like it and also share with your friends.
"juliabox.plugins.sendmail_ses",
"juliabox.plugins.api_admin",
"juliabox.plugins.user_admin",
"juliabox.plugins.bucket_gs",
""
],

Expand Down
5 changes: 3 additions & 2 deletions engine/src/juliabox/cloud/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class JBPluginCloud(LoggerMixin):
""" Interfaces with cloud service providers or provides similar services locally.

- `JBPluginCloud.JBP_BUCKETSTORE`, `JBPluginCloud.JBP_BUCKETSTORE_S3`:
- `JBPluginCloud.JBP_BUCKETSTORE`, `JBPluginCloud.JBP_BUCKETSTORE_S3`, `JBPluginCloud.JBP_BUCKETSTORE_GS`:
Provides storage for blobs of data in named buckets. Similar to Amazon S3 or OpenStack Swift.
- `push(bucket, local_file, metadata=None)`
- `pull(bucket, local_file, metadata_only=False)`
Expand Down Expand Up @@ -52,6 +52,7 @@ class JBPluginCloud(LoggerMixin):

JBP_BUCKETSTORE = "cloud.bucketstore"
JBP_BUCKETSTORE_S3 = "cloud.bucketstore.s3"
JBP_BUCKETSTORE_GS = "cloud.bucketstore.gs"

JBP_DNS = "cloud.dns"
JBP_DNS_ROUTE53 = "cloud.dns.route53"
Expand Down Expand Up @@ -171,4 +172,4 @@ def deregister_instance_dns():
plugin = JBPluginCloud.jbox_get_plugin(JBPluginCloud.JBP_DNS)
if plugin is None:
return
plugin.delete_cname(Compute.get_alias_hostname())
plugin.delete_cname(Compute.get_alias_hostname())
3 changes: 3 additions & 0 deletions engine/src/juliabox/plugins/bucket_gs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__author__ = 'Nishanth'

from impl_gs import JBoxGS
71 changes: 71 additions & 0 deletions engine/src/juliabox/plugins/bucket_gs/impl_gs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
__author__ = 'Nishanth'

import os
import boto
from boto.gs.key import Key
import gcs_oauth2_boto_plugin
from juliabox.cloud import JBPluginCloud

class JBoxGS(JBPluginCloud):
provides = [JBPluginCloud.JBP_BUCKETSTORE, JBPluginCloud.JBP_BUCKETSTORE_GS]
CONN = None
BUCKETS = dict()

@staticmethod
def connect():
if JBoxGS.CONN is None:
JBoxGS.CONN = boto.connect_gs()
return JBoxGS.CONN

@staticmethod
def connect_bucket(bucket):
if bucket not in JBoxGS.BUCKETS:
JBoxGS.BUCKETS[bucket] = JBoxGS.connect().get_bucket(bucket)
return JBoxGS.BUCKETS[bucket]

@staticmethod
def push(bucket, local_file, metadata=None):
key_name = os.path.basename(local_file)
k = Key(JBoxGS.connect_bucket(bucket))
k.key = key_name
if metadata is not None:
for meta_name, meta_value in metadata.iteritems():
k.set_metadata(meta_name, meta_value)
k.set_contents_from_filename(local_file)
return k

@staticmethod
def pull(bucket, local_file, metadata_only=False):
key_name = os.path.basename(local_file)
k = JBoxGS.connect_bucket(bucket).get_key(key_name)
if (k is not None) and (not metadata_only):
k.get_contents_to_filename(local_file)
return k

@staticmethod
def delete(bucket, local_file):
key_name = os.path.basename(local_file)
k = JBoxGS.connect_bucket(bucket).delete_key(key_name)
return k

@staticmethod
def copy(from_file, to_file, from_bucket, to_bucket=None):
if to_bucket is None:
to_bucket = from_bucket

from_key_name = os.path.basename(from_file)
to_key_name = os.path.basename(to_file)

k = JBoxGS.connect_bucket(from_bucket).get_key(from_key_name)
if k is None:
return None
k_new = k.copy(to_bucket, to_key_name)
return k_new

@staticmethod
def move(from_file, to_file, from_bucket, to_bucket=None):
k_new = JBoxGS.copy(from_file, to_file, from_bucket, to_bucket)
if k_new is None:
return None
JBoxGS.delete(from_bucket, from_file)
return k_new