OSDN Git Service

Synchronize "STOP" & "DELETE" method for network storage and storage pool
authorkeisuke fukawa <keisuke@karesansui-project.info>
Mon, 5 Jul 2010 02:58:22 +0000 (11:58 +0900)
committerkeisuke fukawa <keisuke@karesansui-project.info>
Mon, 5 Jul 2010 02:58:22 +0000 (11:58 +0900)
karesansui/gadget/hostby1networkstorageby1.py
karesansui/gadget/hostby1networkstorageby1status.py
karesansui/lib/const.py
karesansui/templates/default/hostby1networkstorage/hostby1networkstorage.part

index 54f5322..7887e0f 100644 (file)
@@ -25,6 +25,7 @@ from karesansui.db.access.machine2jobgroup import new as m2j_new
 
 from pysilhouette.command import dict2command
 
+from karesansui.lib.virt.virt import KaresansuiVirtConnection
 from karesansui.lib.utils import is_param, generate_phrase, create_file, \
     get_filelist, symlink2real
 from karesansui.lib.const import ISCSI_COMMAND_GET, ISCSI_COMMAND_UPDATE, \
@@ -32,7 +33,8 @@ from karesansui.lib.const import ISCSI_COMMAND_GET, ISCSI_COMMAND_UPDATE, \
     PORT_MIN_NUMBER,          PORT_MAX_NUMBER, \
     CHAP_USER_MIN_LENGTH,     CHAP_USER_MAX_LENGTH, \
     CHAP_PASSWORD_MIN_LENGTH, CHAP_PASSWORD_MAX_LENGTH, \
-    ISCSI_DEVICE_DIR,         ISCSI_DEVICE_NAME_TPL
+    ISCSI_DEVICE_DIR,         ISCSI_DEVICE_NAME_TPL, \
+    VIRT_COMMAND_DESTROY_STORAGE_POOL, VIRT_COMMAND_DELETE_STORAGE_POOL
 
 from karesansui.lib.checker import Checker, CHECK_EMPTY, CHECK_VALID, CHECK_LENGTH, \
     CHECK_MIN, CHECK_MAX
@@ -243,15 +245,68 @@ class HostBy1NetworkStorageBy1(Rest):
 
         host = findbyhost1(self.orm, host_id)
 
-        iqn = self.input.iqn
+        if is_param(self.input, "iqn"):
+            iqn = self.input.iqn
+        else:
+            return web.badrequest()
+
         options = {'iqn' : iqn}
+        job_order = 0
+        cmd_name = u'Delete iSCSI'
+        jobgroup = JobGroup(cmd_name, karesansui.sheconf['env.uniqkey'])
+
+        if is_param(self.input, "host") and is_param(self.input, "port"):
+            host = self.input.host
+            port = self.input.port
+            used_pool = []
+            active_used_pool = []
+
+            kvc = KaresansuiVirtConnection()
+            try:
+                dev_symlink_list = get_filelist(ISCSI_DEVICE_DIR)
+                dev_symlink_list.sort()
+                symlink_regexp = re.compile("^%s/%s" % (re.escape(ISCSI_DEVICE_DIR), re.escape(ISCSI_DEVICE_NAME_TPL % (host, port, iqn))))
+
+                pools = kvc.list_active_storage_pool() + kvc.list_inactive_storage_pool()
+                for pool in pools:
+                    pool_type = kvc.get_storage_pool_type(pool)
+                    if pool_type == "iscsi":
+                        if iqn == kvc.get_storage_pool_sourcedevicepath(pool):
+                            used_pool.append(pool)
+                            pool_objs = kvc.search_kvn_storage_pools(pool)
+                            if pool_objs[0].is_active():
+                                active_used_pool.append(pool)
+
+                    elif pool_type == "fs":
+                        if symlink_regexp.match(kvc.get_storage_pool_sourcedevicepath(pool)):
+                            used_pool.append(pool)
+                            pool_objs = kvc.search_kvn_storage_pools(pool)
+                            if pool_objs[0].is_active():
+                                active_used_pool.append(pool)
+
+            finally:
+                kvc.close()
+
+            for pool in active_used_pool:
+                stop_pool_cmd = dict2command(
+                    "%s/%s" % (karesansui.config['application.bin.dir'], VIRT_COMMAND_DESTROY_STORAGE_POOL),
+                    {"name" : pool})
+                stop_pool_cmdname = "Stop Storage Pool"
+                jobgroup.jobs.append(Job('%s command' % stop_pool_cmdname, 0, stop_pool_cmd))
+                job_order = 1
+
+            for pool in used_pool:
+                delete_pool_cmd = dict2command(
+                    "%s/%s" % (karesansui.config['application.bin.dir'], VIRT_COMMAND_DELETE_STORAGE_POOL),
+                    {"name" : pool})
+                delete_pool_cmdname = "Delete Storage Pool"
+                jobgroup.jobs.append(Job('%s command' % delete_pool_cmdname, job_order, delete_pool_cmd))
+                job_order = 2
 
         _cmd = dict2command(
             "%s/%s" % (karesansui.config['application.bin.dir'], ISCSI_COMMAND_DELETE), options)
 
-        cmd_name = u'Delete iSCSI'
-        jobgroup = JobGroup(cmd_name, karesansui.sheconf['env.uniqkey'])
-        jobgroup.jobs.append(Job('%s command' % cmd_name, 0, _cmd))
+        jobgroup.jobs.append(Job('%s command' % cmd_name, job_order, _cmd))
 
         host = findbyhost1(self.orm, host_id)
         _machine2jobgroup = m2j_new(machine=host,
index 1b348c3..b2e3b9f 100644 (file)
@@ -11,6 +11,7 @@
 #
 
 import web
+import re
 
 import karesansui
 from karesansui.lib.rest import Rest, auth
@@ -23,8 +24,11 @@ from karesansui.db.access.machine2jobgroup import new as m2j_new
 
 from pysilhouette.command import dict2command
 
-from karesansui.lib.utils import is_param
-from karesansui.lib.const import ISCSI_COMMAND_START, ISCSI_COMMAND_STOP
+from karesansui.lib.virt.virt import KaresansuiVirtConnection
+from karesansui.lib.utils import is_param, get_filelist, uniq_sort
+from karesansui.lib.const import ISCSI_COMMAND_START, ISCSI_COMMAND_STOP, \
+    ISCSI_DEVICE_NAME_TPL, ISCSI_DEVICE_DIR, \
+    VIRT_COMMAND_DESTROY_STORAGE_POOL
 
 NETWORK_STORAGE_START = "0"
 NETWORK_STORAGE_STOP = "1"
@@ -37,24 +41,67 @@ class HostBy1NetworkStorageBy1Status(Rest):
 
         host = findbyhost1(self.orm, host_id)
 
-        iqn = self.input.iqn
+        if is_param(self.input, "iqn"):
+            iqn = self.input.iqn
+        else:
+            return web.badrequest()
+
         options = {'iqn' : iqn}
+        job_order = 0
 
-        status = self.input.status
+        if is_param(self.input, "status"):
+            status = self.input.status
+        else:
+            return web.badrequest()
 
         if status == NETWORK_STORAGE_START:
             network_storage_cmd = ISCSI_COMMAND_START
             cmd_name = u'Start iSCSI'
+            jobgroup = JobGroup(cmd_name, karesansui.sheconf['env.uniqkey'])
         elif status == NETWORK_STORAGE_STOP:
             network_storage_cmd = ISCSI_COMMAND_STOP
             cmd_name = u'Stop iSCSI'
+            jobgroup = JobGroup(cmd_name, karesansui.sheconf['env.uniqkey'])
+
+            if is_param(self.input, "host") and is_param(self.input, "port"):
+                host = self.input.host
+                port = self.input.port
+                used_pool = []
+
+                kvc = KaresansuiVirtConnection()
+                try:
+                    dev_symlink_list = get_filelist(ISCSI_DEVICE_DIR)
+                    dev_symlink_list.sort()
+                    symlink_regexp = re.compile("^%s/%s" % (re.escape(ISCSI_DEVICE_DIR), re.escape(ISCSI_DEVICE_NAME_TPL % (host, port, iqn))))
+
+                    active_pool = kvc.list_active_storage_pool()
+                    for pool in active_pool:
+                        pool_type = kvc.get_storage_pool_type(pool)
+                        if pool_type == "iscsi":
+                            if iqn == kvc.get_storage_pool_sourcedevicepath(pool):
+                                used_pool.append(pool)
+                        elif pool_type == "fs":
+                            if symlink_regexp.match(kvc.get_storage_pool_sourcedevicepath(pool)):
+                                used_pool.append(pool)
+
+                finally:
+                    kvc.close()
+
+                for pool in used_pool:
+                    pool_cmd = dict2command(
+                        "%s/%s" % (karesansui.config['application.bin.dir'], VIRT_COMMAND_DESTROY_STORAGE_POOL),
+                        {"name" : pool})
+                    pool_cmdname = "Stop Storage Pool"
+                    jobgroup.jobs.append(Job('%s command' % pool_cmdname, 0, pool_cmd))
+                    job_order = 1
+
         else:
             return web.internalerror('Internal Server Error. (Param)')
 
         _cmd = dict2command(
             "%s/%s" % (karesansui.config['application.bin.dir'], network_storage_cmd), options)
-        jobgroup = JobGroup(cmd_name, karesansui.sheconf['env.uniqkey'])
-        jobgroup.jobs.append(Job('%s command' % cmd_name, 0, _cmd))
+
+        jobgroup.jobs.append(Job('%s command' % cmd_name, job_order, _cmd))
 
         host = findbyhost1(self.orm, host_id)
         _machine2jobgroup = m2j_new(machine=host,
index 91e2f4a..29c9cca 100644 (file)
@@ -497,9 +497,9 @@ KVM_BUS_TYPES = ['ide','scsi','virtio']
 XEN_BUS_TYPES = ['xen']
 
 # use for mount check
-MOUNT_CMD = "mount"
-UMOUNT_CMD = "umount"
-FORMAT_CMD = "mkfs"
+MOUNT_CMD = "/bin/mount"
+UMOUNT_CMD = "/bin/umount"
+FORMAT_CMD = "/sbin/mkfs"
 YES_CMD = ("echo", "y")
 
 # interval of monitoring
index 25f2d1a..f2efe18 100644 (file)
@@ -71,8 +71,11 @@ $(document).ready(function(){
                     show_alert_msg("${_('Please select a target.')}", "ERROR");
                     tool_reset("#delete_network_storage");
                 } else {
-                    var url = uri + "/" + "default" + ".part?iqn=" + target_id;
+                    var host = $("tr[id$='" + target_id + "'] .network_storage_host").text();
+                    var port = $("tr[id$='" + target_id + "'] .network_storage_port").text();
+                    var url = uri + "/" + "default" + ".part?iqn=" + target_id + "&host=" + host + "&port=" + port;
                     var param = null;
+
                     delete_dialog("#network_storage_dialog", url, param, "${ctx.homepath}${ctx.path}", "#delete_network_storage", "");
                 }
             });
@@ -117,9 +120,13 @@ $(document).ready(function(){
                     tool_reset("#stop_network_storage");
                 } else {
                     var url = uri + "/" + "default" + "/" + "status.part?iqn=" + target_id;
+                    var host = $("tr[id$='" + target_id + "'] .network_storage_host").text();
+                    var port = $("tr[id$='" + target_id + "'] .network_storage_port").text();
 
                     ajax_put(url,
-                        {"status" : NETWORK_STORAGE_STOP},
+                        {"status" : NETWORK_STORAGE_STOP,
+                         "host" : host,
+                         "port" : port},
                         function(data, status){},
                         true,
                         "${ctx.homepath}${ctx.path}"
@@ -246,7 +253,8 @@ $(document).ready(function(){
                                                 <th width="30%">${_('Target Host Name')}</th>
                                                 <th width="40%">${_('Target IQN')}</th>
                                                 <th width="10%">${_('Status')}</th>
-                                                <th width="10%">${_('Autostart')}
+                                                <th width="10%">${_('Autostart')}</th>
+                                                <th width="0px" style="display:none;"></th>
                                             </tr>
                                         </thead>
                                         <tbody>
@@ -254,7 +262,7 @@ $(document).ready(function(){
 % for network_storage in network_storages:
                                             <tr id="network_storage_row${network_storage['iqn']}">
                                                 <td>${network_storage['type'] |h}</td>
-                                                <td>${network_storage['hostname']|h}</td>
+                                                <td class="network_storage_host">${network_storage['hostname']|h}</td>
                                                 <td>${network_storage['iqn']|h}</td>
     % if network_storage['activity'] == 1:
                                                 <td>${_('Connecting')}</td>
@@ -266,6 +274,7 @@ $(document).ready(function(){
     % else:
                                                 <td align="center">-</td>
     % endif
+                                                <td class="network_storage_port" style="display:none;">${network_storage['port'] |h}</td>
                                             </tr>
 % endfor
                                         </tbody>