diff --git a/client-api/api_lib/pvcapi_provisioner.py b/client-api/api_lib/pvcapi_provisioner.py index f7aad3b2..955764d4 100755 --- a/client-api/api_lib/pvcapi_provisioner.py +++ b/client-api/api_lib/pvcapi_provisioner.py @@ -650,7 +650,7 @@ def list_profile(limit, is_fuzzy=True): profile_data['id'] = profile['id'] profile_data['name'] = profile['name'] # Parse the name of each subelement - for etype in 'system_template', 'network_template', 'storage_template', 'userdata_template', 'script': + for etype in 'system_template', 'network_template', 'storage_template', 'userdata', 'script': query = 'SELECT name from {} WHERE id = %s'.format(etype) args = (profile[etype],) cur.execute(query, args) @@ -663,7 +663,7 @@ def list_profile(limit, is_fuzzy=True): close_database(conn, cur) return data -def create_profile(name, system_template, network_template, storage_template, userdata_template, script, arguments=[]): +def create_profile(name, system_template, network_template, storage_template, userdata, script, arguments=[]): if list_profile(name, is_fuzzy=False): retmsg = { 'message': 'The profile "{}" already exists'.format(name) } retcode = 400 @@ -699,13 +699,13 @@ def create_profile(name, system_template, network_template, storage_template, us retcode = 400 return retmsg, retcode - userdata_templates = list_template_userdata(None) - userdata_template_id = None - for template in userdata_templates: - if template['name'] == userdata_template: - userdata_template_id = template['id'] - if not userdata_template_id: - retmsg = { 'message': 'The userdata template "{}" for profile "{}" does not exist'.format(userdata_template, name) } + userdatas = list_template_userdata(None) + userdata_id = None + for template in userdatas: + if template['name'] == userdata: + userdata_id = template['id'] + if not userdata_id: + retmsg = { 'message': 'The userdata template "{}" for profile "{}" does not exist'.format(userdata, name) } retcode = 400 return retmsg, retcode @@ -723,8 +723,8 @@ def create_profile(name, system_template, network_template, storage_template, us conn, cur = open_database(config) try: - query = "INSERT INTO profile (name, system_template, network_template, storage_template, userdata_template, script, arguments) VALUES (%s, %s, %s, %s, %s, %s, %s);" - args = (name, system_template_id, network_template_id, storage_template_id, userdata_template_id, script_id, arguments_formatted) + query = "INSERT INTO profile (name, system_template, network_template, storage_template, userdata, script, arguments) VALUES (%s, %s, %s, %s, %s, %s, %s);" + args = (name, system_template_id, network_template_id, storage_template_id, userdata_id, script_id, arguments_formatted) cur.execute(query, args) retmsg = { "message": 'Created VM profile "{}"'.format(name) } retcode = 200 diff --git a/client-api/provisioner/schema.sql b/client-api/provisioner/schema.sql index c6e0c2a4..9503b62b 100644 --- a/client-api/provisioner/schema.sql +++ b/client-api/provisioner/schema.sql @@ -7,7 +7,7 @@ create table storage_template (id SERIAL PRIMARY KEY, name TEXT NOT NULL UNIQUE) create table storage (id SERIAL PRIMARY KEY, storage_template INT REFERENCES storage_template(id), pool TEXT NOT NULL, disk_id TEXT NOT NULL, disk_size_gb INT NOT NULL, mountpoint TEXT, filesystem TEXT, filesystem_args TEXT); create table userdata (id SERIAL PRIMARY KEY, name TEXT NOT NULL UNIQUE, userdata TEXT NOT NULL); create table script (id SERIAL PRIMARY KEY, name TEXT NOT NULL UNIQUE, script TEXT NOT NULL); -create table profile (id SERIAL PRIMARY KEY, name TEXT NOT NULL UNIQUE, system_template INT REFERENCES system_template(id), network_template INT REFERENCES network_template(id), storage_template INT REFERENCES storage_template(id), userdata_template INT REFERENCES userdata_template(id), script INT REFERENCES script(id), arguments text); +create table profile (id SERIAL PRIMARY KEY, name TEXT NOT NULL UNIQUE, system_template INT REFERENCES system_template(id), network_template INT REFERENCES network_template(id), storage_template INT REFERENCES storage_template(id), userdata INT REFERENCES userdata(id), script INT REFERENCES script(id), arguments text); grant all privileges on database pvcprov to pvcprov; grant all privileges on all tables in schema public to pvcprov; grant all privileges on all sequences in schema public to pvcprov;