From b0d0a3a2f8f7bff077f7ad456d1a1d18b0e701ef Mon Sep 17 00:00:00 2001
From: David Passante <david.passante@orange.com>
Date: Fri, 29 Mar 2019 15:39:54 +0100
Subject: [PATCH] cs_service_offering: Implement customizable compute offers
 (#54597)

---
 .../cloud/cloudstack/cs_service_offering.py   | 25 +++++++++++-
 .../tasks/guest_vm_service_offering.yml       | 40 +++++++++++++++++++
 2 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/lib/ansible/modules/cloud/cloudstack/cs_service_offering.py b/lib/ansible/modules/cloud/cloudstack/cs_service_offering.py
index 65deb32e83d..3b15fe7f1e6 100644
--- a/lib/ansible/modules/cloud/cloudstack/cs_service_offering.py
+++ b/lib/ansible/modules/cloud/cloudstack/cs_service_offering.py
@@ -162,6 +162,11 @@ options:
     type: list
     aliases:
       - storage_tag
+  is_customized:
+    description:
+      - Whether the offering is customizable or not.
+    type: bool
+    version_added: '2.8'
 extends_documentation_fragment: cloudstack
 '''
 
@@ -203,6 +208,16 @@ EXAMPLES = '''
     storage_tags: eco
   delegate_to: localhost
 
+- name: Create or update a custom compute service offering
+  cs_service_offering:
+    name: custom
+    display_text: custom compute offer
+    is_customized: yes
+    storage_type: shared
+    host_tags: eco
+    storage_tags: eco
+  delegate_to: localhost
+
 - name: Remove a compute service offering
   cs_service_offering:
     name: Tiny
@@ -362,6 +377,12 @@ network_rate:
   returned: success
   type: int
   sample: 1000
+is_customized:
+  description: Whether the offering is customizable or not
+  returned: success
+  type: bool
+  sample: false
+  version_added: '2.8'
 '''
 
 from ansible.module_utils.basic import AnsibleModule
@@ -470,7 +491,8 @@ class AnsibleCloudStackServiceOffering(AnsibleCloudStack):
             'storagetype': self.module.params.get('storage_type'),
             'systemvmtype': system_vm_type,
             'tags': self.module.params.get('storage_tags'),
-            'limitcpuuse': self.module.params.get('limit_cpu_usage')
+            'limitcpuuse': self.module.params.get('limit_cpu_usage'),
+            'customized': self.module.params.get('is_customized')
         }
         if not self.module.check_mode:
             res = self.query_api('createServiceOffering', **args)
@@ -536,6 +558,7 @@ def main():
         system_vm_type=dict(choices=['domainrouter', 'consoleproxy', 'secondarystoragevm']),
         storage_tags=dict(type='list', aliases=['storage_tag']),
         state=dict(choices=['present', 'absent'], default='present'),
+        is_customized=dict(type='bool'),
     ))
 
     module = AnsibleModule(
diff --git a/test/integration/targets/cs_service_offering/tasks/guest_vm_service_offering.yml b/test/integration/targets/cs_service_offering/tasks/guest_vm_service_offering.yml
index ea24b823c58..f7aee3c8a28 100644
--- a/test/integration/targets/cs_service_offering/tasks/guest_vm_service_offering.yml
+++ b/test/integration/targets/cs_service_offering/tasks/guest_vm_service_offering.yml
@@ -181,3 +181,43 @@
   assert:
     that:
     - so is not changed
+
+- name: create custom service offering
+  cs_service_offering:
+    name: custom
+    display_text: custom offer
+    is_customized: yes
+    host_tags: eco
+    storage_tags:
+      - eco
+      - backup
+    storage_type: local
+  register: so
+- name: verify create custom service offering
+  assert:
+    that:
+    - so is changed
+    - so.name == "custom"
+    - so.display_text == "custom offer"
+    - so.is_customized == True
+    - so.cpu_number is not defined
+    - so.cpu_speed is not defined
+    - so.memory is not defined
+    - so.host_tags == ['eco']
+    - so.storage_tags == ['eco', 'backup']
+    - so.storage_type == "local"
+
+- name: remove custom service offering
+  cs_service_offering:
+    name: custom
+    state: absent
+  register: so
+- name: verify remove service offering
+  assert:
+    that:
+    - so is changed
+    - so.name == "custom"
+    - so.display_text == "custom offer"
+    - so.host_tags == ['eco']
+    - so.storage_tags == ['eco', 'backup']
+    - so.storage_type == "local"