<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 25, 2017 at 8:29 PM, Michal Skrivanek <span dir="ltr">&lt;<a href="mailto:michal.skrivanek@redhat.com" target="_blank">michal.skrivanek@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5"><br>
<br>
&gt; On 25 Dec 2017, at 18:41, Juan Hernández &lt;<a href="mailto:jhernand@redhat.com">jhernand@redhat.com</a>&gt; wrote:<br>
&gt;<br>
&gt; On 12/25/2017 05:46 PM, Yaniv Kaul wrote:<br>
&gt;&gt; While trying to add an instance type, I fail with the error:<br>
&gt;&gt; Operation Failed&quot;. Fault detail is &quot;[Cannot add Template. Memory size<br>
&gt;&gt; (1024MB) cannot exceed maximum memory size (0MB).]<br>
&gt;&gt; The code is taken from the example in the SDK, so I&#39;m not sure what I&#39;m<br>
&gt;&gt; doing wrong here.<br>
&gt;&gt; Code:<br>
&gt;&gt;         instance_types_service.add(<br>
&gt;&gt;             types.InstanceType(<br>
&gt;&gt;                 name=&#39;myinstancetype&#39;,<br>
&gt;&gt;                 description=&#39;My instance type&#39;,<br>
&gt;&gt;                 memory=1 * 2**30,<br>
&gt;&gt;                 high_availability=types.<wbr>HighAvailability(<br>
&gt;&gt;                     enabled=True,<br>
&gt;&gt;                 ),<br>
&gt;&gt;                 cpu=types.Cpu(<br>
&gt;&gt;                     topology=types.CpuTopology(<br>
&gt;&gt;                         cores=2,<br>
&gt;&gt;                         sockets=2,<br>
&gt;&gt;                     ),<br>
&gt;&gt;                 ),<br>
&gt;&gt;             ),<br>
&gt;&gt;         )<br>
&gt;&gt; engine.log:<br>
&gt;&gt; 2017-12-25 10:58:19,825-05 INFO<br>
&gt;&gt; [org.ovirt.engine.core.bll.<wbr>AddVmTemplateCommand] (default task-13)<br>
&gt;&gt; [265ff704-d89f-471b-8207-<wbr>fc0e1b8816fd] Lock Acquired to object<br>
&gt;&gt; &#39;EngineLock:{exclusiveLocks=&#39;[<wbr>myinstancetype=TEMPLATE_NAME,<br>
&gt;&gt; 703e1265-e160-4a76-82e6-<wbr>06974156b7b9=TEMPLATE]&#39;, sharedLocks=&#39;[]&#39;}&#39;<br>
&gt;&gt; 2017-12-25 10:58:19,831-05 WARN<br>
&gt;&gt; [org.ovirt.engine.core.bll.<wbr>AddVmTemplateCommand] (default task-13)<br>
&gt;&gt; [265ff704-d89f-471b-8207-<wbr>fc0e1b8816fd] Validation of action &#39;AddVmTemplate&#39;<br>
&gt;&gt; failed for user admin@internal-authz. Reasons:<br>
&gt;&gt; VAR__ACTION__ADD,VAR__TYPE__<wbr>VM_TEMPLATE,ACTION_TYPE_<wbr>FAILED_MAX_MEMORY_CANNOT_BE_<wbr>SMALLER_THAN_MEMORY_SIZE,$<wbr>maxMemory<br>
&gt;&gt; 0,$memory 1024<br>
&gt;&gt; 2017-12-25 10:58:19,832-05 INFO<br>
&gt;&gt; [org.ovirt.engine.core.bll.<wbr>AddVmTemplateCommand] (default task-13)<br>
&gt;&gt; [265ff704-d89f-471b-8207-<wbr>fc0e1b8816fd] Lock freed to object<br>
&gt;&gt; &#39;EngineLock:{exclusiveLocks=&#39;[<wbr>myinstancetype=TEMPLATE_NAME,<br>
&gt;&gt; 703e1265-e160-4a76-82e6-<wbr>06974156b7b9=TEMPLATE]&#39;, sharedLocks=&#39;[]&#39;}&#39;<br>
&gt;&gt; 2017-12-25 10:58:19,839-05 DEBUG<br>
&gt;&gt; [org.ovirt.engine.core.common.<wbr>di.interceptor.<wbr>DebugLoggingInterceptor]<br>
&gt;&gt; (default task-13) [265ff704-d89f-471b-8207-<wbr>fc0e1b8816fd] method: runAction,<br>
&gt;&gt; params: [AddVmTemplate,<br>
&gt;&gt; AddVmTemplateParameters:{<wbr>commandId=&#39;179df9ed-209c-4882-<wbr>a19a-b76a4fe1adb8&#39;,<br>
&gt;&gt; user=&#39;null&#39;, commandType=&#39;Unknown&#39;}], timeElapsed: 33ms<br>
&gt;&gt; 2017-12-25 10:58:19,846-05 ERROR<br>
&gt;&gt; [org.ovirt.engine.api.restapi.<wbr>resource.<wbr>AbstractBackendResource] (default<br>
&gt;&gt; task-13) [] Operation Failed: [Cannot add Template. Memory size (1024MB)<br>
&gt;&gt; cannot exceed maximum memory size (0MB).]<br>
&gt;&gt; TIA,<br>
&gt;&gt; Y.<br>
&gt;<br>
&gt; I think this is related to the new `memory_policy.max` attribute that was introduced in 4.1. I think that for virtual machines it has a default value so that it isn&#39;t necessary to explicitly provide it. It may not have a default value fro instance types. Can you try adding this to the request to create the instance type?<br>
&gt;<br>
&gt;  memory_policy=types.<wbr>MemoryPolicy(<br>
&gt;    max=1 * 2**30<br>
&gt;  )<br>
&gt;<br>
&gt; Then try again. If it works I think that we need to fix the engine so that it assigns a default value, like it does for virtual machines.<br>
<br>
</div></div>The default for VMs comes from the Blank template. There’s no template for instance types, so it always needs to be provided<br></blockquote><div><br></div><div>That&#39;s true in general, but not for max-memory. Let the blank template be defined with memory=1024mb and max-memory=4096mb. When a request to add a VM based on the blank template with memory=8192mb arrives with no max-memory specified, we cannot take the value of max-memory from the template since then the operation will fail (as the memory exceeds max memory)</div><div>When adding a VM from rest-api and max-memory is not specified then we set max-memory = memory * 4 [1, 2].</div><div>We can do the same for templates/instance types..</div><div><br></div><div>[1] <a href="https://github.com/oVirt/ovirt-engine/blob/master/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java#L163">https://github.com/oVirt/ovirt-engine/blob/master/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java#L163</a></div><div>[2] and that logic is problematic since the result may exceed the max memory limitation defined for the OS in os-info and then the operation will fail..</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div class="gmail-HOEnZb"><div class="gmail-h5"><span style="color:rgb(34,34,34)"> </span><br></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5">
&gt; ______________________________<wbr>_________________<br>
&gt; Devel mailing list<br>
&gt; <a href="mailto:Devel@ovirt.org">Devel@ovirt.org</a><br>
&gt; <a href="http://lists.ovirt.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.ovirt.org/<wbr>mailman/listinfo/devel</a><br>
&gt;<br>
&gt;<br>
<br>
______________________________<wbr>_________________<br>
Devel mailing list<br>
<a href="mailto:Devel@ovirt.org">Devel@ovirt.org</a><br>
<a href="http://lists.ovirt.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.ovirt.org/<wbr>mailman/listinfo/devel</a></div></div></blockquote></div><br></div></div>