Add option to overwrite when adding template
Add --overwrite to the cli as an option and a parameter to the api Change-Id: I76942f4b4ebab64fdb51f5a727cb72c40d7d11a5
This commit is contained in:
parent
7c76bc764b
commit
5d00aa0e89
@ -1071,6 +1071,7 @@ Query Parameters
|
|||||||
|
|
||||||
- path (string, required) - the path to template file or directory
|
- path (string, required) - the path to template file or directory
|
||||||
- type (string, optional) - template type (standard,definition,equivalence)
|
- type (string, optional) - template type (standard,definition,equivalence)
|
||||||
|
- overwrite (boolean, optional) - if template already exists will overwrite it
|
||||||
|
|
||||||
Request Body
|
Request Body
|
||||||
============
|
============
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- Added support to overwrite existing template when adding one.
|
@ -11,7 +11,10 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
import pecan
|
import pecan
|
||||||
from pytz import utc
|
from pytz import utc
|
||||||
@ -28,6 +31,8 @@ from vitrage.common.exception import VitrageError
|
|||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
ONE_HOUR = int(timedelta(hours=1).total_seconds())
|
||||||
|
|
||||||
|
|
||||||
@profiler.trace_cls("template controller",
|
@profiler.trace_cls("template controller",
|
||||||
info={}, hide_args=False, trace_private=False)
|
info={}, hide_args=False, trace_private=False)
|
||||||
@ -93,6 +98,16 @@ class TemplateController(RootRestController):
|
|||||||
{})
|
{})
|
||||||
template_type = kwargs['template_type']
|
template_type = kwargs['template_type']
|
||||||
params = kwargs.get('params')
|
params = kwargs.get('params')
|
||||||
|
overwrite = kwargs.get('overwrite')
|
||||||
|
|
||||||
|
if overwrite:
|
||||||
|
names = [
|
||||||
|
template[1]['metadata']['name']
|
||||||
|
for template in templates
|
||||||
|
]
|
||||||
|
|
||||||
|
uuids = self._to_uuids(names)
|
||||||
|
self._delete_templates_and_wait(uuids)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return self._add(templates, template_type, params)
|
return self._add(templates, template_type, params)
|
||||||
@ -218,6 +233,21 @@ class TemplateController(RootRestController):
|
|||||||
return template.uuid
|
return template.uuid
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
def _delete_templates_and_wait(self, uuids):
|
||||||
|
self._delete(uuids)
|
||||||
|
|
||||||
|
def check_deleted():
|
||||||
|
for _id in uuids:
|
||||||
|
try:
|
||||||
|
self._show_template(_id)
|
||||||
|
except Exception: # if deleted we get exception
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
return wait_for_action_to_end(ONE_HOUR, check_deleted)
|
||||||
|
|
||||||
|
|
||||||
def is_uuid(val):
|
def is_uuid(val):
|
||||||
# unwrap the name or id
|
# unwrap the name or id
|
||||||
@ -226,3 +256,13 @@ def is_uuid(val):
|
|||||||
if type(val) is list:
|
if type(val) is list:
|
||||||
val, = val
|
val, = val
|
||||||
return is_uuid_like(val)
|
return is_uuid_like(val)
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_action_to_end(timeout, func, **kwargs):
|
||||||
|
count = 0
|
||||||
|
while count < timeout:
|
||||||
|
if func(**kwargs):
|
||||||
|
return True
|
||||||
|
count += 1
|
||||||
|
time.sleep(1)
|
||||||
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user