Example #1
0
File: jobs.py Project: v1psta/atst
def do_create_environment(csp: CloudProviderInterface, environment_id=None):
    environment = Environments.get(environment_id)

    with claim_for_update(environment) as environment:

        if environment.cloud_id is not None:
            # TODO: Return value for this?
            return

        user = environment.creator

        # we'll need to do some checking in this job for cases where it's retrying
        # when a failure occured after some successful steps
        # (e.g. if environment.cloud_id is not None, then we can skip first step)

        # credentials either from a given user or pulled from config?
        # if using global creds, do we need to log what user authorized action?
        atat_root_creds = csp.root_creds()

        # user is needed because baseline root account in the environment will
        # be assigned to the requesting user, open question how to handle duplicate
        # email addresses across new environments
        csp_environment_id = csp.create_environment(atat_root_creds, user,
                                                    environment)
        environment.cloud_id = csp_environment_id
        db.session.add(environment)
        db.session.commit()

        body = render_email("emails/application/environment_ready.txt",
                            {"environment": environment})
        app.mailer.send([environment.creator.email],
                        translate("email.environment_ready"), body)
Example #2
0
File: jobs.py Project: v1psta/atst
def do_create_atat_admin_user(csp: CloudProviderInterface,
                              environment_id=None):
    environment = Environments.get(environment_id)

    with claim_for_update(environment) as environment:
        atat_root_creds = csp.root_creds()

        atat_remote_root_user = csp.create_atat_admin_user(
            atat_root_creds, environment.cloud_id)
        environment.root_user_info = atat_remote_root_user
        db.session.add(environment)
        db.session.commit()
Example #3
0
File: jobs.py Project: v1psta/atst
def do_provision_user(csp: CloudProviderInterface, environment_role_id=None):
    environment_role = EnvironmentRoles.get_by_id(environment_role_id)

    with claim_for_update(environment_role) as environment_role:
        credentials = environment_role.environment.csp_credentials

        csp_user_id = csp.create_or_update_user(credentials, environment_role,
                                                environment_role.role)
        environment_role.csp_user_id = csp_user_id
        environment_role.status = EnvironmentRole.Status.COMPLETED
        db.session.add(environment_role)
        db.session.commit()
Example #4
0
def do_create_environment_baseline(csp: CloudProviderInterface,
                                   environment_id=None):
    environment = Environments.get(environment_id)

    with claim_for_update(environment) as environment:
        # ASAP switch to use remote root user for provisioning
        atat_remote_root_creds = environment.root_user_info["credentials"]

        baseline_info = csp.create_environment_baseline(
            atat_remote_root_creds, environment.cloud_id)
        environment.baseline_info = baseline_info
        body = render_email("emails/application/environment_ready.txt",
                            {"environment": environment})
        app.mailer.send([environment.creator.email],
                        translate("email.environment_ready"), body)
        db.session.add(environment)
        db.session.commit()
Example #5
0
 def run(self):
     try:
         with claim_for_update(environment):
             satisfied_claims.append("SecondThread")
     except ClaimFailedException:
         exceptions.append("SecondThread")