Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update BOSH plugin

- rvc 1.7.0 support

- Micro BOSH support

- bosh-release support (drops chef_deployer support)

- rvc launcher
  • Loading branch information...
commit abf591b757721761e2039adcb23031fe49883f08 1 parent af57b50
@dougm authored
Showing with 79 additions and 19 deletions.
  1. +28 −0 home/.rvc/README.md
  2. +51 −19 home/.rvc/bosh.rb
View
28 home/.rvc/README.md
@@ -0,0 +1,28 @@
+# RVC plugins
+
+Plugins for [Ruby vSphere Client](https://github.com/vmware/rvc)
+
+## bosh.vcenter
+
+Connect to vCenter instances by [BOSH](https://github.com/cloudfoundry/bosh) deployment name.
+
+This plugin command uses vCenter properties from both BOSH and Micro BOSH
+[deployment manifests](https://github.com/cloudfoundry/oss-docs/tree/master/bosh)
+to connect to vCenter via RVC. The bosh.vcenter command will connect to vCenter
+and cd to datacenter/cluster/pool/vms.
+
+Example:
+
+ > bosh.vcenter dev179
+ /cf-dev179.x.x.x/LAS01/computers/CLUSTER14/resourcePool/pools/Dev179/vms> ls
+ 0 sc-dff4843d-9077-47f5-bab7-6d94c1b9d657: poweredOff
+ ...
+ 8 vm-4ec48ee1-acb8-4997-a857-e8d9c33786c8: poweredOn
+ 9 vm-dac12047-094b-486c-b61e-ee10a1e1d453: poweredOn
+ 10 vm-3c3e9be8-34a8-497c-a812-dac0c6f77988: poweredOn
+ ...
+
+The plugin can also be used to start RVC itself with vCenter connection using a
+BOSH deployment name. Example:
+
+ $ ruby ~/.rvc/bosh.rb dev179
View
70 home/.rvc/bosh.rb
@@ -1,28 +1,60 @@
+require "yaml"
require "resolv"
-opts :vcenter do
- summary "Connect to bosh vCenter"
- arg :name, "bosh instance name"
-end
+def vcenter_config name
+ deployments = ENV["CF_DEPLOYMENTS"] || "#{ENV["HOME"]}/cf/deployments"
-def vcenter name
- deployments = ENV['CF_DEPLOYMENTS'] || "#{ENV['HOME']}/cf/deployments"
- yml = ["micro_bosh.yml", "cloud/assets/director/director.yml.erb"].map {|f|
+ yml = ["bosh.yml", "micro_bosh.yml"].map {|f|
File.join(deployments, name, f)
}.select {|path| File.exists?(path)}.first
- config = YAML.load(File.read(yml))['cloud']['properties']['vcenters'].first
- begin
- host = Resolv.new.getname(config['host'])
- rescue
- host = config['host']
+
+ config = YAML.load(File.read(yml))
+
+ if File.basename(yml) == "bosh.yml"
+ config = config["properties"]["vcenter"]
+ else
+ config = config["cloud"]["properties"]["vcenters"].first
end
- dc = config['datacenters'].first
+
+ ENV["RBVMOMI_PASSWORD"] = config["password"]
+ ENV["RBVMOMI_USER"] = config["user"]
+
+ config
+end
+
+def vcenter_host config
+ address = config["address"] || config["host"]
+ Resolv.new.getname(address)
+rescue
+ address
+end
+
+def vcenter name
+ config = vcenter_config(name)
+ host = vcenter_host(config)
+
unless $shell.connections[host]
- ENV['RBVMOMI_PASSWORD'] = config['password']
- CMD.vim.connect "#{config['user']}@#{host}", {}
+ $shell.cmds.vim.connect host, {}
+ end
+
+ dc = config["datacenters"].first
+ cluster = dc["clusters"].first
+ cluster_name = cluster.keys.first
+ cluster_path = File.join("", host, dc["name"], "computers", cluster_name)
+ if pool = cluster[cluster_name]["resource_pool"]
+ cluster_path = File.join(cluster_path, "resourcePool", "pools", pool, "vms")
+ end
+
+ $shell.cmds.basic.cd $shell.fs.lookup_single(cluster_path)
+end
+
+if __FILE__ == $0
+ config = vcenter_config(ARGV[0])
+
+ exec "rvc", vcenter_host(config)
+else
+ opts :vcenter do
+ summary "Connect to bosh vCenter"
+ arg :name, "bosh instance name"
end
- cluster_path = File.join("", host, dc['name'], "computers", dc['clusters'].first)
- CMD.basic.cd RVC::Util.lookup_single(cluster_path)
-ensure
- ENV['RBVMOMI_PASSWORD'] = nil
end
Please sign in to comment.
Something went wrong with that request. Please try again.