Ejemplo n.º 1
0
def activate_subscribed_service(customer_email, customer_pgpinfo, customer_id, subscription_id,
                                plan_id, stdout, stderr, secretsfile, logfile,
                                configpath='../secret_config/lae_automation_config.json',
                                serverinfopath=None, clock=None):
    print >>stderr, "entering activate_subscribed_service call."
    print >>stderr, "configpath is %s" % configpath
    config = Config(configpath)
    myclock = clock or reactor

    s3_access_key_id = config.other["s3_access_key_id"]
    s3_secret_path = config.other["s3_secret_path"]
    s3_secretkey = FilePath(s3_secret_path).getContent().strip()

    bucketname = get_bucket_name(subscription_id, customer_id)
    location = None  # default S3 location for now

    print >>stderr, "plan_id is %s" % plan_id
    product = lookup_product(config, plan_id)
    fullname = product['plan_name']
    amiimageid = product['ami_image_id']
    instancesize = product['instance_size']

    print >>stdout, "Signing up customer for %s..." % (fullname,)

    d = create_stripe_user_bucket(s3_access_key_id, s3_secretkey, bucketname, stdout, stderr, location)

    print >>stdout, "After create_stripe_account_user_bucket %s..." % str(
        (s3_access_key_id, s3_secretkey, bucketname,
         None, amiimageid, instancesize,
         customer_email, customer_pgpinfo, stdout, stderr,
         secretsfile, config, serverinfopath, myclock))

    d.addCallback(lambda ign: deploy_server(s3_access_key_id, s3_secretkey, None, None, bucketname,
                                            None, amiimageid, instancesize,
                                            customer_email, customer_pgpinfo, stdout, stderr,
                                            secretsfile, config, serverinfopath, clock=myclock))

    d.addErrback(lambda f: send_notify_failure(f, customer_email, logfile, stdout, stderr))
    return d
import os, sys

from twisted.internet import reactor
from twisted.python.failure import Failure
from twisted.python.filepath import FilePath

from lae_automation.config import Config
from lae_automation.initialize import create_stripe_user_bucket

if len(sys.argv) != 2:
    print "Usage: python create_stripe_user_bucket.py BUCKETNAME"
    print "Happy bucket-creating!"
    sys.exit(1)

conf = Config()
useraccesskeyid = conf.other['ec2_access_key_id']
usersecretkey = FilePath(conf.other['ec2_secret_path']).getContent().rstrip()
bucketname = sys.argv[1]

def cb(x):
    print str(x)
    if isinstance(x, Failure) and hasattr(x.value, 'response'):
        print x.value.response

d = create_stripe_user_bucket(useraccesskeyid, usersecretkey, bucketname, sys.stdout, sys.stderr,
                              location='http://s3.amazonaws.com')
d.addBoth(cb)
d.addCallbacks(lambda ign: os._exit(0), lambda ign: os._exit(1))
reactor.run()