Class: GlusterFS::Volume

Inherits:
Object
  • Object
show all
Defined in:
lib/glusterfs/volume.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Volume

Returns a new instance of Volume.



4
5
6
7
8
# File 'lib/glusterfs/volume.rb', line 4

def initialize(name)
  @name = name
  @fs = GlusterFS.new(@name)
  self
end

Instance Attribute Details

#fsObject (readonly)

Returns the value of attribute fs.



2
3
4
# File 'lib/glusterfs/volume.rb', line 2

def fs
  @fs
end

#hostObject (readonly)

Returns the value of attribute host.



2
3
4
# File 'lib/glusterfs/volume.rb', line 2

def host
  @host
end

#mountedObject (readonly)

Returns the value of attribute mounted.



2
3
4
# File 'lib/glusterfs/volume.rb', line 2

def mounted
  @mounted
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/glusterfs/volume.rb', line 2

def name
  @name
end

#portObject (readonly)

Returns the value of attribute port.



2
3
4
# File 'lib/glusterfs/volume.rb', line 2

def port
  @port
end

#protocolObject (readonly)

Returns the value of attribute protocol.



2
3
4
# File 'lib/glusterfs/volume.rb', line 2

def protocol
  @protocol
end

Instance Method Details

#delete_dir(path) ⇒ Object



39
40
41
42
# File 'lib/glusterfs/volume.rb', line 39

def delete_dir(path)
  check_mounted
  GlusterFS.rmdir(@fs, path)
end

#delete_file(path) ⇒ Object



34
35
36
37
# File 'lib/glusterfs/volume.rb', line 34

def delete_file(path)
  check_mounted
  GlusterFS.unlink(@fs, path)
end

#list(path) ⇒ Object



29
30
31
32
# File 'lib/glusterfs/volume.rb', line 29

def list(path)
  dir = Directory.new(volume, path)
  dir.list
end

#lstat(path) ⇒ Object



22
23
24
25
26
27
# File 'lib/glusterfs/volume.rb', line 22

def lstat(path)
  check_mounted
  data = GlusterFS::Stat.new
  GlusterFS.lstat(@fs, path, data)
  data
end

#mount(host, port = 24007, protocol = 'tcp') ⇒ Object

Raises:



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/glusterfs/volume.rb', line 10

def mount(host, port = 24007, protocol = 'tcp')
  raise GlusterFS::Error, "Already mounted: #{self}" if mounted?
  GlusterFS.set_volfile_server(@fs, protocol, host, port)
  result = GlusterFS.init(@fs)
  raise GlusterFS::Error, "Failed to mount volume #{self}" if result != 0
  @mounted = true
  @host = host
  @protocol = protocol
  @port = port
  self
end

#mounted?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/glusterfs/volume.rb', line 44

def mounted?
  @mounted
end

#unmountObject



48
49
50
51
52
53
54
# File 'lib/glusterfs/volume.rb', line 48

def unmount
  if mounted?
    GlusterFS.fini(@fs)
    @mounted = false
    true
  end
end