Merge "Handle creation of plan with existing name"
This commit is contained in:
commit
30d90ff5e4
@ -22,6 +22,7 @@ from cliff import lister
|
||||
from cliff import show
|
||||
|
||||
from tuskarclient.common import utils
|
||||
from tuskarclient.openstack.common.apiclient import exceptions as exc
|
||||
|
||||
|
||||
class CreateManagementPlan(show.ShowOne):
|
||||
@ -47,11 +48,16 @@ class CreateManagementPlan(show.ShowOne):
|
||||
self.log.debug("take_action(%s)" % parsed_args)
|
||||
|
||||
client = self.app.client_manager.management
|
||||
name = parsed_args.name
|
||||
|
||||
plan = client.plans.create(
|
||||
name=parsed_args.name,
|
||||
description=parsed_args.description
|
||||
)
|
||||
try:
|
||||
plan = client.plans.create(
|
||||
name=name,
|
||||
description=parsed_args.description
|
||||
)
|
||||
except exc.Conflict:
|
||||
raise exc.CommandError(
|
||||
'Plan with name "%s" already exists.' % name)
|
||||
|
||||
return self.dict2columns(plan.to_dict())
|
||||
|
||||
|
@ -17,6 +17,7 @@ import sys
|
||||
|
||||
import tuskarclient.common.formatting as fmt
|
||||
from tuskarclient.common import utils
|
||||
from tuskarclient.openstack.common.apiclient import exceptions as exc
|
||||
|
||||
|
||||
def do_plan_list(tuskar, args, outfile=sys.stdout):
|
||||
@ -123,10 +124,14 @@ def do_plan_delete(tuskar, args, outfile=sys.stdout):
|
||||
help='User-readable text describing the Plan.')
|
||||
def do_plan_create(tuskar, args, outfile=sys.stdout):
|
||||
"""Create a new plan."""
|
||||
plan = tuskar.plans.create(
|
||||
name=vars(args).get('name'),
|
||||
description=vars(args).get('description')
|
||||
)
|
||||
name = vars(args).get('name')
|
||||
try:
|
||||
plan = tuskar.plans.create(
|
||||
name=name,
|
||||
description=vars(args).get('description')
|
||||
)
|
||||
except exc.Conflict:
|
||||
raise exc.CommandError('Plan with name "%s" already exists.' % name)
|
||||
print_plan_summary(plan, outfile=outfile)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user