OSDN Git Service

Add validate
[karesansui/karesansui.git] / bin / delete_export_data.py
index abb86db..85cf300 100755 (executable)
@@ -27,10 +27,9 @@ try:
     import karesansui
     from karesansui import __version__
     from karesansui.lib.virt.virt import KaresansuiVirtConnection, KaresansuiVirtException
-    from karesansui.lib.utils import load_locale
+    from karesansui.lib.utils import load_locale, is_uuid
     from karesansui.lib.virt.config_export import ExportConfigParam
     from karesansui.lib.virt.config import ConfigParam
-    from karesansui.lib.utils import is_uuid
 except ImportError:
     print >>sys.stderr, "[Error] karesansui package was not found."
     sys.exit(1)
@@ -46,7 +45,10 @@ def getopts():
     return optp.parse_args()
 
 def chkopts(opts):
-    if not opts.uuid:
+    if opts.uuid:
+        if not is_uuid(opts.uuid):
+            raise KssCommandOptException('ERROR: Illigal UUID. uuid=%s' % (opts.uuid))
+    else:
         raise KssCommandOptException('ERROR: -u or --uuid option is required.')
 
 class DeleteExportData(KssCommand):
@@ -54,7 +56,7 @@ class DeleteExportData(KssCommand):
     def process(self):
         (opts, args) = getopts()
         chkopts(opts)
-        self.up_progress(1)
+        self.up_progress(10)
 
         kvc = KaresansuiVirtConnection()
         # #1 libvirt process
@@ -64,7 +66,7 @@ class DeleteExportData(KssCommand):
             active_pool = kvc.list_active_storage_pool()
             pools = inactive_pool + active_pool
             pools.sort()
-            
+
             export = []
             for pool_name in pools:
                 pool = kvc.search_kvn_storage_pools(pool_name)
@@ -88,7 +90,7 @@ class DeleteExportData(KssCommand):
                                 'Export corrupt data.(file not found) - path=%s' % path)
 
                         param.load_xml_config(path)
-                        
+
                         if e_name != param.get_domain_name():
                             raise KssCommandException(
                                 'Export corrupt data.(The name does not match) - info=%s, xml=%s' \
@@ -116,6 +118,7 @@ class DeleteExportData(KssCommand):
         finally:
             kvc.close()
 
+        self.up_progress(30)
         # #2 physical process
         if os.path.isdir(export['dir']) is False:
             raise KssCommandException(_("Failed to delete export data. - %s") % (_("Export data directory not found. [%s]") % (export['dir'])))
@@ -131,6 +134,7 @@ class DeleteExportData(KssCommand):
         for _afile in glob.glob("%s*img" % (export['dir'])):
             os.remove(_afile)
 
+        self.up_progress(30)
         # refresh pool.
         conn = KaresansuiVirtConnection(readonly=False)
         try:
@@ -141,6 +145,8 @@ class DeleteExportData(KssCommand):
         except:
             pass
 
+        self.logger.info('Deleted export data. - uuid=%s' % (opts.uuid))
+        print >>sys.stderr, _('Deleted export data. - uuid=%s') % (opts.uuid)
         return True
 
 if __name__ == "__main__":