Support more licensed products
Instead of hardcoding the os_distro name in code, this patch is proposing to add a new config option 'licensed_os_distro_list' under odoo config section so that we can support more os_distro for licensed products. Change-Id: Ia913ebec82815d5e9a0b681d0b0e0b4f5ecbb2d1
This commit is contained in:
parent
7579f5362c
commit
c5c5c5437a
|
@ -102,6 +102,13 @@ ODOO_OPTS = [
|
|||
"to hide the reseller margin for reseller's customer.")),
|
||||
cfg.FloatOpt('tax_rate', default='0.15',
|
||||
help='Tax rate for invoicing.'),
|
||||
cfg.ListOpt('licensed_os_distro_list',
|
||||
default=['windows',
|
||||
'sql-server-standard-windows',
|
||||
'sql-server-enterprise-windows'],
|
||||
help='The os_distro list supported for microsoft product '
|
||||
'family. e.g. in Odoo, the product name could be '
|
||||
'c1.c1r2-windows or c1.c2r4-sql-server-standard-windows')
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -470,21 +470,23 @@ class OdooDriver(driver.BaseDriver):
|
|||
products = self.get_products()[region]
|
||||
service_mapping = self._get_service_mapping(products)
|
||||
|
||||
# Find windows VM usage entries
|
||||
windows_vm_entries = []
|
||||
# Find licensed VM usage entries
|
||||
licensed_vm_entries = []
|
||||
for entry in measurements:
|
||||
(service_name, service_type, _, _, resource,
|
||||
resource_type) = self._get_entry_info(entry, resources_info,
|
||||
service_mapping)
|
||||
|
||||
if (service_type == COMPUTE_CATEGORY
|
||||
and resource_type == 'Virtual Machine'
|
||||
and resource.get('os_distro') == 'windows'):
|
||||
new_entry = copy.deepcopy(entry)
|
||||
setattr(new_entry, 'service', '%s-windows' % service_name)
|
||||
windows_vm_entries.append(new_entry)
|
||||
for os_distro in self.conf.odoo.licensed_os_distro_list:
|
||||
if (service_type == COMPUTE_CATEGORY
|
||||
and resource_type == 'Virtual Machine'
|
||||
and resource.get('os_distro') == os_distro):
|
||||
new_entry = copy.deepcopy(entry)
|
||||
setattr(new_entry,
|
||||
'service', '%s-%s' % (service_name, os_distro))
|
||||
licensed_vm_entries.append(new_entry)
|
||||
|
||||
for entry in itertools.chain(measurements, windows_vm_entries):
|
||||
for entry in itertools.chain(measurements, licensed_vm_entries):
|
||||
(service_name, service_type, volume, unit, resource,
|
||||
resource_type) = self._get_entry_info(entry, resources_info,
|
||||
service_mapping)
|
||||
|
|
|
@ -410,8 +410,8 @@ class TestOdooDriver(base.DistilTestCase):
|
|||
|
||||
@mock.patch('odoorpc.ODOO')
|
||||
@mock.patch('distil.erp.drivers.odoo.OdooDriver.get_products')
|
||||
def test_get_quotations_with_details_windows_vm(self, mock_get_products,
|
||||
mock_odoo):
|
||||
def test_get_quotations_with_details_licensed_vm(self, mock_get_products,
|
||||
mock_odoo):
|
||||
mock_get_products.return_value = {
|
||||
'nz_1': {
|
||||
'Compute': [
|
||||
|
@ -419,10 +419,19 @@ class TestOdooDriver(base.DistilTestCase):
|
|||
'name': 'c1.c2r16', 'description': 'c1.c2r16',
|
||||
'rate': 0.01, 'unit': 'hour'
|
||||
},
|
||||
{
|
||||
'name': 'c1.c4r32', 'description': 'c1.c4r32',
|
||||
'rate': 0.04, 'unit': 'hour'
|
||||
},
|
||||
{
|
||||
'name': 'c1.c2r16-windows',
|
||||
'description': 'c1.c2r16-windows',
|
||||
'rate': 0.02, 'unit': 'hour'
|
||||
},
|
||||
{
|
||||
'name': 'c1.c4r32-sql-server-standard-windows',
|
||||
'description': 'c1.c4r32-sql-server-standard-windows',
|
||||
'rate': 0.04, 'unit': 'hour'
|
||||
}
|
||||
],
|
||||
'Block Storage': [
|
||||
|
@ -445,6 +454,11 @@ class TestOdooDriver(base.DistilTestCase):
|
|||
2,
|
||||
'{"name": "instance2", "type": "Virtual Machine", '
|
||||
'"os_distro": "windows"}'
|
||||
),
|
||||
Resource(
|
||||
3,
|
||||
'{"name": "instance3", "type": "Virtual Machine", '
|
||||
'"os_distro": "sql-server-standard-windows"}'
|
||||
)
|
||||
]
|
||||
|
||||
|
@ -460,7 +474,8 @@ class TestOdooDriver(base.DistilTestCase):
|
|||
|
||||
usage = [
|
||||
Usage('b1.standard', 1, 1024 * 1024 * 1024, 'byte'),
|
||||
Usage('c1.c2r16', 2, 3600, 'second')
|
||||
Usage('c1.c2r16', 2, 3600, 'second'),
|
||||
Usage('c1.c4r32', 3, 3600, 'second'),
|
||||
]
|
||||
|
||||
odoodriver = odoo.OdooDriver(self.conf)
|
||||
|
@ -471,10 +486,10 @@ class TestOdooDriver(base.DistilTestCase):
|
|||
|
||||
self.assertDictEqual(
|
||||
{
|
||||
'total_cost': 0.05,
|
||||
'total_cost': 0.13,
|
||||
'details': {
|
||||
'Compute': {
|
||||
'total_cost': 0.03,
|
||||
'total_cost': 0.11,
|
||||
'breakdown': {
|
||||
'NZ-1.c1.c2r16': [
|
||||
{
|
||||
|
@ -496,6 +511,26 @@ class TestOdooDriver(base.DistilTestCase):
|
|||
"unit": "hour",
|
||||
}
|
||||
],
|
||||
'NZ-1.c1.c4r32': [
|
||||
{
|
||||
"resource_name": "instance3",
|
||||
"resource_id": 3,
|
||||
"cost": 0.04,
|
||||
"quantity": 1.0,
|
||||
"rate": 0.04,
|
||||
"unit": "hour",
|
||||
}
|
||||
],
|
||||
'NZ-1.c1.c4r32-sql-server-standard-windows': [
|
||||
{
|
||||
"resource_name": "instance3",
|
||||
"resource_id": 3,
|
||||
"cost": 0.04,
|
||||
"quantity": 1.0,
|
||||
"rate": 0.04,
|
||||
"unit": "hour",
|
||||
}
|
||||
],
|
||||
}
|
||||
},
|
||||
'Block Storage': {
|
||||
|
|
Loading…
Reference in New Issue