Class: Bosh::Clouds::Dummy

Inherits:
Object show all
Defined in:
lib/cloud/dummy.rb

Defined Under Namespace

Classes: NotImplemented

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Dummy

Returns a new instance of Dummy.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cloud/dummy.rb', line 12

def initialize(options)
  if options["dir"].nil?
    raise ArgumentError, "please provide base directory for dummy cloud"
  end

  @options = options
  @base_dir = options["dir"]
  FileUtils.mkdir_p(@base_dir)
rescue Errno::EACCES
  raise ArgumentError, "cannot create dummy cloud base directory #{@base_dir}"
end

Instance Method Details

#attach_disk(vm_id, disk_id) ⇒ Object



88
89
90
91
92
# File 'lib/cloud/dummy.rb', line 88

def attach_disk(vm_id, disk_id)
  file = attachment_file(vm_id, disk_id)
  FileUtils.mkdir_p(File.dirname(file))
  FileUtils.touch(file)
end

#blobstore_uriObject



34
35
36
37
38
39
40
# File 'lib/cloud/dummy.rb', line 34

def blobstore_uri
  properties = @options['agent']['blobstore']['options']
  uri = URI(properties['endpoint'])
  uri.user = properties['user']
  uri.password = properties['password']
  uri.to_s
end

#configure_networks(vm, networks) ⇒ Object

Raises:



84
85
86
# File 'lib/cloud/dummy.rb', line 84

def configure_networks(vm, networks)
  raise NotImplemented, "configure_networks"
end

#create_disk(size, vm_locality = nil) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/cloud/dummy.rb', line 98

def create_disk(size, vm_locality = nil)
  disk_id = SecureRandom.hex
  file = disk_file(disk_id)
  FileUtils.mkdir_p(File.dirname(file))
  File.write(file, size.to_s)
  disk_id
end

#create_stemcell(image, _) ⇒ Object



24
25
26
27
28
# File 'lib/cloud/dummy.rb', line 24

def create_stemcell(image, _)
  stemcell_id = Digest::SHA1.hexdigest(File.read(image))
  File.write(stemcell_file(stemcell_id), image)
  stemcell_id
end

#create_vm(agent_id, stemcell, resource_pool, networks, disk_locality = nil, env = nil) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cloud/dummy.rb', line 46

def create_vm(agent_id, stemcell, resource_pool, networks, disk_locality = nil, env = nil)
  agent_base_dir = "#{@options['dir']}/agent-base-dir-#{agent_id}"

  root_dir = File.join(agent_base_dir, 'root_dir')
  FileUtils.mkdir_p(File.join(root_dir, 'etc', 'logrotate.d'))

  # FIXME: if there is a need to start this dummy cloud agent with alerts turned on
  # then port should be overriden for each agent, otherwise all but first won't start
  # (won't be able to bind to port)
  agent_cmd = %W[bosh_agent -a #{agent_id} -s #{blobstore_uri} -p simple -b #{agent_base_dir} -n #{nats_uri} -r #{root_dir} --no-alerts]
  agent_log = "#{@options['dir']}/agent.#{agent_id}.log"
  agent_pid = Process.spawn(*agent_cmd, chdir: agent_base_dir, out: agent_log, err: agent_log)

  Process.detach(agent_pid)

  FileUtils.mkdir_p(File.join(@base_dir, "running_vms"))
  FileUtils.touch(vm_file(agent_pid))

  agent_pid.to_s
end

#delete_disk(disk_id) ⇒ Object



106
107
108
# File 'lib/cloud/dummy.rb', line 106

def delete_disk(disk_id)
  FileUtils.rm(disk_file(disk_id))
end

#delete_snapshot(snapshot_id) ⇒ Object



118
119
120
# File 'lib/cloud/dummy.rb', line 118

def delete_snapshot(snapshot_id)
  FileUtils.rm(snapshot_file(snapshot_id))
end

#delete_stemcell(stemcell_cid) ⇒ Object



30
31
32
# File 'lib/cloud/dummy.rb', line 30

def delete_stemcell(stemcell_cid)
  FileUtils.rm(stemcell_file(stemcell_cid))
end

#delete_vm(vm_name) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/cloud/dummy.rb', line 67

def delete_vm(vm_name)
  agent_pid = vm_name.to_i
  Process.kill("INT", agent_pid)
rescue Errno::ESRCH
  # don't care :)
ensure
  FileUtils.rm_rf(File.join(@base_dir, "running_vms", vm_name))
end

#detach_disk(vm_id, disk_id) ⇒ Object



94
95
96
# File 'lib/cloud/dummy.rb', line 94

def detach_disk(vm_id, disk_id)
  FileUtils.rm(attachment_file(vm_id, disk_id))
end

#has_vm?(vm_id) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/cloud/dummy.rb', line 80

def has_vm?(vm_id)
  File.exists?(vm_file(vm_id))
end

#nats_uriObject



42
43
44
# File 'lib/cloud/dummy.rb', line 42

def nats_uri
  @options['nats']
end

#reboot_vm(vm) ⇒ Object

Raises:



76
77
78
# File 'lib/cloud/dummy.rb', line 76

def reboot_vm(vm)
  raise NotImplemented, "reboot_vm"
end

#snapshot_disk(_, metadata) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/cloud/dummy.rb', line 110

def snapshot_disk(_, )
  snapshot_id = SecureRandom.hex
  file = snapshot_file(snapshot_id)
  FileUtils.mkdir_p(File.dirname(file))
  File.write(file, .to_json)
  snapshot_id
end

#validate_deployment(old_manifest, new_manifest) ⇒ Object

Raises:



122
123
124
# File 'lib/cloud/dummy.rb', line 122

def validate_deployment(old_manifest, new_manifest)
  raise NotImplemented, "validate_deployment"
end