fix: create template with Marvin (#4631)

* undefined params
* if we define those params, when invoking the functions
create_from_volume/create_from_snapshot will be created two templates
* according to the API docs createTemplate command does not accept account and
domainid
This commit is contained in:
slavkap 2021-05-25 17:56:43 +03:00 committed by GitHub
parent 06744c16ba
commit a0d9acec6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 17 deletions

View File

@ -1476,16 +1476,12 @@ class Template:
@classmethod
def create_from_volume(cls, apiclient, volume, services,
random_name=True):
random_name=True, projectid=None):
"""Create Template from volume"""
# Create template from Volume ID
cmd = createTemplate.createTemplateCmd()
Template._set_command(apiclient, cmd, services, random_name)
cmd.volumeid = volume.id
return Template(apiclient.createTemplate(cmd).__dict__)
return Template._set_command(apiclient, cmd, services, random_name, projectid = projectid, volume = volume)
@classmethod
def create_from_snapshot(cls, apiclient, snapshot, services, account=None,
@ -1494,14 +1490,10 @@ class Template:
# Create template from Snapshot ID
cmd = createTemplate.createTemplateCmd()
Template._set_command(apiclient, cmd, services, random_name)
cmd.snapshotid = snapshot.id
return Template(apiclient.createTemplate(cmd).__dict__)
return Template._set_command(apiclient, cmd, services, random_name, snapshot = snapshot, projectid = projectid)
@classmethod
def _set_command(cls, apiclient, cmd, services, random_name=True):
def _set_command(cls, apiclient, cmd, services, random_name=True, snapshot=None, volume=None, projectid=None):
cmd.displaytext = services["displaytext"]
cmd.name = "-".join([
services["name"],
@ -1528,12 +1520,12 @@ class Template:
raise Exception(
"Unable to find Ostype is required for creating template")
cmd.snapshotid = snapshot.id
if volume:
cmd.volumeid = volume.id
if snapshot:
cmd.snapshotid = snapshot.id
if account:
cmd.account = account
if domainid:
cmd.domainid = domainid
if projectid:
cmd.projectid = projectid