def subscribe(reactor, root_url, email):
    """
    Add a new subscription to the subscription manager.

    :param reactor: The reactor to use for I/O to the manager.

    :param bytes root_url: The root URL of the subscription manager API
        server.

    :param bytes email: An email address to associate with the subscription.

    :return Deferred: A deferred which fires after the subscription has been
        created.
    """
    identifier = sha256(bytes(reactor.seconds())).hexdigest()[:14]
    sid = u"sid_" + identifier
    cid = u"cus_" + identifier

    agent = Agent(reactor)
    client = network_client(root_url, agent)
    subscription = SubscriptionDetails(
        bucketname=get_bucket_name(sid, cid),
        oldsecrets={},
        product_id=u"filler",
        customer_email=email,
        customer_pgpinfo=None,
        customer_id=cid,
        subscription_id=sid,
        introducer_port_number=0,
        storage_port_number=0,
    )
    return client.create(sid, subscription)
 def signup(self, customer_email, customer_id, subscription_id, plan_id):
     details = SubscriptionDetails(
         bucketname=get_bucket_name(subscription_id, customer_id),
         oldsecrets=None,
         customer_email=customer_email,
         customer_pgpinfo="",
         product_id=plan_id,
         customer_id=customer_id,
         subscription_id=subscription_id,
         introducer_port_number=0,
         storage_port_number=0,
     )
     a = start_action(action_type=u"provisioning-signup")
     with a.context():
         d = DeferredContext(
             self.provision_subscription(
                 self.smclient,
                 details,
             ), )
         return d.addActionFinish()
    def create_pod(self, ip, storage_pem, storage_port, intro_pem, intro_port):
        """
        A new customer grid pod shows up, as would happen if a new user just
        signed up and got provisioned.
        """
        assume(storage_pem != intro_pem
               and Tub(storage_pem).getTubID() not in self.used_tubs
               and Tub(intro_pem).getTubID() not in self.used_tubs)
        details = SubscriptionDetails(
            bucketname=u"foo",
            # Set the node secrets.  From these, tub identifiers can be
            # derived.
            oldsecrets={
                # Storage server.
                u"server_node_pem": storage_pem,
                u"introducer_node_pem": intro_pem,
            },
            customer_email=u"foo",
            customer_pgpinfo=u"foo",
            product_id=u"foo",
            customer_id=u"foo",
            subscription_id=u"foo",
            stripe_subscription_id=u"foo",
            introducer_port_number=intro_port,
            storage_port_number=storage_port,
        )
        deployment = create_deployment(
            self.deploy_config,
            details,
            self.model,
        )
        self.deployments.append(deployment)
        pod = derive_pod(self.model, deployment, ip)
        self.case.successResultOf(self.client.create(pod))

        self.pods[pod] = (ip, storage_pem, storage_port, intro_pem, intro_port)
        self.used_tubs.update({
            Tub(storage_pem).getTubID(),
            Tub(intro_pem).getTubID(),
        })