Module and states code refactor

Change-Id: Ia1c468d0b55603b6274ca0d275b2720602e5319e
diff --git a/_states/jenkins_security.py b/_states/jenkins_security.py
index 6442e2b..98e8a70 100644
--- a/_states/jenkins_security.py
+++ b/_states/jenkins_security.py
@@ -1,4 +1,5 @@
 import logging
+
 logger = logging.getLogger(__name__)
 
 set_ldap_groovy = """\
@@ -6,24 +7,24 @@
 import hudson.security.*
 import org.jenkinsci.plugins.*
 
-def server = '{server}'
-def rootDN = '{rootDN}'
-def userSearchBase = '{userSearchBase}'
-def userSearch = '{userSearch}'
-def groupSearchBase = '{groupSearchBase}'
-def managerDN = '{managerDN}'
-def managerPassword = '{managerPassword}'
+def server = '${server}'
+def rootDN = '${rootDN}'
+def userSearchBase = '${userSearchBase}'
+def userSearch = '${userSearch}'
+def groupSearchBase = '${groupSearchBase}'
+def managerDN = '${managerDN}'
+def managerPassword = '${managerPassword}'
 boolean inhibitInferRootDN = {inhibitInferRootDN}
 
-try{{
+try{
 ldapRealm = Class.forName("hudson.security.LDAPSecurityRealm").getConstructor(String.class, String.class, String.class, String.class, String.class, String.class, String.class, Boolean.TYPE)
 .newInstance(server, rootDN, userSearchBase, userSearch, groupSearchBase, managerDN, managerPassword, inhibitInferRootDN) 
 Jenkins.instance.setSecurityRealm(ldapRealm)
 Jenkins.instance.save()
 print("SUCCESS")
-}}catch(ClassNotFoundException e){{
+}catch(ClassNotFoundException e){
     print("Cannot instantiate LDAPSecurityRealm, maybe ldap plugin not installed")
-}}
+}
 """  # noqa
 
 set_matrix_groovy = """\
@@ -32,15 +33,15 @@
 import com.cloudbees.plugins.credentials.*
 
 def instance = Jenkins.getInstance()
-try{{
-def strategy = Class.forName("hudson.security.{matrix_class}").newInstance()
-{strategies}
+try{
+def strategy = Class.forName("hudson.security.${matrix_class}").newInstance()
+${strategies}
 instance.setAuthorizationStrategy(strategy)
 instance.save()
 print("SUCCESS")
-}}catch(ClassNotFoundException e){{
-    print("Cannot instantiate {matrix_class}, maybe auth-matrix plugin not installed")
-}}
+}catch(ClassNotFoundException e){
+    print("Cannot instantiate ${matrix_class}, maybe auth-matrix plugin not installed")
+}
 """  # noqa
 
 
@@ -56,7 +57,8 @@
     return True
 
 
-def ldap(name, server, root_dn, user_search_base, manager_dn, manager_password, user_search="", group_search_base="", inhibit_infer_root_dn=False):
+def ldap(name, server, root_dn, user_search_base, manager_dn, manager_password,
+         user_search="", group_search_base="", inhibit_infer_root_dn=False):
     """
     Jenkins ldap state method
 
@@ -93,7 +95,7 @@
                               "managerDN": manager_dn if manager_dn else "",
                               "managerPassword": manager_password if manager_password else "",
                               "userSearch": user_search if user_search else "",
-                              "groupSearchBase": group_search_base if group_search_base else "", 
+                              "groupSearchBase": group_search_base if group_search_base else "",
                               "inhibitInferRootDN": "true" if inhibit_infer_root_dn else "false"})
         if call_result["code"] == 200 and call_result["msg"] == "SUCCESS":
             status = call_result["msg"]
@@ -155,7 +157,8 @@
 
 def _build_strategies(permissions):
     strategies_str = ""
-    for strategy in _to_strategies_list("strategy.add({},\"{}\")", _to_one_dict(permissions, "")):
+    for strategy in _to_strategies_list(
+            "strategy.add({},\"{}\")", _to_one_dict(permissions, "")):
         strategies_str += "{}\n".format(strategy)
     return strategies_str