Class: VSphereCloud::DiskProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud/vsphere/disk_provider.rb

Instance Method Summary collapse

Constructor Details

#initialize(virtual_disk_manager, datacenter, resources, disk_path, client, logger) ⇒ DiskProvider

Returns a new instance of DiskProvider.



6
7
8
9
10
11
12
13
# File 'lib/cloud/vsphere/disk_provider.rb', line 6

def initialize(virtual_disk_manager, datacenter, resources, disk_path, client, logger)
  @virtual_disk_manager = virtual_disk_manager
  @datacenter = datacenter
  @resources = resources
  @disk_path = disk_path
  @client = client
  @logger = logger
end

Instance Method Details

#create(disk_size_in_mb) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/cloud/vsphere/disk_provider.rb', line 15

def create(disk_size_in_mb)
  datastore = find_datastore(disk_size_in_mb)
  disk_cid = "disk-#{SecureRandom.uuid}"
  @logger.debug("Creating disk '#{disk_cid}' in datastore '#{datastore.name}'")

  @client.create_disk(@datacenter, datastore, disk_cid, @disk_path, disk_size_in_mb)
end

#find(disk_cid) ⇒ Object

Raises:

  • (Bosh::Clouds::DiskNotFound)


40
41
42
43
44
45
46
47
# File 'lib/cloud/vsphere/disk_provider.rb', line 40

def find(disk_cid)
  @datacenter.persistent_datastores.each do |_, datastore|
    disk = @client.find_disk(disk_cid, datastore, @disk_path)
    return disk unless disk.nil?
  end

  raise Bosh::Clouds::DiskNotFound, "Could not find disk with id #{disk_cid}"
end

#find_and_move(disk_cid, cluster, datacenter_name, accessible_datastores) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cloud/vsphere/disk_provider.rb', line 23

def find_and_move(disk_cid, cluster, datacenter_name, accessible_datastores)
  disk = find(disk_cid)
  return disk if accessible_datastores.include?(disk.datastore.name)

  destination_datastore =  @resources.pick_persistent_datastore_in_cluster(cluster, disk.size_in_mb)

  unless accessible_datastores.include?(destination_datastore.name)
    raise "Datastore '#{destination_datastore.name}' is not accessible to cluster '#{cluster.name}'"
  end

  destination_path = path(destination_datastore, disk_cid)
  @logger.info("Moving #{disk.path} to #{destination_path}")
  @client.move_disk(datacenter_name, disk.path, datacenter_name, destination_path) #TODO: return the new disk
  @logger.info('Moved disk successfully')
  Resources::Disk.new(disk_cid, disk.size_in_mb, destination_datastore, destination_path)
end