def set_description(self, dbg, sr, key, new_description):
     VHDVolume.set_description(
         dbg,
         sr,
         key,
         new_description,
         gfs2.Callbacks()
     )
    def stat(self, dbg, sr):
        # SR path (sr) is file://<mnt_path>
        # Get mnt_path by dropping url scheme
        uri = urlparse.urlparse(sr)
        mnt_path = "/%s/%s" % (uri.netloc, uri.path)

        if not(os.path.isdir(mnt_path)) or not(os.path.ismount(mnt_path)):
            raise xapi.storage.api.volume.Sr_not_attached(mnt_path)

        # Get the filesystem size
        statvfs = os.statvfs(mnt_path)
        psize = statvfs.f_blocks * statvfs.f_frsize
        fsize = statvfs.f_bfree * statvfs.f_frsize
        log.debug("%s: statvfs says psize = %Ld" % (dbg, psize))

        overprovision = \
             VHDVolume.get_sr_provisioned_size(sr, gfs2.Callbacks()) / psize

        return {
            "sr": sr,
            "name": "SR Name",
            "description": "GFS2 SR",
            "total_space": psize,
            "free_space": fsize,
            "overprovision": overprovision,
            "datasources": [],
            "clustered": True,
            "health": ["Healthy", ""]
        }
 def resize(self, dbg, sr, key, new_size):
     return VHDVolume.resize(
         dbg,
         sr,
         key,
         new_size,
         gfs2.Callbacks()
     )
 def create(self, dbg, sr, name, description, size):
     return VHDVolume.create(
         dbg,
         sr,
         name,
         description,
         size,
         gfs2.Callbacks()
     )
 def set(self, dbg, sr, key, k, v):
     VHDVolume.set(key, k, v, gfs2BaseCallbacks)
     return None
 def resize(self, dbg, sr, key, new_size):
     return VHDVolume.destroy(dbg, sr, key, new_size, gfs2BaseCallbacks)
 def destroy(self, dbg, sr, key):
     return VHDVolume.destroy(dbg, sr, key, gfs2BaseCallbacks)
 def snapshot(self, dbg, sr, key):
     return VHDVolume.snapshot(dbg, sr, key, gfs2BaseCallbacks)
 def clone(self, dbg, sr, key):
     return VHDVolume.clone(dbg, sr, key, gfs2BaseCallbacks)
 def set_name(self, dbg, sr, key, new_name):
     VHDVolume.set_name(key, new_name, gfs2BaseCallbacks)
     return None
                    call(dbg, ["gfs2_grow", mountpoint_root + "dev/" + vg_name +"/gfs2"])

                except Exception, e:
                    raise e

                finally:
                    if f:
                        util.unlock_file(dbg,f)
            else:
                log.debug("No free space detected in VG")

        except Exception, e:
                log.debug("Exception in SR.ls: %s" %str(e))

        finally:
            return VHDVolume.ls(dbg, sr, gfs2.Callbacks())

    def stat(self, dbg, sr):
        # SR path (sr) is file://<mnt_path>
        # Get mnt_path by dropping url scheme
        uri = urlparse.urlparse(sr)
        mnt_path = "/%s/%s" % (uri.netloc, uri.path)

        if not(os.path.isdir(mnt_path)) or not(os.path.ismount(mnt_path)):
            raise xapi.storage.api.volume.Sr_not_attached(mnt_path)

        # Get the filesystem size
        statvfs = os.statvfs(mnt_path)
        psize = statvfs.f_blocks * statvfs.f_frsize
        fsize = statvfs.f_bfree * statvfs.f_frsize
        log.debug("%s: statvfs says psize = %Ld" % (dbg, psize))
 def stat(self, dbg, sr, key):
     return VHDVolume.stat(dbg, sr, key, gfs2.Callbacks())
 def set_name(self, dbg, sr, key, new_name):
     VHDVolume.set_name(dbg, sr, key, new_name, gfs2.Callbacks())
 def unset(self, dbg, sr, key, k):
     VHDVolume.unset(dbg, sr, key, k, gfs2.Callbacks())
 def set(self, dbg, sr, key, k, v):
     VHDVolume.set(dbg, sr, key, k, v, gfs2.Callbacks())
 def unset(self, dbg, sr, key, k):
     VHDVolume.unset(key, k, gfs2BaseCallbacks)
     return None
 def set_description(self, dbg, sr, key, new_description):
     VHDVolume.set_description(key, new_description, gfs2BaseCallbacks)
     return None
    def create(self, dbg, uri, name, description, configuration):
        log.debug("%s: SR.create: uri=%s, config=%s" % (dbg, uri, configuration))

        cmd = ["/usr/sbin/corosync-cmapctl", "totem.cluster_name"]
        out = call(dbg, cmd).rstrip()
        # Cluster id is quite limited in size
        cluster_name = out.split("=")[1][1:9]

        # Generate a UUID for the filesystem name
        # According to mkfs.gfs2 manpage, SR name can only be 1--16 chars in length
        sr_name = str(uuid.uuid4())[0:16]
        fsname = "%s:%s" % (cluster_name, sr_name)

        # Zone-in the LUN
        dev_path = plug_device(dbg, uri)
        log.debug("%s: dev_path = %s" % (dbg, dev_path))

        cmd = ["/usr/bin/dd", "if=/dev/zero", "of=%s" % dev_path, "bs=1M",
               "count=10", "oflag=direct"]
        call(dbg, cmd)

        unique_id = get_unique_id_from_dev_path(dev_path)

        # create the VG on the LUN
        cmd = ["/usr/sbin/vgcreate", "-f", unique_id, dev_path, "--config", "global{metadata_read_only=0}"]
        call(dbg, cmd)

        # create the sbd LV
        cmd = ["/usr/sbin/lvcreate", "-L", "16M", "-n", "sbd", unique_id, "--config", "global{metadata_read_only=0}"]
        call(dbg, cmd)

        # activate sbd LV
        cmd = ["/usr/sbin/lvchange", "-ay", unique_id + "/sbd"]
        call(dbg, cmd)

        # deactivate sbd LV
        cmd = ["/usr/sbin/lvchange", "-an", unique_id + "/sbd"]
        call(dbg, cmd)

        # create the gfs2 LV
        cmd = ["/usr/sbin/lvcreate", "-l", "100%FREE", "-n", "gfs2", unique_id, "--config", "global{metadata_read_only=0}"]
        call(dbg, cmd)

        # activate gfs2 LV
        cmd = ["/usr/sbin/lvchange", "-ay", unique_id + "/gfs2"]
        call(dbg, cmd)

        gfs2_dev_path = "/dev/" + unique_id + "/gfs2"

        # Make the filesystem
        cmd = ["/usr/sbin/mkfs.gfs2",
               "-t", fsname,
               "-p", "lock_dlm",
               "-r", "2048",
               "-J", "128",
               "-O",
               "-j", "16",
               gfs2_dev_path]
        call(dbg, cmd)

        # Temporarily mount the filesystem so we can write the SR metadata
        mnt_path = mount_local(dbg, gfs2_dev_path)

        # Create the metadata database
        VHDVolume.create_metabase(mnt_path + "/sqlite3-metadata.db")

        read_caching = True
        if 'read_caching' in configuration:
            if configuration['read_caching'] not in ['true', 't', 'on', '1', 'yes']:
                read_caching = False

        meta = {
            "name": name,
            "description": description,
            "uri": uri,
            "unique_id": unique_id,
            "fsname": fsname,
            "read_caching": read_caching,
            "keys": {}
        }
        metapath = mnt_path + "/meta.json"
        log.debug("%s: dumping metadata to %s: %s" % (dbg, metapath, meta))

        with open(metapath, "w") as json_fp:
            json.dump(meta, json_fp)
            json_fp.write("\n")

        umount(dbg, mnt_path)

        # deactivate gfs2 LV
        cmd = ["/usr/sbin/lvchange", "-an", unique_id + "/gfs2"]
        call(dbg, cmd)

        unplug_device(dbg, uri)
        return
 def stat(self, dbg, sr, key):
     return VHDVolume.stat(key, gfs2BaseCallbacks)
 def snapshot(self, dbg, sr, key):
     return VHDVolume.clone(dbg, sr, key, gfs2.Callbacks())