Add variables support for remaining resources
This patch implements the variables support for the remaining resources that use variables Change-Id: I8d5515742db2d62ff1dea38c10018cc9579a82f4 Partial-Bug: 1659110
This commit is contained in:
parent
05b4f117bb
commit
c0cdd3950f
cratonclient
@ -14,6 +14,9 @@
|
||||
"""Cells resource and resource shell wrapper."""
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from cratonclient.common import cliutils
|
||||
from cratonclient import exceptions as exc
|
||||
|
||||
@ -221,3 +224,60 @@ def do_cell_delete(cc, args):
|
||||
else:
|
||||
print("Cell {0} was {1} deleted.".
|
||||
format(args.id, 'successfully' if response else 'not'))
|
||||
|
||||
|
||||
@cliutils.arg('id',
|
||||
metavar='<cell>',
|
||||
type=int,
|
||||
help='ID or name of the cell.')
|
||||
@cliutils.handle_shell_exception
|
||||
def do_cell_vars_get(cc, args):
|
||||
"""Get variables for a cell."""
|
||||
variables = cc.cells.get(args.id).variables.get()
|
||||
formatter = args.formatter.configure(dict_property="Variable", wrap=72)
|
||||
formatter.handle(variables)
|
||||
|
||||
|
||||
@cliutils.arg('id',
|
||||
metavar='<cell>',
|
||||
type=int,
|
||||
help='ID of the cell.')
|
||||
@cliutils.arg('variables', nargs=argparse.REMAINDER)
|
||||
@cliutils.handle_shell_exception
|
||||
def do_cell_vars_set(cc, args):
|
||||
"""Set variables for a cell."""
|
||||
cell_id = args.id
|
||||
if not args.variables and sys.stdin.isatty():
|
||||
raise exc.CommandError(
|
||||
'Nothing to update... Please specify variables to set in the '
|
||||
'following format: "key=value". You may also specify variables to '
|
||||
'delete by key using the format: "key="'
|
||||
)
|
||||
adds, deletes = cliutils.variable_updates(args.variables)
|
||||
variables = cc.cells.get(cell_id).variables
|
||||
if deletes:
|
||||
variables.delete(*deletes)
|
||||
variables.update(**adds)
|
||||
formatter = args.formatter.configure(wrap=72, dict_property="Variable")
|
||||
formatter.handle(variables.get())
|
||||
|
||||
|
||||
@cliutils.arg('id',
|
||||
metavar='<cell>',
|
||||
type=int,
|
||||
help='ID of the cell.')
|
||||
@cliutils.arg('variables', nargs=argparse.REMAINDER)
|
||||
@cliutils.handle_shell_exception
|
||||
def do_cell_vars_delete(cc, args):
|
||||
"""Delete variables for a cell by key."""
|
||||
cell_id = args.id
|
||||
if not args.variables and sys.stdin.isatty():
|
||||
raise exc.CommandError(
|
||||
'Nothing to delete... Please specify variables to delete by '
|
||||
'listing the keys you wish to delete separated by spaces.'
|
||||
)
|
||||
deletes = cliutils.variable_deletes(args.variables)
|
||||
variables = cc.cells.get(cell_id).variables
|
||||
response = variables.delete(*deletes)
|
||||
print("Variables {0} deleted.".
|
||||
format('successfully' if response else 'not'))
|
||||
|
@ -12,6 +12,9 @@
|
||||
"""Hosts resource and resource shell wrapper."""
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from cratonclient.common import cliutils
|
||||
from cratonclient import exceptions as exc
|
||||
|
||||
@ -153,3 +156,60 @@ def do_cloud_delete(cc, args):
|
||||
else:
|
||||
print("Cloud {0} was {1} deleted.".
|
||||
format(args.id, 'successfully' if response else 'not'))
|
||||
|
||||
|
||||
@cliutils.arg('id',
|
||||
metavar='<cloud>',
|
||||
type=int,
|
||||
help='ID or name of the cloud.')
|
||||
@cliutils.handle_shell_exception
|
||||
def do_cloud_vars_get(cc, args):
|
||||
"""Get variables for a cloud."""
|
||||
variables = cc.clouds.get(args.id).variables.get()
|
||||
formatter = args.formatter.configure(dict_property="Variable", wrap=72)
|
||||
formatter.handle(variables)
|
||||
|
||||
|
||||
@cliutils.arg('id',
|
||||
metavar='<cloud>',
|
||||
type=int,
|
||||
help='ID of the cloud.')
|
||||
@cliutils.arg('variables', nargs=argparse.REMAINDER)
|
||||
@cliutils.handle_shell_exception
|
||||
def do_cloud_vars_set(cc, args):
|
||||
"""Set variables for a cloud."""
|
||||
cloud_id = args.id
|
||||
if not args.variables and sys.stdin.isatty():
|
||||
raise exc.CommandError(
|
||||
'Nothing to update... Please specify variables to set in the '
|
||||
'following format: "key=value". You may also specify variables to '
|
||||
'delete by key using the format: "key="'
|
||||
)
|
||||
adds, deletes = cliutils.variable_updates(args.variables)
|
||||
variables = cc.clouds.get(cloud_id).variables
|
||||
if deletes:
|
||||
variables.delete(*deletes)
|
||||
variables.update(**adds)
|
||||
formatter = args.formatter.configure(wrap=72, dict_property="Variable")
|
||||
formatter.handle(variables.get())
|
||||
|
||||
|
||||
@cliutils.arg('id',
|
||||
metavar='<cloud>',
|
||||
type=int,
|
||||
help='ID of the cloud.')
|
||||
@cliutils.arg('variables', nargs=argparse.REMAINDER)
|
||||
@cliutils.handle_shell_exception
|
||||
def do_cloud_vars_delete(cc, args):
|
||||
"""Delete variables for a cloud by key."""
|
||||
cloud_id = args.id
|
||||
if not args.variables and sys.stdin.isatty():
|
||||
raise exc.CommandError(
|
||||
'Nothing to delete... Please specify variables to delete by '
|
||||
'listing the keys you wish to delete separated by spaces.'
|
||||
)
|
||||
deletes = cliutils.variable_deletes(args.variables)
|
||||
variables = cc.clouds.get(cloud_id).variables
|
||||
response = variables.delete(*deletes)
|
||||
print("Variables {0} deleted.".
|
||||
format('successfully' if response else 'not'))
|
||||
|
@ -14,6 +14,9 @@
|
||||
"""Projects resource and resource shell wrapper."""
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from cratonclient.common import cliutils
|
||||
from cratonclient import exceptions as exc
|
||||
|
||||
@ -131,3 +134,57 @@ def do_project_delete(cc, args):
|
||||
else:
|
||||
print("Project {0} was {1} deleted.".
|
||||
format(args.id, 'successfully' if response else 'not'))
|
||||
|
||||
|
||||
@cliutils.arg('id',
|
||||
metavar='<project>',
|
||||
help='ID or name of the project.')
|
||||
@cliutils.handle_shell_exception
|
||||
def do_project_vars_get(cc, args):
|
||||
"""Get variables for a project."""
|
||||
variables = cc.projects.get(args.id).variables.get()
|
||||
formatter = args.formatter.configure(dict_property="Variable", wrap=72)
|
||||
formatter.handle(variables)
|
||||
|
||||
|
||||
@cliutils.arg('id',
|
||||
metavar='<project>',
|
||||
help='ID of the project.')
|
||||
@cliutils.arg('variables', nargs=argparse.REMAINDER)
|
||||
@cliutils.handle_shell_exception
|
||||
def do_project_vars_set(cc, args):
|
||||
"""Set variables for a project."""
|
||||
project_id = args.id
|
||||
if not args.variables and sys.stdin.isatty():
|
||||
raise exc.CommandError(
|
||||
'Nothing to update... Please specify variables to set in the '
|
||||
'following format: "key=value". You may also specify variables to '
|
||||
'delete by key using the format: "key="'
|
||||
)
|
||||
adds, deletes = cliutils.variable_updates(args.variables)
|
||||
variables = cc.projects.get(project_id).variables
|
||||
if deletes:
|
||||
variables.delete(*deletes)
|
||||
variables.update(**adds)
|
||||
formatter = args.formatter.configure(wrap=72, dict_property="Variable")
|
||||
formatter.handle(variables.get())
|
||||
|
||||
|
||||
@cliutils.arg('id',
|
||||
metavar='<project>',
|
||||
help='ID of the project.')
|
||||
@cliutils.arg('variables', nargs=argparse.REMAINDER)
|
||||
@cliutils.handle_shell_exception
|
||||
def do_project_vars_delete(cc, args):
|
||||
"""Delete variables for a project by key."""
|
||||
project_id = args.id
|
||||
if not args.variables and sys.stdin.isatty():
|
||||
raise exc.CommandError(
|
||||
'Nothing to delete... Please specify variables to delete by '
|
||||
'listing the keys you wish to delete separated by spaces.'
|
||||
)
|
||||
deletes = cliutils.variable_deletes(args.variables)
|
||||
variables = cc.projects.get(project_id).variables
|
||||
response = variables.delete(*deletes)
|
||||
print("Variables {0} deleted.".
|
||||
format('successfully' if response else 'not'))
|
||||
|
@ -12,6 +12,9 @@
|
||||
"""Hosts resource and resource shell wrapper."""
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from cratonclient.common import cliutils
|
||||
from cratonclient import exceptions as exc
|
||||
|
||||
@ -181,3 +184,60 @@ def do_region_delete(cc, args):
|
||||
else:
|
||||
print("Region {0} was {1} deleted.".
|
||||
format(args.id, 'successfully' if response else 'not'))
|
||||
|
||||
|
||||
@cliutils.arg('id',
|
||||
metavar='<region>',
|
||||
type=int,
|
||||
help='ID or name of the region.')
|
||||
@cliutils.handle_shell_exception
|
||||
def do_region_vars_get(cc, args):
|
||||
"""Get variables for a region."""
|
||||
variables = cc.regions.get(args.id).variables.get()
|
||||
formatter = args.formatter.configure(dict_property="Variable", wrap=72)
|
||||
formatter.handle(variables)
|
||||
|
||||
|
||||
@cliutils.arg('id',
|
||||
metavar='<region>',
|
||||
type=int,
|
||||
help='ID of the region.')
|
||||
@cliutils.arg('variables', nargs=argparse.REMAINDER)
|
||||
@cliutils.handle_shell_exception
|
||||
def do_region_vars_set(cc, args):
|
||||
"""Set variables for a region."""
|
||||
region_id = args.id
|
||||
if not args.variables and sys.stdin.isatty():
|
||||
raise exc.CommandError(
|
||||
'Nothing to update... Please specify variables to set in the '
|
||||
'following format: "key=value". You may also specify variables to '
|
||||
'delete by key using the format: "key="'
|
||||
)
|
||||
adds, deletes = cliutils.variable_updates(args.variables)
|
||||
variables = cc.regions.get(region_id).variables
|
||||
if deletes:
|
||||
variables.delete(*deletes)
|
||||
variables.update(**adds)
|
||||
formatter = args.formatter.configure(wrap=72, dict_property="Variable")
|
||||
formatter.handle(variables.get())
|
||||
|
||||
|
||||
@cliutils.arg('id',
|
||||
metavar='<region>',
|
||||
type=int,
|
||||
help='ID of the region.')
|
||||
@cliutils.arg('variables', nargs=argparse.REMAINDER)
|
||||
@cliutils.handle_shell_exception
|
||||
def do_region_vars_delete(cc, args):
|
||||
"""Delete variables for a region by key."""
|
||||
region_id = args.id
|
||||
if not args.variables and sys.stdin.isatty():
|
||||
raise exc.CommandError(
|
||||
'Nothing to delete... Please specify variables to delete by '
|
||||
'listing the keys you wish to delete separated by spaces.'
|
||||
)
|
||||
deletes = cliutils.variable_deletes(args.variables)
|
||||
variables = cc.regions.get(region_id).variables
|
||||
response = variables.delete(*deletes)
|
||||
print("Variables {0} deleted.".
|
||||
format('successfully' if response else 'not'))
|
||||
|
@ -24,6 +24,7 @@ class TestCloud(base.TestCase):
|
||||
def test_is_a_resource_instance(self):
|
||||
"""Verify that a Cloud instance is an instance of a Resource."""
|
||||
manager = mock.Mock()
|
||||
manager.extra_request_kwargs = {}
|
||||
self.assertIsInstance(clouds.Cloud(manager, {"id": 1234}),
|
||||
crud.Resource)
|
||||
|
||||
|
@ -24,6 +24,7 @@ class TestRegion(base.TestCase):
|
||||
def test_is_a_resource_instance(self):
|
||||
"""Verify that a Region instance is an instance of a Resource."""
|
||||
manager = mock.Mock()
|
||||
manager.extra_request_kwargs = {}
|
||||
self.assertIsInstance(regions.Region(manager, {"id": 1234}),
|
||||
crud.Resource)
|
||||
|
||||
|
@ -13,12 +13,15 @@
|
||||
# under the License.
|
||||
"""Regions manager code."""
|
||||
from cratonclient import crud
|
||||
from cratonclient.v1 import variables
|
||||
|
||||
|
||||
class Cell(crud.Resource):
|
||||
"""Representation of a Region."""
|
||||
|
||||
pass
|
||||
subresource_managers = {
|
||||
'variables': variables.VariableManager,
|
||||
}
|
||||
|
||||
|
||||
class CellManager(crud.CRUDClient):
|
||||
|
@ -13,12 +13,15 @@
|
||||
# under the License.
|
||||
"""Clouds manager code."""
|
||||
from cratonclient import crud
|
||||
from cratonclient.v1 import variables
|
||||
|
||||
|
||||
class Cloud(crud.Resource):
|
||||
"""Representation of a Cloud."""
|
||||
|
||||
pass
|
||||
subresource_managers = {
|
||||
'variables': variables.VariableManager,
|
||||
}
|
||||
|
||||
|
||||
class CloudManager(crud.CRUDClient):
|
||||
|
@ -13,12 +13,15 @@
|
||||
# under the License.
|
||||
"""Regions manager code."""
|
||||
from cratonclient import crud
|
||||
from cratonclient.v1 import variables
|
||||
|
||||
|
||||
class Project(crud.Resource):
|
||||
"""Representation of a Project."""
|
||||
|
||||
pass
|
||||
subresource_managers = {
|
||||
'variables': variables.VariableManager,
|
||||
}
|
||||
|
||||
|
||||
class ProjectManager(crud.CRUDClient):
|
||||
|
@ -13,12 +13,15 @@
|
||||
# under the License.
|
||||
"""Regions manager code."""
|
||||
from cratonclient import crud
|
||||
from cratonclient.v1 import variables
|
||||
|
||||
|
||||
class Region(crud.Resource):
|
||||
"""Representation of a Region."""
|
||||
|
||||
pass
|
||||
subresource_managers = {
|
||||
'variables': variables.VariableManager,
|
||||
}
|
||||
|
||||
|
||||
class RegionManager(crud.CRUDClient):
|
||||
|
Loading…
x
Reference in New Issue
Block a user