Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
feat(client): add apps:rename command
Browse files Browse the repository at this point in the history
This allows users to modify their app names after having created
one.

There was a previous test in api/tests/test_app that checked
to ensure that the PATCH method was not allowed, so I repurposed
it to test appname changes.

The API call to modify app names is:

    PATCH /api/apps/{appname} {new_name}

Which will return HTTP status 200, and the endpoint is no longer
available. You will be able to reach the app at /api/apps/{new_name}
moving forward.

TESTING: Since this affects practically every aspect of app
management, running the integration test suite is recommended:

    $ vagrant up
    $ make pull
    $ cd test
    $ bundle exec rake

fixes #475
  • Loading branch information
Matthew Fisher committed May 15, 2014
1 parent 1737835 commit cafd4f3
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 3 deletions.
46 changes: 46 additions & 0 deletions client/deis.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ def apps(self, args):
apps:info view info about an application
apps:open open the application in a browser
apps:logs view aggregated application logs
apps:rename rename an application
apps:run run a command in an ephemeral app container
apps:destroy destroy an application
Expand Down Expand Up @@ -563,6 +564,50 @@ def apps_logs(self, args):
else:
raise ResponseError(response)

def apps_rename(self, args):
"""
Rename the app
Usage: deis apps:rename <new_name> [--app=<app>]
"""
current_name = args.get('--app')
if not current_name:
current_name = self._session.app
new_name = args['<new_name>']
body = {'id': new_name}
sys.stdout.write('Renaming app... ')
sys.stdout.flush()
try:
progress = TextProgress()
progress.start()
response = self._dispatch('patch',
'/api/apps/{}'.format(current_name),
json.dumps(body))
finally:
progress.cancel()
progress.join()
if response.status_code == requests.codes.ok: # @UndefinedVariable
data = response.json()
appname = data['id']
print("done, new name is {}".format(appname))
# modify the git remote
# TODO: retrieve the hostname from service discovery
hostname = urlparse.urlparse(self._settings['controller']).netloc.split(':')[0]
git_remote = "ssh://git@{hostname}:2222/{appname}.git".format(**locals())
if args.get('--no-remote'):
print('remote available at {}'.format(git_remote))
else:
try:
subprocess.check_call(
['git', 'remote', 'set-url', 'deis', git_remote],
stdout=subprocess.PIPE)
print('Git remote deis modified')
except subprocess.CalledProcessError:
print('Could not modify Deis remote')
sys.exit(1)
else:
raise ResponseError(response)

def apps_run(self, args):
"""
Run a command inside an ephemeral app container
Expand Down Expand Up @@ -1410,6 +1455,7 @@ def shortcuts(self, args):
('open', 'apps:open'),
('logs', 'apps:logs'),
('register', 'auth:register'),
('rename', 'apps:rename'),
('login', 'auth:login'),
('logout', 'auth:logout'),
('scale', 'ps:scale'),
Expand Down
10 changes: 9 additions & 1 deletion controller/api/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ def test_app(self):
self.assertEqual(response.status_code, 200)
body = {'id': 'new'}
response = self.client.patch(url, json.dumps(body), content_type='application/json')
self.assertEqual(response.status_code, 405)
self.assertEqual(response.status_code, 200)
response = self.client.delete(url)
self.assertEqual(response.status_code, 404)
app_id = 'new'
# verify that a new release was created
url = '/api/apps/{app_id}/releases'.format(**locals())
response = self.client.get(url, content_type='application/json')
self.assertEqual(response.data['count'], 2)
url = '/api/apps/{app_id}'.format(**locals())
response = self.client.delete(url)
self.assertEqual(response.status_code, 204)

Expand Down
6 changes: 5 additions & 1 deletion controller/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@
views.AppPermsViewSet.as_view({'get': 'list', 'post': 'create'})),
# apps base endpoint
url(r'^apps/(?P<id>[-_\w]+)/?',
views.AppViewSet.as_view({'get': 'retrieve', 'delete': 'destroy'})),
views.AppViewSet.as_view({
'get': 'retrieve',
'delete': 'destroy',
'patch': 'partial_update',
})),
url(r'^apps/?',
views.AppViewSet.as_view({'get': 'list', 'post': 'create'})),
# key
Expand Down
7 changes: 7 additions & 0 deletions controller/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ def post_save(self, app, created=False, **kwargs):
if created:
app.create()

def partial_update(self, request, *args, **kwargs):
app = get_object_or_404(models.App, id=kwargs['id'])
release = app.release_set.latest()
self.release = release.new(self.request.user)
app.deploy(self.release)
return super(AppViewSet, self).partial_update(request, *args, **kwargs)

def scale(self, request, **kwargs):
new_structure = {}
try:
Expand Down
13 changes: 13 additions & 0 deletions docs/developer/manage-application.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ Use ``deis run`` to execute commands against the deployed version of your applic
Applications deployed on Deis `use one-off processes for admin tasks`_ like
database migrations and other tasks that must run against the live application.

Rename the Application
----------------------

Sometimes, we just don't like the name that the auto-generation script makes
for us. We can use ``deis apps:rename`` to rename the application name to
something more sensible.

.. code-block:: console
$ deis rename african-swallow
Renaming app... done, new name is african-swallow
Git remote deis modified
Share the Application
---------------------
Use ``deis sharing:add`` to allow another Deis user to collaborate on your
Expand Down
7 changes: 6 additions & 1 deletion test/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,18 @@ namespace :tests do
task :verify_app do
run_command("curl -s http://testing.#{HOSTNAME} | grep -q 'Powered by Deis'")
end
task :rename_app do
Dir.chdir(EXAMPLE_APP) do
run_command('deis rename app-renamed')
end
end
end

namespace :cleanup do
task :all => ['destroy_app','destroy_cluster','remove_key','logout']
task :destroy_app do
Dir.chdir(EXAMPLE_APP) do
run_command('deis apps:destroy --app=testing --confirm=testing')
run_command('deis apps:destroy --app=app-renamed --confirm=app-renamed')
end
end
task :destroy_cluster do
Expand Down

1 comment on commit cafd4f3

@developerinlondon
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when is this coming out?

Please sign in to comment.