Implements use of yaml.safe_load as per sec audit
[releng.git] / utils / lab-reconfiguration / reconfigUcsNet.py
index 90c292b..4c08f3d 100755 (executable)
@@ -82,6 +82,17 @@ def ack_pending(handle=None, server=None):
     print " Pending-reboot -> Acknowledged."
 
 
+def boot_server(handle=None, server=None):
+    """
+    Boot server (when is in power-off state)
+    """
+    obj = handle.GetManagedObject(None, LsServer.ClassId(), {LsServer.DN: server.Dn})
+    handle.AddManagedObject(obj, LsPower.ClassId(), {
+            LsPower.DN: server.Dn + "/power",
+            LsPower.STATE:"admin-up"}, True)
+    print " Booting."
+
+
 def get_vnics(handle=None, server=None):
     """
     Return list of vnics for given server
@@ -146,7 +157,7 @@ def read_yaml_file(yamlFile):
     """
     # TODO: add check if vnic templates specified in file exist on UCS
     with open(yamlFile, 'r') as stream:
-        return yaml.load(stream)
+        return yaml.safe_load(stream)
 
 
 def set_network(handle=None, yamlFile=None):
@@ -176,6 +187,8 @@ def set_network(handle=None, yamlFile=None):
 
 
 if __name__ == "__main__":
+    print "\n*** SKIPING RECONFIGURATION.***\n"
+    sys.exit(0)
     # Latest urllib2 validate certs by default
     # The process wide "revert to the old behaviour" hook is to monkeypatch the ssl module
     # https://bugs.python.org/issue22417
@@ -216,6 +229,8 @@ if __name__ == "__main__":
         while True:
             list_of_states = []
             for server in get_servers(handle):
+                if server.OperState == "power-off":
+                    boot_server(handle,server)
                 if server.OperState == "pending-reboot":
                     ack_pending(handle,server)
                 list_of_states.append(server.OperState)
@@ -224,7 +239,7 @@ if __name__ == "__main__":
                 break
             if time.time() > timeout:
                 raise Exception("Timeout reached while waiting for OK status.")
-            time.sleep(5)
+            time.sleep(10)
 
         # Show current vnic MACs and VLANs
         get_network_config(handle)