[ovirt-users] How to create a DataCenterQuota via Python SDK?

Nicolás nicolas at devels.es
Sat Feb 20 08:45:16 UTC 2016


El 19/02/16 a las 13:56, nicolas at devels.es escribió:
> Hi,
>
> I'm trying to create a Data Center Quota with limits for memory, vcpu 
> and storage. As per the class definition, DataCenterQuota expects: a 
> datacenter, a quota and a context. Quota class in turn expects limits 
> but only as percentages, for hard and soft limits.
>
> However if I dump an already created DataCenterQuota object I see:
>
> {'_Base__context': 36443152,
>  'parentclass': <ovirtsdk.xml.params.DataCenter object at 0x278e750>,
>  'permissions': 
> <ovirtsdk.infrastructure.brokers.DataCenterQuotaPermissions object at 
> 0x278ef90>,
>  'quotaclusterlimits': 
> <ovirtsdk.infrastructure.brokers.DataCenterQuotaQuotaClusterLimits 
> object at 0x2540490>,
>  'quotastoragelimits': 
> <ovirtsdk.infrastructure.brokers.DataCenterQuotaQuotaStorageLimits 
> object at 0x278ef50>,
>  'superclass': <ovirtsdk.xml.params.Quota object at 0x278ec90>}
>
> I see DataCenterQuotaQuotaClusterLimits and 
> DataCenterQuotaQuotaStorageLimits allow creating limits for memory/cpu 
> and storage respectively, and they're set in the DataCenterQuota 
> __init__ method like this:
>
>   self.quotaclusterlimits = DataCenterQuotaQuotaClusterLimits(self, 
> context)
>   self.quotastoragelimits = DataCenterQuotaQuotaStorageLimits(self, 
> context)
>
> However, I'm unable to find out how to handle the 'context' parameter 
> to contain those two limit classes.
>
> Could someone shed some light on it? An example would be welcome too.
>
> Thanks.
>
> Nicolás
> _______________________________________________
> Users mailing list
> Users at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/users

I found a way, not sure if it's the best way to go though (probably 
not), but works.

dc=api.datacenters.get(name='DC')
q = params.Quota(name='Python-SDK', description='Python-SDK', 
data_center=dc, cluster_soft_limit_pct=80, cluster_hard_limit_pct=20, 
storage_soft_limit_pct=80, storage_hard_limit_pct=20)
dc.quotas.add(q)

z = dc.quotas.get(name='Python-SDK')
qcl = params.QuotaClusterLimit(vcpu_limit=20, memory_limit=1)
z.quotaclusterlimits.add(qcl)
qsl = params.QuotaStorageLimit(limit=500)
z.quotastoragelimits.add(qsl)

Regards.



More information about the Users mailing list