Adding states to disable nova-compute service

Change-Id: Id6042a5c18b6867fc90e5005e1edeb2eb3270f8e
Related-PROD: PROD-23088 (PROD:23088)
diff --git a/_states/novav21.py b/_states/novav21.py
index 1feefee..27e7f43 100644
--- a/_states/novav21.py
+++ b/_states/novav21.py
@@ -13,8 +13,9 @@
 import logging
 import six
 from six.moves import zip_longest
-
+import time
 import salt
+from salt.exceptions import CommandExecutionError
 
 LOG = logging.getLogger(__name__)
 
@@ -434,6 +435,56 @@
     return ret
 
 
+@_error_handler
+def service_enabled(name, cloud_name, binary="nova-compute"):
+    """Ensures that the service is enabled on the host
+
+    :param name:    name of a host where service is running
+    :param service: name of the service have to be run
+    """
+    changes = {}
+
+    services = _call_nova_salt_module('services_list', name)(
+        name, service=binary, cloud_name=cloud_name)
+    enabled_service = [s for s in services if s['binary'] == binary
+                       and s['status'] == 'enabled' and s['host'] == name]
+    if len(enabled_service) > 0:
+        ret = _no_change(name, 'Compute services')
+    else:
+        changes = _call_nova_salt_module('services_update', name)(
+            name, binary, 'enable', cloud_name=cloud_name)
+        ret = _updated(name, 'Compute services', changes)
+
+    return ret
+
+@_error_handler
+def service_disabled(name, cloud_name, binary="nova-compute", disabled_reason=None):
+    """Ensures that the service is disabled on the host
+
+    :param name:    name of a host where service is running
+    :param service: name of the service have to be disabled
+    """
+
+    changes = {}
+    kwargs = {}
+
+    if disabled_reason is not None:
+        kwargs['disabled_reason'] = disabled_reason
+
+    services = _call_nova_salt_module('services_list', name)(
+        name, service=binary, cloud_name=cloud_name)
+    disabled_service = [s for s in services if s['binary'] == binary
+                       and s['status'] == 'disabled' and s['host'] == name]
+    if len(disabled_service) > 0:
+        ret = _no_change(name, 'Compute services')
+    else:
+        changes = _call_nova_salt_module('services_update', name)(
+            name, binary, 'disable', cloud_name=cloud_name, **kwargs)
+        ret = _updated(name, 'Compute services', changes)
+
+    return ret
+
+
 def _find_failed(name, resource):
     return {
         'name': name, 'changes': {}, 'result': False,