コード例 #1
0
def main(stdin, flapp_stdout, flapp_stderr):
    append_record(flapp_stdout, "Automation script started.")
    parameters_json = stdin.read()
    (customer_email,
     customer_pgpinfo,
     customer_id,
     plan_id,
     subscription_id) = simplejson.loads(parameters_json)

    (abslogdir_fp,
    stripesecrets_log_fp,
    SSEC2secrets_log_fp,
    signup_log_fp) = create_log_filepaths(plan_id, customer_id, subscription_id)

    append_record(flapp_stdout, "Writing logs to %r." % (abslogdir_fp.path,))

    stripesecrets_log_fp.setContent(parameters_json)

    SSEC2_secretsfile = SSEC2secrets_log_fp.open('a+')
    signup_logfile = signup_log_fp.open('a+')
    signup_stdout = LoggingStream(signup_logfile, '>')
    signup_stderr = LoggingStream(signup_logfile, '')
    sys.stdout = signup_stderr

    def errhandler(err):
        fh = flapp_stderr.open('a+')
        fh.write(repr(err))
        fh.close()
        return err

    d = defer.succeed(None)
    d.addCallback(lambda ign: activate_subscribed_service(customer_email, customer_pgpinfo,
                                                          customer_id, subscription_id,
                                                          plan_id,
                                                          signup_stdout, signup_stderr,
                                                          SSEC2_secretsfile, signup_log_fp.path)
                  )
    d.addErrback(errhandler)
    d.addBoth(lambda ign: signup_logfile.close())
コード例 #2
0
    if len(sys.argv) < 5:
        print "Usage: python replace_server.py STRIPE_SECRETS_PATH SSEC2_SECRETS_PATH AMI_IMAGE_ID INSTANCE_SIZE CUSTOMER_EMAIL"
        print "Happy replacement!"
        sys.exit(1)

    # Secrets necessary for correct logging
    stripe_secrets_path = sys.argv[1]
    stripe_secrets = simplejson.loads(FilePath(stripe_secrets_path).getContent())
    stripe_plan_id = stripe_secrets[3]
    stripe_customer_id = stripe_secrets[2]
    stripe_subscription_id = stripe_secrets[4]

    (abslogdir_fp,
    stripesecrets_log_fp,
    SSEC2secrets_log_fp,
    signup_log_fp) = create_log_filepaths(stripe_plan_id, stripe_customer_id, stripe_subscription_id)

    # The stripe secrets are unchanged.
    stripesecrets_log_fp.setContent(simplejson.dumps(stripe_secrets))

    SSEC2_secretsfile = SSEC2secrets_log_fp.open('a+')
    signup_logfile = signup_log_fp.open('a+')
    signup_stdout = LoggingStream(signup_logfile, '>')
    signup_stderr = LoggingStream(signup_logfile, '')
    # This is to work around the fact that fabric echoes all commands and output to sys.stdout.
    # It does have a way to disable that, but not (easily) to redirect it.
    sys.stdout = signup_stderr

    # Secrets necessary to provision SSEC2
    old_ssec2_secrets_path = sys.argv[2]
    old_ssec2_secrets = simplejson.loads(FilePath(old_ssec2_secrets_path).getContent())