autopep8
authorparmentelat <thierry.parmentelat@inria.fr>
Thu, 13 Dec 2018 15:17:28 +0000 (16:17 +0100)
committerparmentelat <thierry.parmentelat@inria.fr>
Thu, 13 Dec 2018 15:17:28 +0000 (16:17 +0100)
PLC/Logger.py
db-config.d/000-functions
db-config.d/020-boot_states
db-config.d/050-pcu_types
db-config.d/060-messages
db-config.d/099-hrns

index a48ac7d..aa2eb79 100644 (file)
@@ -1,11 +1,17 @@
 # pylint: disable=c0103
 
+import os
 import logging
 import logging.config
 
 # we essentially need one all-purpose logger
 # that goes into /var/log/plcapi.log
 
+# for debugging
+global_filename = "/var/log/plcapi.log"
+if 'PLCAPILOG' in os.environ:
+    global_filename = os.environ['PLCAPILOG']
+
 plcapi_logging_config = {
     'version': 1,
     # IMPORTANT: we may be imported by something else, like sfa, so:
@@ -19,7 +25,7 @@ plcapi_logging_config = {
     },
     'handlers': {
         'plcapi': {
-            'filename': '/var/log/plcapi.log',
+            'filename': global_filename,
             'level': 'INFO',
             'class': 'logging.FileHandler',
             'formatter': 'standard',
index f304036..30fd330 100644 (file)
@@ -1,9 +1,14 @@
 # -*-python-*-
 ####################
-import sys, os
+import sys
+import os
 
 g_url = ""
+
+
 def GetMyPLCURL(): return g_url
+
+
 def SetMyPLCURL(url):
     global g_url
     g_url = url
@@ -13,21 +18,25 @@ def SetMyPLCURL(url):
 g_known_tag_types = [tag_type['tagname'] for tag_type in GetTagTypes()]
 g_known_tag_types.sort()
 
-def AllPersonRoles (): return [ 'pi','user','tech' ]
+
+def AllPersonRoles():
+    return ['pi', 'user', 'tech']
+
 
 def SetTagType(tag_type):
     try:
-        tagname=tag_type['tagname']
+        tagname = tag_type['tagname']
         global g_known_tag_types
         # handle 'roles' field differently
         if 'roles' in tag_type:
-            roles=tag_type['roles']
+            roles = tag_type['roles']
             del tag_type['roles']
         else:
-            roles=['admin']
+            roles = ['admin']
         # just in case
         if 'min_role_id' in tag_type:
-            print("WARNING: ignoring deprecated field min_role_id for tagtype %s"%tagname)
+            print(
+                "WARNING: ignoring deprecated field min_role_id for tagtype %s" % tagname)
             del tag_type['min_role_id']
         # Create/update default slice tag types
         if tagname not in g_known_tag_types:
@@ -37,24 +46,25 @@ def SetTagType(tag_type):
         else:
             UpdateTagType(tagname, tag_type)
         # enforce provided roles if present
-        old_roles=GetTagTypes(tagname)[0]['roles']
+        old_roles = GetTagTypes(tagname)[0]['roles']
         for minus_role in set(old_roles).difference(set(roles)):
-            DeleteRoleFromTagType(minus_role,tagname)
+            DeleteRoleFromTagType(minus_role, tagname)
         for plus_role in set(roles).difference(set(old_roles)):
-            AddRoleToTagType(plus_role,tagname)
+            AddRoleToTagType(plus_role, tagname)
     except:
         # something went wrong for that tagname,
         # but don't want to break the whole startup sequence
-        print("Could not enforce tagtype %s --- beg"%tagname)
+        print("Could not enforce tagtype %s --- beg" % tagname)
         import traceback
         traceback.print_exc()
-        print("Could not enforce tagtype %s --- end"%tagname)
+        print("Could not enforce tagtype %s --- end" % tagname)
+
 
 # Get list of existing (enabled, global) files
 g_conf_files = GetConfFiles()
-g_conf_files = [conf_file for conf_file in g_conf_files if conf_file['enabled'] and \
-                    not conf_file['node_ids'] and \
-                    not conf_file['nodegroup_ids']]
+g_conf_files = [conf_file for conf_file in g_conf_files if conf_file['enabled'] and
+                not conf_file['node_ids'] and
+                not conf_file['nodegroup_ids']]
 g_dests = [conf_file['dest'] for conf_file in g_conf_files]
 g_conf_files = dict(list(zip(g_dests, g_conf_files)))
 
@@ -63,18 +73,20 @@ g_oldinitscripts = GetInitScripts()
 g_oldinitscript_names = [script['name'] for script in g_oldinitscripts]
 g_oldinitscripts = dict(list(zip(g_oldinitscript_names, g_oldinitscripts)))
 
+
 def SetInitScript(initscript):
     global g_oldinitscripts, g_oldinitscript_names
     if initscript['name'] not in g_oldinitscript_names:
         initscript_id = AddInitScript(initscript)
         g_oldinitscript_names.append(initscript['name'])
-        initscript['initscript_id']=initscript_id
-        g_oldinitscripts[initscript['name']]=initscript
+        initscript['initscript_id'] = initscript_id
+        g_oldinitscripts[initscript['name']] = initscript
     else:
         orig_initscript = g_oldinitscripts[initscript['name']]
         initscript_id = orig_initscript['initscript_id']
         UpdateInitScript(initscript_id, initscript)
 
+
 def SetConfFile(conf_file):
     global g_conf_files, g_dests
     if conf_file['dest'] not in g_dests:
@@ -84,17 +96,18 @@ def SetConfFile(conf_file):
         conf_file_id = orig_conf_file['conf_file_id']
         UpdateConfFile(conf_file_id, conf_file)
 
+
 def SetSlice(slice, tags):
     try:
         # Create or Update slice
         slice_name = slice['name']
         slices = GetSlices([slice_name])
-        if len(slices)==1:
+        if len(slices) == 1:
             slice_id = slices[0]['slice_id']
             if 'name' in slice:
                 del slice['name']
             UpdateSlice(slice_id, slice)
-            slice['name']=slice_name
+            slice['name'] = slice_name
         else:
             expires = None
             if 'expires' in slice:
@@ -102,7 +115,7 @@ def SetSlice(slice, tags):
                 del slice['expires']
             slice_id = AddSlice(slice)
             if expires is not None:
-                UpdateSlice(slice_id, {'expires':expires})
+                UpdateSlice(slice_id, {'expires': expires})
 
         # Get slice structure with all fields
         slice = GetSlices([slice_name])[0]
@@ -120,11 +133,12 @@ def SetSlice(slice, tags):
                 if (slice_tag['tagname'], slice_tag['value']) not in tags:
                     DeleteSliceTag(slice_tag['slice_tag_id'])
                 else:
-                    slice_tags.append((slice_tag['tagname'],slice_tag['value']))
+                    slice_tags.append(
+                        (slice_tag['tagname'], slice_tag['value']))
 
         # only add slice tags that are new
         for (name, value) in tags:
-            if (name,value) not in slice_tags:
+            if (name, value) not in slice_tags:
                 AddSliceTag(slice_name, name, value)
             else:
                 # NOTE: this confirms that the user-specified tag is
@@ -132,23 +146,26 @@ def SetSlice(slice, tags):
                 pass
     except:
         # something went wrong for that tagname,
-        print("Could not create init slice %s --- beg"%slice['name'])
+        print("Could not create init slice %s --- beg" % slice['name'])
         import traceback
         traceback.print_exc()
-        print("Could not create init slice %s --- end"%slice['name'])
+        print("Could not create init slice %s --- end" % slice['name'])
+
 
 def SetMessage(message):
     messages = GetMessages([message['message_id']])
-    if len(messages)==0:
+    if len(messages) == 0:
         AddMessage(message)
-    ### Thierry 2012-03
+    # Thierry 2012-03
     # let people customize their messages if they want to
-    #else:
+    # else:
     #    UpdateMessage(message['message_id'],message)
 
+
 # Get all model names
 g_pcu_models = [type['model'] for type in GetPCUTypes()]
 
+
 def SetPCUType(pcu_type):
     global g_pcu_models
     if 'pcu_protocol_types' in pcu_type:
index 0f7c768..076ce53 100644 (file)
@@ -1,5 +1,5 @@
 # -*-python-*-
-#################### slice tag types
+# slice tag types
 default_boot_states = [
     'boot',
     'failboot',
@@ -14,9 +14,8 @@ for state in default_boot_states:
     if state not in current_boot_states:
         AddBootState(state)
 
-# TODO: Delete old boot states. 
-if False:# NOTE: Only set to true if all federating peers have the new default boot states above.
+# TODO: Delete old boot states.
+if False:  # NOTE: Only set to true if all federating peers have the new default boot states above.
     for state in current_boot_states:
         if state not in default_boot_states:
             DeleteBootState(state)
-    
index 8db5bb3..84ee39f 100644 (file)
@@ -1,20 +1,20 @@
 # -*-python-*-
-#################### PCUs
-### Setup Initial PCU information
-       
+# PCUs
+# Setup Initial PCU information
+
 pcu_types = [
     {'model': 'HPiLO',
      'name': 'HP iLO v1 or v2 (Integrated Lights-Out)', },
-    
+
     {'model': 'IntelAMT',
      'name': 'Intel AMT v2.5 or v3.0 (Active Management Technology)', },
-    
+
     {'model': 'DRAC',
      'name': 'DRAC - Dell Remote Access Control (not Modular Chassis (MC))', },
-    
+
     {'model': 'OpenIPMI',
      'name': 'OpenIPMI - Intelligent Platform Management Interface', },
-    
+
     {'model': 'APCControl12p3',
      'name': 'APC AP79xx or Masterswitch (sequence 1-2-port-3)', },
     {'model': 'APCControl1p4',
@@ -25,38 +25,37 @@ pcu_types = [
      'name': 'APC AP79xx or Masterswitch (sequence 1-2-1-port-1)', },
     {'model': 'APCControl13p13',
      'name': 'APC AP79xx or Masterswitch (sequence 1-3-port-1-3)', },
-    
-    {'model': 'BayTechRPC3NC', 
+
+    {'model': 'BayTechRPC3NC',
      'name': 'BayTech with prompt RPC3-NC>', },
-    {'model': 'BayTechRPC16', 
+    {'model': 'BayTechRPC16',
      'name': 'BayTech with prompt RPC-16>', },
     {'model': 'BayTech',
      'name': 'BayTech with prompt DS-RPC>', },
-    {'model': 'BayTechCtrlC', 
+    {'model': 'BayTechCtrlC',
      'name': 'BayTech Ctrl-C, 5, then with prompt DS-RPC>', },
-    {'model': 'BayTechCtrlCUnibe', 
+    {'model': 'BayTechCtrlCUnibe',
      'name': 'BayTech Ctrl-C, 3, then with prompt DS-RPC>', },
-    
+
     {'model': 'BlackBoxPSMaverick',
      'name': 'BlackBoxPSMaverick Web based controller'},
-    
-    {'model': 'IPAL', 
+
+    {'model': 'IPAL',
      'name': 'IPAL - Dataprobe IP-41x & IP-81x', },
     {'model': 'ePowerSwitchNew',
      'name': 'ePowerSwitch Newer Models 1/4/8x', },
     {'model': 'ePowerSwitchOld',
      'name': 'ePowerSwitch Older Models 1/4/8x', },
-    
+
     {'model': 'PM211MIP',
      'name': 'Infratec PM221-MIP', },
-    
+
     {'model': 'WTIIPS4',
      'name': 'Western Telematic (WTI IPS-4)', },
-    
+
     {'model': 'ManualPCU',
      'name': 'Manual Administrator Operation (choose if model unknown)', },
-    ]
+]
 
 for pcu_type in pcu_types:
     SetPCUType(pcu_type)
-
index bee865e..4fa0530 100644 (file)
@@ -1,5 +1,5 @@
 # -*-python-*-
-#################### body for messages
+# body for messages
 
 installfailed = """Once the node meets these requirements, please reinitiate the install
 by visiting:
@@ -130,7 +130,7 @@ requirements.
     {'message_id': "authfail",
      'subject': "%(hostname)s failed to authenticate",
      'template':
-"""
+     """
 %(hostname)s failed to authenticate for the following reason:
 
 %(fault)s
@@ -164,7 +164,7 @@ message, please reply so that we can help investigate the problem.
     {'message_id': "notinstalled",
      'subject': "%(hostname)s is not installed",
      'template':
-"""
+     """
 %(hostname)s failed to boot because it has either never been
 installed, or the installation is corrupt.
 
@@ -183,7 +183,7 @@ message, please reply so that we may investigate the problem.
     {'message_id': "missingkernel",
      'subject': "%(hostname)s is missing its production kernel",
      'template':
-"""
+     """
 %(hostname)s failed to boot because the filesystem is missing its production
 kernel.
 
@@ -199,7 +199,7 @@ We will investigate the problem shortly.
     {'message_id': "filesystemcorrupted",
      'subject': "%(hostname)s may have corrupt filesystem",
      'template':
-"""
+     """
 %(hostname)s failed to boot because the filesystem appears to be corrupted. 
 
 No action is needed from you at this time; this message is merely
@@ -214,7 +214,7 @@ We will investigate the problem shortly.
     {'message_id': "mountfailed",
      'subject': "%(hostname)s could not mount filesystem",
      'template':
-"""
+     """
 %(hostname)s failed to boot because the boot scripts could not mount the 
 filesystem.
 
@@ -230,7 +230,7 @@ We will investigate the problem shortly.
     {'message_id': "hostnamenotresolve",
      'subject': "%(hostname)s does not resolve",
      'template':
-"""
+     """
 %(hostname)s failed to boot because its hostname does not resolve, or
 does resolve but does not match its configured IP address.
 
@@ -271,7 +271,7 @@ message, please reply so that we may investigate the problem.
     {'message_id': "nodetectednetwork",
      'subject': "%(hostname)s has unsupported network hardware",
      'template':
-"""
+     """
 
 %(hostname)s failed to boot because it has network hardware that is
 unsupported by the current production kernel. If it has booted
index 879c9d0..a2070f6 100644 (file)
@@ -1,6 +1,7 @@
 # -*-python-*-
-#################### 
+####################
 # quick and dirty, make sure all hrns are set on local nodes
 # could/should get trashed somedy
 
-for node in GetNodes({'peer_id':None}): UpdateNode(node['node_id'],{'hostname':node['hostname']})
+for node in GetNodes({'peer_id': None}):
+    UpdateNode(node['node_id'], {'hostname': node['hostname']})