def post_remotes(user, project, domain, application): '''Bind project to application. ''' return projects.clone_remote(user, project, projects.Application(domain, application, None, None, None))
def post_application(user, domain): headers = bottle.HeaderDict(bottle.request.headers) headers.pop('content-length', None) body = request_params() #TODO: fix default gear_profile on broker if 'gear_profile' not in body: body.update(gear_profile=app.config.provider.openshift.default_gear_profile) is_dev_gear = body['gear_profile'] == app.config.provider.openshift.devel_gear_profile name = body['name'] app_name = '{name}-{domain}'.format(name=name, domain=domain) # For dev gears, the project already exists. # We simply add the new app as a remote to the project. # The project name is extracted from :initial_git_url, given # as a parameter to this request. # The git url MUST be inside our domain (ex: [email protected]/<project>.git) if is_dev_gear and 'initial_git_url' in body: match = re.match('(?:[a-z]+://)?git@git\.getupcloud\.com/(?P<project>[^.]+)\.git$', body['initial_git_url'], re.IGNORECASE) if not match: raise bottle.HTTPError(status=500, body='invalid git repository: {repo}'.format(repo=body['initial_git_url'])) project = match.group('project') body.pop('initial_git_url', None) else: project = '{name}-{domain}'.format(name=name, domain=domain) print 'Creatin application:' print ' - user: {user.email}'.format(user=user) print ' - name: {name}'.format(name=name) print ' - domain: {domain}'.format(domain=domain) print ' - project: {project}'.format(project=project) print ' - gear: {body[gear_profile]}'.format(body=body) # create git repo if not is_dev_gear: gitlab.Gitlab().add_project(project) # create the app print 'creating application: name={app_name}'.format(app_name=app_name) openshift = provider.OpenShift(user, hostname=app.config.provider.openshift.ops_hostname) uri = '?'.join(filter(None, [ bottle.request.fullpath, bottle.request.query_string ])) body = json.dumps(body) if bottle.request.json else dict(body) os_res = openshift(uri).POST(verify=False, data=body, headers=headers) print 'creating application: name={app_name} (done with {status})'.format(app_name=app_name, status=os_res.status_code) if not os_res.ok: print 'ERROR:', os_res.text return to_bottle_response(os_res) try: if is_dev_gear: res = projects.add_remote(user, project, projects.Application(domain, name, None, None, None)) os_res.json['data']['git_url'] = 'ssh://[email protected]/{project}.git'.format(project=project) projects.dns_register_wildcard_cname(app_name) else: res = projects.clone_remote(user, project, projects.Application(domain, name, None, None, None)) if not res.ok: print 'ERROR:', res.body finally: # account the app print 'accounting new application: name={project}'.format(project=project) aaa.create_app(user, domain, request_params()) return to_bottle_response(os_res)