<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<br>
<br>
<div class="moz-cite-prefix">On 04/05/2016 01:28 PM, Aline Manera
wrote:<br>
</div>
<blockquote cite="mid:5703E7B9.4010004@linux.vnet.ibm.com"
type="cite">
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
<br>
<br>
<div class="moz-cite-prefix">On 04/05/2016 09:52 AM, Ramon
Medeiros wrote:<br>
</div>
<blockquote cite="mid:5703B506.9020505@linux.vnet.ibm.com"
type="cite">
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
<br>
<br>
<div class="moz-cite-prefix">On 04/04/2016 03:52 PM, Aline
Manera wrote:<br>
</div>
<blockquote cite="mid:5702B808.3060909@linux.vnet.ibm.com"
type="cite">
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
<br>
Hi Ramon,<br>
<br>
I just want to send you some tips on how to do that feature.<br>
<br>
1. You are changing the way the template is created. Now
source_media is a required parameter and need to be properly
added on API.json<br>
</blockquote>
Cdrom can be removed, but disks need to stay. For example: if
you want to create a template without disks? <br>
<br>
</blockquote>
<br>
You can remove the 'base' value available for disks.<br>
</blockquote>
But, what about scsi ? See the following test :<br>
<br>
test_scsi_fc_storage (i ran it with pdb and saw the "disks" list. I
can't understand how scsi templates can use source_media. <br>
<blockquote cite="mid:5703E7B9.4010004@linux.vnet.ibm.com"
type="cite"> <br>
<blockquote cite="mid:5703B506.9020505@linux.vnet.ibm.com"
type="cite"> Or, for scsi installation, you need disks to
specify the lun device.<br>
<blockquote cite="mid:5702B808.3060909@linux.vnet.ibm.com"
type="cite"> <br>
2. source_media will replace cdrom and disk[base], so, please
update API.json to reflect it.<br>
<br>
3. Following the Template creation flow, the request will
first touch on model/templates.py in create() function.<br>
<br>
The code below needs to be moved around as at this point you
will not know if source_media is an ISO or an Image file.<br>
<br>
...<br>
iso =
params.get('cdrom')
<br>
# check search
permission <br>
if iso and iso.startswith('/') and
os.path.exists(iso): <br>
st_mode =
os.stat(iso).st_mode <br>
if stat.S_ISREG(st_mode) or
stat.S_ISBLK(st_mode): <br>
user =
UserTests().probe_user() <br>
run_setfacl_set_attr(iso,
user=user) <br>
ret, excp = probe_file_permission_as_user(iso,
user) <br>
if ret is
False: <br>
raise
InvalidParameter('KCHISO0008E', <br>
{'filename': iso,
'user': user, <br>
'err': excp})
<br>
</blockquote>
done<br>
<blockquote cite="mid:5702B808.3060909@linux.vnet.ibm.com"
type="cite"> <br>
4. The second step is vmtemplate.py.<br>
As you can see you will need to change the function
_get_os_info() to something like:<br>
<b><br>
</b><b> source_media = args.get('source_media)</b><b><br>
</b><b> if source_media is not None:</b><b><br>
</b><b> if
source_media.startswith('http|https|ftp|...') or <use
python magic to identify it is an ISO> :</b><b><br>
</b><b> args[cdrom] = source_media</b><b><br>
</b><b> else:</b><b><br>
</b><b> # assume it is an image</b><b><br>
</b><b> args[disks] = {base: source_media}</b><small><br>
</small></blockquote>
Nope, when this function run, source_media is also identified on
cdrom or disks, so the code works like in the past. <br>
<br>
</blockquote>
<br>
Not sure I got your point here.<br>
When you receive a source_media you need to identify if it is a
cdrom or a disk, right?<br>
So this part of code is needed, correct?<br>
<br>
</blockquote>
Not it. <br>
<br>
You suggest to identify the media inside the method, but, when this
function is called, the media is already identified:<br>
<br>
93 def _create_template(self, args, scan=False):<br>
94 """<br>
95 Creates a new template<br>
96 """<br>
97 # no source_media argument: raise error<br>
98 if args.get("source_media") is None:<br>
99 raise MissingParameter('KCHTMPL0016E')<br>
100 <br>
101 # identify source media<br>
102 <b>self._identify_installation_media(args)</b><br>
103 <br>
104 # Fetch defaults based on the os distro and version<br>
105 try:<br>
106 distro, version = self._<b>self._get_os_info(args,
scan)</b><br>
107 except ImageFormatError as e:<br>
108 raise OperationFailed('KCHTMPL0020E', {'err':
e.message})<br>
109 os_distro = args.get('os_distro', distro)<br>
110 os_version = args.get('os_version', version)<br>
111 entry = osinfo.lookup(os_distro, os_version)<br>
<br>
<blockquote cite="mid:5703E7B9.4010004@linux.vnet.ibm.com"
type="cite">
<blockquote cite="mid:5703B506.9020505@linux.vnet.ibm.com"
type="cite">
<blockquote cite="mid:5702B808.3060909@linux.vnet.ibm.com"
type="cite"><small> </small><br>
# the code below keeps the same<br>
<br>
Does all that make sense for you?<br>
<br>
Regards,<br>
Aline Manera<br>
<br>
<div class="moz-cite-prefix">On 03/31/2016 10:47 AM, Ramon
Medeiros wrote:<br>
</div>
<blockquote
cite="mid:1459432076-27272-1-git-send-email-ramonn@linux.vnet.ibm.com"
type="cite">
<pre wrap="">Instead of specify if the media is cdrom or disk, use source_media to create a template
Changes:
v2:
Remove libvirt connection from VMtemplate
Fix incorrect changes on tests
Fix return status when source_media not passed
v3:
Fix pep8 issues
Remove/add some constants
Rewrite API message
Ramon Medeiros (4):
Create a single field to pass the installation media
Fix checking duplicate template before creating it
Identify installation media while creating template
Update tests
API.json | 5 ++
i18n.py | 2 +-
model/templates.py | 15 ++++--
tests/test_authorization.py | 4 +-
tests/test_livemigration.py | 7 +--
tests/test_mockmodel.py | 13 +++---
tests/test_model.py | 94 ++++++++++++++++++++-----------------
tests/test_rest.py | 36 +++++++--------
tests/test_template.py | 47 +++++++++----------
tests/test_vmtemplate.py | 40 ++++++++--------
vmtemplate.py | 110 +++++++++++++++++++++++++++++++++++++-------
11 files changed, 235 insertions(+), 138 deletions(-)
</pre>
</blockquote>
<br>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Ramon Nunes Medeiros
Kimchi Developer
Linux Technology Center Brazil
IBM Systems & Technology Group
Phone : +55 19 2132 7878
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:ramonn@br.ibm.com">ramonn@br.ibm.com</a> </pre>
</blockquote>
<br>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Ramon Nunes Medeiros
Kimchi Developer
Linux Technology Center Brazil
IBM Systems & Technology Group
Phone : +55 19 2132 7878
<a class="moz-txt-link-abbreviated" href="mailto:ramonn@br.ibm.com">ramonn@br.ibm.com</a> </pre>
</body>
</html>