|
19 | 19 | domains manage and assign domain names to your applications |
20 | 20 | builds manage builds created using `git push` |
21 | 21 | limits manage resource limits for your application |
| 22 | + tags manage tags for application containers |
22 | 23 | releases manage releases of an application |
23 | 24 |
|
24 | 25 | keys manage ssh keys used for `git push` deployments |
@@ -1587,6 +1588,127 @@ def ps_scale(self, args): |
1587 | 1588 | else: |
1588 | 1589 | raise ResponseError(response) |
1589 | 1590 |
|
| 1591 | + def tags(self, args): |
| 1592 | + """ |
| 1593 | + Valid commands for tags: |
| 1594 | +
|
| 1595 | + tags:list list tags for an app |
| 1596 | + tags:set set tags for an app |
| 1597 | + tags:unset unset tags for an app |
| 1598 | +
|
| 1599 | + Use `deis help [command]` to learn more. |
| 1600 | + """ |
| 1601 | + sys.argv[1] = 'tags:list' |
| 1602 | + args = docopt(self.tags_list.__doc__) |
| 1603 | + return self.tags_list(args) |
| 1604 | + |
| 1605 | + def tags_list(self, args): |
| 1606 | + """ |
| 1607 | + Lists tags for an application. |
| 1608 | +
|
| 1609 | + Usage: deis tags:list [options] |
| 1610 | +
|
| 1611 | + Options: |
| 1612 | + -a --app=<app> |
| 1613 | + the uniquely identifiable name of the application. |
| 1614 | + """ |
| 1615 | + app = args.get('--app') |
| 1616 | + if not app: |
| 1617 | + app = self._session.app |
| 1618 | + response = self._dispatch('get', "/api/apps/{}/config".format(app)) |
| 1619 | + if response.status_code == requests.codes.ok: # @UndefinedVariable |
| 1620 | + self._print_tags(app, response.json()) |
| 1621 | + else: |
| 1622 | + raise ResponseError(response) |
| 1623 | + |
| 1624 | + def tags_set(self, args): |
| 1625 | + """ |
| 1626 | + Sets tags for an application. |
| 1627 | +
|
| 1628 | + A tag is a key/value pair used to tag an application's containers. |
| 1629 | + This is often used to restrict workloads to specific hosts. |
| 1630 | +
|
| 1631 | + Usage: deis tags:set [options] <key>=<value>... |
| 1632 | +
|
| 1633 | + Arguments: |
| 1634 | + <key> the tag key, for example: "environ" or "rack" |
| 1635 | + <value> the tag value, for example: "prod" or "1" |
| 1636 | +
|
| 1637 | + Options: |
| 1638 | + -a --app=<app> |
| 1639 | + the uniquely identifiable name for the application. |
| 1640 | + """ |
| 1641 | + app = args.get('--app') |
| 1642 | + if not app: |
| 1643 | + app = self._session.app |
| 1644 | + body = {} |
| 1645 | + body['tags'] = json.dumps(dictify(args['<key>=<value>'])) |
| 1646 | + sys.stdout.write('Applying tags... ') |
| 1647 | + sys.stdout.flush() |
| 1648 | + try: |
| 1649 | + progress = TextProgress() |
| 1650 | + progress.start() |
| 1651 | + response = self._dispatch('post', "/api/apps/{}/config".format(app), json.dumps(body)) |
| 1652 | + finally: |
| 1653 | + progress.cancel() |
| 1654 | + progress.join() |
| 1655 | + if response.status_code == requests.codes.created: # @UndefinedVariable |
| 1656 | + version = response.headers['x-deis-release'] |
| 1657 | + print("done, v{}\n".format(version)) |
| 1658 | + |
| 1659 | + self._print_tags(app, response.json()) |
| 1660 | + else: |
| 1661 | + raise ResponseError(response) |
| 1662 | + |
| 1663 | + def tags_unset(self, args): |
| 1664 | + """ |
| 1665 | + Unsets tags for an application. |
| 1666 | +
|
| 1667 | + Usage: deis tags:unset [options] <key>... |
| 1668 | +
|
| 1669 | + Arguments: |
| 1670 | + <key> the tag key to unset, for example: "environ" or "rack" |
| 1671 | +
|
| 1672 | + Options: |
| 1673 | + -a --app=<app> |
| 1674 | + the uniquely identifiable name for the application. |
| 1675 | + """ |
| 1676 | + app = args.get('--app') |
| 1677 | + if not app: |
| 1678 | + app = self._session.app |
| 1679 | + values = {} |
| 1680 | + for k in args.get('<key>'): |
| 1681 | + values[k] = None |
| 1682 | + body = {} |
| 1683 | + body['tags'] = json.dumps(values) |
| 1684 | + sys.stdout.write('Applying tags... ') |
| 1685 | + sys.stdout.flush() |
| 1686 | + try: |
| 1687 | + progress = TextProgress() |
| 1688 | + progress.start() |
| 1689 | + response = self._dispatch('post', "/api/apps/{}/config".format(app), json.dumps(body)) |
| 1690 | + finally: |
| 1691 | + progress.cancel() |
| 1692 | + progress.join() |
| 1693 | + if response.status_code == requests.codes.created: # @UndefinedVariable |
| 1694 | + version = response.headers['x-deis-release'] |
| 1695 | + print("done, v{}\n".format(version)) |
| 1696 | + self._print_tags(app, response.json()) |
| 1697 | + else: |
| 1698 | + raise ResponseError(response) |
| 1699 | + |
| 1700 | + def _print_tags(self, app, config): |
| 1701 | + items = json.loads(config['tags']) |
| 1702 | + print("=== {} Tags".format(app)) |
| 1703 | + if len(items) == 0: |
| 1704 | + print('No tags defined') |
| 1705 | + return |
| 1706 | + keys = sorted(items) |
| 1707 | + width = max(map(len, keys)) + 5 |
| 1708 | + for k in keys: |
| 1709 | + v = items[k] |
| 1710 | + print(("{k:<" + str(width) + "} {v}").format(**locals())) |
| 1711 | + |
1590 | 1712 | def keys(self, args): |
1591 | 1713 | """ |
1592 | 1714 | Valid commands for SSH keys: |
|
0 commit comments