vcloud-cli-utils 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +15 -0
- data/LICENSE +21 -0
- data/README.md +72 -0
- data/Rakefile +14 -0
- data/bin/vcloud-attach-disk +8 -0
- data/bin/vcloud-curl +59 -0
- data/bin/vcloud-curl-example.sh +66 -0
- data/bin/vcloud-delete-disk +8 -0
- data/bin/vcloud-delete-network +8 -0
- data/bin/vcloud-delete-vapp +8 -0
- data/bin/vcloud-detach-disk +8 -0
- data/bin/vcloud-get-entity +8 -0
- data/bin/vcloud-get_vms_attached_to-disk +8 -0
- data/bin/vcloud-make-vapp-template +8 -0
- data/bin/vcloud-start-vapp +8 -0
- data/bin/vcloud-stop-vapp +8 -0
- data/lib/vcloud/cli/utils.rb +16 -0
- data/lib/vcloud/cli/utils/attach_disk.rb +35 -0
- data/lib/vcloud/cli/utils/delete_disk.rb +29 -0
- data/lib/vcloud/cli/utils/delete_network.rb +39 -0
- data/lib/vcloud/cli/utils/delete_vapp.rb +45 -0
- data/lib/vcloud/cli/utils/detach_disk.rb +35 -0
- data/lib/vcloud/cli/utils/get_entity.rb +61 -0
- data/lib/vcloud/cli/utils/get_vms_attached_to_disk.rb +32 -0
- data/lib/vcloud/cli/utils/make_vapp_template.rb +85 -0
- data/lib/vcloud/cli/utils/start_vapp.rb +39 -0
- data/lib/vcloud/cli/utils/stop_vapp.rb +39 -0
- data/lib/vcloud/cli/utils/version.rb +7 -0
- data/vcloud-cli-utils.gemspec +32 -0
- metadata +200 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 84c5b9217176679b341cb302c9334855492961dc
|
4
|
+
data.tar.gz: c137de0353479909bda37f65e3c222c43abc35e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8d400391d4f33f95fb10e77ab64354255444b6d5471f578427e5aabf10a9b43903c7d75be8d1ff253afc97ace4a7f6cd5a0f58cde3a919fa154048867a7db260
|
7
|
+
data.tar.gz: b2d81d529fd2aedb50b01ffc561392c91fd3c969ff40cd02a00cc7a3ddf52e5098cd5973ab2fd290fdac09b812252c22ff8bc7ccc96e31dd942ff9264b94f3f0
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
if ENV['VCLOUD_CORE_DEV_MASTER']
|
6
|
+
gem 'vcloud-core', :git => 'git@github.com:alphagov/vcloud-core.git', :branch => 'master'
|
7
|
+
elsif ENV['VCLOUD_CORE_DEV_LOCAL']
|
8
|
+
gem 'vcloud-core', :path => '../vcloud-core'
|
9
|
+
end
|
10
|
+
|
11
|
+
if ENV['FOG_DEV_MASTER']
|
12
|
+
gem 'fog', :git => 'git@github.com:fog/fog.git', :branch => 'master'
|
13
|
+
elsif ENV['FOG_DEV_LOCAL']
|
14
|
+
gem 'fog', :path => '../fog'
|
15
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Mike Pountney
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
vcloud-cli-utils
|
2
|
+
================
|
3
|
+
|
4
|
+
Simple CLI utils to talk to the vCloud Director API
|
5
|
+
|
6
|
+
These are very hacky utils that I've found handy whilst helping develop
|
7
|
+
a more rich toolchain for GOV.UK:
|
8
|
+
|
9
|
+
* https://github.com/alphagov/vcloud-core
|
10
|
+
* https://github.com/alphagov/vcloud-edge_gateway
|
11
|
+
* https://github.com/alphagov/vcloud-tools
|
12
|
+
* https://github.com/alphagov/vcloud-walker
|
13
|
+
|
14
|
+
... which in turn depend on the vcloud_director provider in Fog:
|
15
|
+
|
16
|
+
* https://github.com/fog/fog
|
17
|
+
|
18
|
+
If you find any of these utilities useful, please let me know, so a sured up
|
19
|
+
version can be created.
|
20
|
+
|
21
|
+
The tools
|
22
|
+
----
|
23
|
+
|
24
|
+
### vcloud-get-entity
|
25
|
+
|
26
|
+
Designed to retrieve a complete entity from vCloud via the Fog request layer. Useful
|
27
|
+
for seeing what is available from the raw requests, as Fog sees it (which can
|
28
|
+
be slightly, or completely, different from the raw XML returned from the API).
|
29
|
+
|
30
|
+
bx vcloud-get-entity {entity} {entity_id}
|
31
|
+
|
32
|
+
{entity} can be 'vm', 'vApp', 'orgVdc', 'edgeGateway', etc. Or alternatively,
|
33
|
+
any fog service request that takes a single ID as a parameter (eg
|
34
|
+
'get_vm_capabilities')
|
35
|
+
|
36
|
+
### vcloud-curl
|
37
|
+
|
38
|
+
Wrapper around curl to use Fog credentials & vcloud-login. Very useful for
|
39
|
+
getting the complete XML response from the API, for comparison against the data
|
40
|
+
returned by the Fog request layer
|
41
|
+
|
42
|
+
### vcloud-delete-vapp
|
43
|
+
|
44
|
+
Deletes a vApp by name or id. --force option stops the vApp first, as vCloud
|
45
|
+
sensibly prevents running vApps from being deleted.
|
46
|
+
|
47
|
+
### vcloud-delete-disk
|
48
|
+
|
49
|
+
Deletes an Independent Disk by ID.
|
50
|
+
|
51
|
+
### vcloud-delete-network
|
52
|
+
|
53
|
+
Deletes an orgVdcNetwork by ID
|
54
|
+
|
55
|
+
### vcloud-attach-disk
|
56
|
+
|
57
|
+
Attaches an independent disk to a stopped or running VM.
|
58
|
+
|
59
|
+
NB: To create a disk, see vcloud-disk_launcher Gem/tool.
|
60
|
+
|
61
|
+
### vcloud-detach-disk
|
62
|
+
|
63
|
+
Detaches an independent disk from a stopped or running VM. NB: this can cause
|
64
|
+
problems within the guest OS - beware!
|
65
|
+
|
66
|
+
### vcloud-start-vapp
|
67
|
+
|
68
|
+
Start a stopped vApp by name or ID.
|
69
|
+
|
70
|
+
### vcloud-stop-vapp
|
71
|
+
|
72
|
+
Stop a started vApp by name or ID.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require 'gem_publisher'
|
3
|
+
|
4
|
+
task :default => [:rubocop]
|
5
|
+
|
6
|
+
task :publish_gem do
|
7
|
+
gem = GemPublisher.publish_if_updated("vcloud-cli-utils.gemspec", :rubygems)
|
8
|
+
puts "Published #{gem}" if gem
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'rubocop/rake_task'
|
12
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
13
|
+
task.options = ['--lint']
|
14
|
+
end
|
data/bin/vcloud-curl
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'pp'
|
6
|
+
require 'vcloud/core'
|
7
|
+
require 'methadone'
|
8
|
+
|
9
|
+
ENV['FOG_MOCK'] && Fog.mock!
|
10
|
+
|
11
|
+
class App
|
12
|
+
|
13
|
+
include Methadone::Main
|
14
|
+
include Methadone::CLILogging
|
15
|
+
|
16
|
+
main do
|
17
|
+
|
18
|
+
fsi = Vcloud::Fog::ServiceInterface.new()
|
19
|
+
token = fsi.vcloud_token
|
20
|
+
end_point = fsi.end_point
|
21
|
+
|
22
|
+
rel_url = ARGV.shift
|
23
|
+
url = end_point + rel_url
|
24
|
+
|
25
|
+
system("/usr/bin/curl #{options[:curl_base_opts]} \
|
26
|
+
-H 'Accept:#{options[:content_type]}' \
|
27
|
+
-H 'x-vcloud-authorization: #{token}' \
|
28
|
+
#{ARGV.join(' ')} #{url}")
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
options[:content_type] = "application/*+xml;version=5.1"
|
33
|
+
options[:curl_base_opts] = '-s'
|
34
|
+
|
35
|
+
on("--content_type", "=ATTRIBUTE",
|
36
|
+
"Override default content_type (#{options[:content_type]})" ) do |v|
|
37
|
+
options[:content_type] = v
|
38
|
+
end
|
39
|
+
|
40
|
+
on("--curl_base_opts", "=ATTRIBUTE",
|
41
|
+
"Override base curl options (#{options[:curl_base_opts]})" ) do |v|
|
42
|
+
options[:curl_base_opts] = v
|
43
|
+
end
|
44
|
+
|
45
|
+
on("--verbose", "Verbose output")
|
46
|
+
on("--debug", "Debugging output")
|
47
|
+
|
48
|
+
arg :relative_url, :optional
|
49
|
+
|
50
|
+
description '
|
51
|
+
vcloud-curl takes a relative URL for a query (to the base api url), then
|
52
|
+
shells out to cURL with the remainder of ARGV
|
53
|
+
|
54
|
+
See https://github.com/alphagov/vcloud-tools for more info'
|
55
|
+
|
56
|
+
go!
|
57
|
+
end
|
58
|
+
|
59
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
# This is an illustrative (functional) example of how to use just curl
|
4
|
+
# to talk to the vCloud API.
|
5
|
+
#
|
6
|
+
# The rest of the tools in vcloud-tools use Fog and hence have a unified
|
7
|
+
# credential/session handling system - and should as a result be used instead
|
8
|
+
# of this example.
|
9
|
+
#
|
10
|
+
|
11
|
+
usage() {
|
12
|
+
echo "vcloud-curl: simple curl wrapper to allow GET requests to vcloud API"
|
13
|
+
echo
|
14
|
+
echo "Usage:"
|
15
|
+
echo " vcloud-curl-example.sh {request}"
|
16
|
+
echo
|
17
|
+
echo "where {request} is the resource required after the /api end point"
|
18
|
+
echo "eg: vcloud-curl-example.sh vApp/{vm-id}/virtualHardwareSection/cpu"
|
19
|
+
echo
|
20
|
+
echo "You must set in environment:"
|
21
|
+
echo " VCLOUD_HOST"
|
22
|
+
echo " VCLOUD_ORG"
|
23
|
+
echo " VCLOUD_USER"
|
24
|
+
echo " VCLOUD_PASS"
|
25
|
+
exit 1
|
26
|
+
}
|
27
|
+
|
28
|
+
[ -z "$VCLOUD_HOST" ] && usage
|
29
|
+
[ -z "$VCLOUD_ORG" ] && usage
|
30
|
+
[ -z "$VCLOUD_USER" ] && usage
|
31
|
+
[ -z "$VCLOUD_PASS" ] && usage
|
32
|
+
|
33
|
+
CURL_OPTS=${CURL_OPTS-'--silent'}
|
34
|
+
MAIN_QUERY_CURL_OPTS=${MAIN_QUERY_CURL_OPTS-''}
|
35
|
+
|
36
|
+
api_version=${VCLOUD_API_VERSION-'5.1'}
|
37
|
+
|
38
|
+
MAIN_QUERY_CONTENT_TYPE=${MAIN_QUERY_CONTENT_TYPE-"application/*+xml;version=${api_version}"}
|
39
|
+
|
40
|
+
SESSION_KEY=`curl --include $CURL_OPTS \
|
41
|
+
-H "Accept:application/*+xml;version=${api_version}" \
|
42
|
+
-u "${VCLOUD_USER}@${VCLOUD_ORG}:${VCLOUD_PASS}" \
|
43
|
+
-X POST \
|
44
|
+
"https://${VCLOUD_HOST}/api/sessions" \
|
45
|
+
| grep '^x-vcloud-authorization:' \
|
46
|
+
| tr -d '\r' \
|
47
|
+
| awk '{print $2}'
|
48
|
+
`
|
49
|
+
|
50
|
+
if [ -z "${SESSION_KEY}" ]; then
|
51
|
+
echo "Failed to get vCloud session. Bailing"
|
52
|
+
exit 2
|
53
|
+
fi
|
54
|
+
|
55
|
+
curl $CURL_OPTS $MAIN_QUERY_CURL_OPTS \
|
56
|
+
-H "Accept:${MAIN_QUERY_CONTENT_TYPE}" \
|
57
|
+
-H "x-vcloud-authorization: ${SESSION_KEY}" \
|
58
|
+
"https://${VCLOUD_HOST}/api/$1"
|
59
|
+
|
60
|
+
# Log out
|
61
|
+
curl $CURL_OPTS \
|
62
|
+
-H "Accept:application/*+xml;version=${api_version}" \
|
63
|
+
-H "x-vcloud-authorization: ${SESSION_KEY}" \
|
64
|
+
-X DELETE \
|
65
|
+
"https://${VCLOUD_HOST}/api/session"
|
66
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
require 'methadone'
|
3
|
+
require 'fog'
|
4
|
+
require 'vcloud/core'
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
require 'vcloud/cli/utils/get_entity'
|
8
|
+
require 'vcloud/cli/utils/stop_vapp'
|
9
|
+
require 'vcloud/cli/utils/start_vapp'
|
10
|
+
require 'vcloud/cli/utils/delete_vapp'
|
11
|
+
require 'vcloud/cli/utils/delete_network'
|
12
|
+
require 'vcloud/cli/utils/make_vapp_template'
|
13
|
+
require 'vcloud/cli/utils/attach_disk'
|
14
|
+
require 'vcloud/cli/utils/detach_disk'
|
15
|
+
require 'vcloud/cli/utils/delete_disk'
|
16
|
+
require 'vcloud/cli/utils/get_vms_attached_to_disk'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'methadone'
|
2
|
+
require 'vcloud/core'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
module Vcloud
|
6
|
+
module CLI
|
7
|
+
module Utils
|
8
|
+
class AttachDisk
|
9
|
+
|
10
|
+
include Methadone::Main
|
11
|
+
include Methadone::CLILogging
|
12
|
+
|
13
|
+
def self.run
|
14
|
+
|
15
|
+
main do |vm_id, disk_id|
|
16
|
+
vcloud = ::Fog::Compute::VcloudDirector.new
|
17
|
+
Fog.mock! if ENV['FOG_MOCK']
|
18
|
+
task = vcloud.post_attach_disk(vm_id, disk_id).body
|
19
|
+
vcloud.process_task(task)
|
20
|
+
end
|
21
|
+
|
22
|
+
arg :vm_id
|
23
|
+
arg :disk_id
|
24
|
+
|
25
|
+
description "
|
26
|
+
"
|
27
|
+
|
28
|
+
go!
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Vcloud
|
2
|
+
module CLI
|
3
|
+
module Utils
|
4
|
+
class DeleteDisk
|
5
|
+
|
6
|
+
include Methadone::Main
|
7
|
+
include Methadone::CLILogging
|
8
|
+
|
9
|
+
def self.run
|
10
|
+
|
11
|
+
main do |disk_id|
|
12
|
+
Fog.mock! if ENV['FOG_MOCK']
|
13
|
+
disk = Vcloud::Core::IndependentDisk.new(disk_id)
|
14
|
+
disk.destroy
|
15
|
+
end
|
16
|
+
|
17
|
+
arg :disk_id
|
18
|
+
|
19
|
+
description "
|
20
|
+
"
|
21
|
+
|
22
|
+
go!
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'methadone'
|
2
|
+
require 'vcloud/core'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
module Vcloud
|
6
|
+
module CLI
|
7
|
+
module Utils
|
8
|
+
class DeleteNetwork
|
9
|
+
|
10
|
+
include Methadone::Main
|
11
|
+
include Methadone::CLILogging
|
12
|
+
|
13
|
+
def self.run
|
14
|
+
|
15
|
+
main do |identifier|
|
16
|
+
vcloud = ::Fog::Compute::VcloudDirector.new
|
17
|
+
if identifier =~ /^[-0-9a-f]+/
|
18
|
+
net = Vcloud::Core::OrgVdcNetwork.new(identifier)
|
19
|
+
end
|
20
|
+
Fog.mock! if ENV['FOG_MOCK']
|
21
|
+
task = vcloud.delete_network(net.id).body
|
22
|
+
vcloud.process_task(task)
|
23
|
+
end
|
24
|
+
|
25
|
+
arg :identifier
|
26
|
+
|
27
|
+
on("-f", "--force", "Force deletion of running vapp")
|
28
|
+
|
29
|
+
description "
|
30
|
+
"
|
31
|
+
|
32
|
+
go!
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'methadone'
|
2
|
+
require 'vcloud/core'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
module Vcloud
|
6
|
+
module CLI
|
7
|
+
module Utils
|
8
|
+
class DeleteVapp
|
9
|
+
|
10
|
+
include Methadone::Main
|
11
|
+
include Methadone::CLILogging
|
12
|
+
|
13
|
+
def self.run
|
14
|
+
|
15
|
+
main do |identifier|
|
16
|
+
vcloud = ::Fog::Compute::VcloudDirector.new
|
17
|
+
if identifier =~ /^vapp-[-0-9a-f]+/
|
18
|
+
vapp = Vcloud::Core::Vapp.new(identifier)
|
19
|
+
else
|
20
|
+
vapp = Vcloud::Core::Vapp.get_by_name(identifier)
|
21
|
+
end
|
22
|
+
Fog.mock! if ENV['FOG_MOCK']
|
23
|
+
if options[:force]
|
24
|
+
task = vcloud.post_undeploy_vapp(vapp.id).body
|
25
|
+
vcloud.process_task(task)
|
26
|
+
end
|
27
|
+
task = vcloud.delete_vapp(vapp.id).body
|
28
|
+
vcloud.process_task(task)
|
29
|
+
end
|
30
|
+
|
31
|
+
arg :identifier
|
32
|
+
|
33
|
+
on("-f", "--force", "Force deletion of running vapp")
|
34
|
+
|
35
|
+
description "
|
36
|
+
"
|
37
|
+
|
38
|
+
go!
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'methadone'
|
2
|
+
require 'vcloud/core'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
module Vcloud
|
6
|
+
module CLI
|
7
|
+
module Utils
|
8
|
+
class DetachDisk
|
9
|
+
|
10
|
+
include Methadone::Main
|
11
|
+
include Methadone::CLILogging
|
12
|
+
|
13
|
+
def self.run
|
14
|
+
|
15
|
+
main do |vm_id, disk_id|
|
16
|
+
vcloud = ::Fog::Compute::VcloudDirector.new
|
17
|
+
Fog.mock! if ENV['FOG_MOCK']
|
18
|
+
task = vcloud.post_detach_disk(vm_id, disk_id).body
|
19
|
+
vcloud.process_task(task)
|
20
|
+
end
|
21
|
+
|
22
|
+
arg :vm_id
|
23
|
+
arg :disk_id
|
24
|
+
|
25
|
+
description "
|
26
|
+
"
|
27
|
+
|
28
|
+
go!
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'methadone'
|
2
|
+
require 'vcloud/core'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
module Vcloud
|
6
|
+
module CLI
|
7
|
+
module Utils
|
8
|
+
class GetEntity
|
9
|
+
|
10
|
+
include Methadone::Main
|
11
|
+
include Methadone::CLILogging
|
12
|
+
|
13
|
+
def self.run
|
14
|
+
|
15
|
+
main do |entity_type, identifier|
|
16
|
+
vcloud = ::Fog::Compute::VcloudDirector.new
|
17
|
+
case entity_type
|
18
|
+
when 'vm'
|
19
|
+
pp vcloud.get_vapp(identifier).body
|
20
|
+
when 'vApp'
|
21
|
+
pp vcloud.get_vapp(identifier).body
|
22
|
+
when 'edgeGateway'
|
23
|
+
pp vcloud.get_edge_gateway(identifier).body
|
24
|
+
when 'orgVdcNetwork'
|
25
|
+
pp vcloud.get_network_complete(identifier).body
|
26
|
+
when 'orgVdc'
|
27
|
+
pp vcloud.get_vdc(identifier).body
|
28
|
+
when /^get_/
|
29
|
+
pp vcloud.send(entity_type.to_s, identifier).body
|
30
|
+
else
|
31
|
+
help_now!("Invalid argument #{entity_type}")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
arg :entity_type
|
36
|
+
arg :identifier
|
37
|
+
|
38
|
+
description "
|
39
|
+
vcloud-get-entity retreives the raw Fog body for key entity types in vCD.
|
40
|
+
|
41
|
+
It can also call any Fog request method beginning with 'get_', that takes a single
|
42
|
+
argument -- generally the id of the entity. There are many of these.
|
43
|
+
|
44
|
+
Supported entities can usually be retreived by name as well:
|
45
|
+
|
46
|
+
* vm
|
47
|
+
* vApp
|
48
|
+
* edgeGateway
|
49
|
+
* orgVdcNetwork
|
50
|
+
* orgVdc
|
51
|
+
|
52
|
+
"
|
53
|
+
|
54
|
+
go!
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Vcloud
|
2
|
+
module CLI
|
3
|
+
module Utils
|
4
|
+
class GetVmsAttachedToDisk
|
5
|
+
|
6
|
+
include Methadone::Main
|
7
|
+
include Methadone::CLILogging
|
8
|
+
|
9
|
+
def self.run
|
10
|
+
|
11
|
+
main do |disk_id|
|
12
|
+
Fog.mock! if ENV['FOG_MOCK']
|
13
|
+
disk = Vcloud::Core::IndependentDisk.new(disk_id)
|
14
|
+
disk.attached_vms.each do |vm|
|
15
|
+
puts vm.name + " " + vm.id
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
arg :disk_id
|
20
|
+
|
21
|
+
description "
|
22
|
+
"
|
23
|
+
|
24
|
+
go!
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'methadone'
|
2
|
+
require 'vcloud/core'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
module Vcloud
|
6
|
+
module CLI
|
7
|
+
module Utils
|
8
|
+
class MakeVappTemplate
|
9
|
+
|
10
|
+
include Methadone::Main
|
11
|
+
include Methadone::CLILogging
|
12
|
+
|
13
|
+
def self.run
|
14
|
+
|
15
|
+
main do |vdc_name, blank_vapp_template_id, iso_id, template_name|
|
16
|
+
|
17
|
+
vcloud = ::Fog::Compute::VcloudDirector.new
|
18
|
+
Fog.mock! if ENV['FOG_MOCK']
|
19
|
+
|
20
|
+
vdc = Vcloud::Core::Vdc.get_by_name(vdc_name)
|
21
|
+
|
22
|
+
# Instantiate a 'blank vApp':
|
23
|
+
# * contains one VM
|
24
|
+
# * this VM has a single HDD
|
25
|
+
# * the VM HDD is blank
|
26
|
+
puts "Instantiating blank vApp/VM"
|
27
|
+
vapp = Vcloud::Core::Vapp.instantiate(
|
28
|
+
'make_vapp_template_temp_vapp',
|
29
|
+
['VappCreationTesting'],
|
30
|
+
blank_vapp_template_id,
|
31
|
+
vdc_name,
|
32
|
+
)
|
33
|
+
|
34
|
+
child_vm_id = vapp.fog_vms.first[:href].split('/').last
|
35
|
+
vm = Vcloud::Core::Vm.new(child_vm_id, vapp)
|
36
|
+
puts "Found child VM id: #{vm.id}"
|
37
|
+
|
38
|
+
# Add our ISO to the VM inside the vApp
|
39
|
+
puts "Inserting ISO into VM"
|
40
|
+
task = vcloud.post_insert_cd_rom(vm.id, iso_id).body
|
41
|
+
vcloud.process_task(task)
|
42
|
+
|
43
|
+
puts "Powering on vApp to install OS"
|
44
|
+
vapp.power_on
|
45
|
+
|
46
|
+
# vapp will now boot. VM will be shut down at the end
|
47
|
+
puts "Waiting for OS to install"
|
48
|
+
while vapp.vcloud_attributes[:status].to_i == 4
|
49
|
+
# vapp is in RUNNING state, so OS is still installing
|
50
|
+
printf('.')
|
51
|
+
sleep(5)
|
52
|
+
end
|
53
|
+
puts ""
|
54
|
+
|
55
|
+
puts "Removing ISO from VM"
|
56
|
+
task = vcloud.post_eject_cd_rom(vm.id, iso_id).body
|
57
|
+
vcloud.process_task(task)
|
58
|
+
|
59
|
+
puts "Stopping vApp completely"
|
60
|
+
task = vcloud.post_undeploy_vapp(vapp.id).body
|
61
|
+
vcloud.process_task(task)
|
62
|
+
|
63
|
+
puts "Turn the newly provisioned vApp into a vAppTemplate (in vDC #{vdc_name})"
|
64
|
+
capture_body = vcloud.post_capture_vapp(vdc.id, template_name, vapp.id).body
|
65
|
+
#vcloud.process_task(task)
|
66
|
+
pp capture_body
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
arg :vdc_id
|
71
|
+
arg :empty_vapp_template_id
|
72
|
+
arg :iso_name
|
73
|
+
arg :template_name
|
74
|
+
|
75
|
+
description "
|
76
|
+
"
|
77
|
+
|
78
|
+
go!
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'methadone'
|
2
|
+
require 'vcloud/core'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
module Vcloud
|
6
|
+
module CLI
|
7
|
+
module Utils
|
8
|
+
class StartVapp
|
9
|
+
|
10
|
+
include Methadone::Main
|
11
|
+
include Methadone::CLILogging
|
12
|
+
|
13
|
+
def self.run
|
14
|
+
|
15
|
+
main do |identifier|
|
16
|
+
vcloud = ::Fog::Compute::VcloudDirector.new
|
17
|
+
if identifier =~ /^vapp-[-0-9a-f]+/
|
18
|
+
vapp = Vcloud::Core::Vapp.new(identifier)
|
19
|
+
else
|
20
|
+
vapp = Vcloud::Core::Vapp.get_by_name(identifier)
|
21
|
+
end
|
22
|
+
Fog.mock! if ENV['FOG_MOCK']
|
23
|
+
task = vcloud.post_deploy_vapp(vapp.id).body
|
24
|
+
vcloud.process_task(task)
|
25
|
+
end
|
26
|
+
|
27
|
+
arg :identifier
|
28
|
+
|
29
|
+
description "
|
30
|
+
"
|
31
|
+
|
32
|
+
go!
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'methadone'
|
2
|
+
require 'vcloud/core'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
module Vcloud
|
6
|
+
module CLI
|
7
|
+
module Utils
|
8
|
+
class StopVapp
|
9
|
+
|
10
|
+
include Methadone::Main
|
11
|
+
include Methadone::CLILogging
|
12
|
+
|
13
|
+
def self.run
|
14
|
+
|
15
|
+
main do |identifier|
|
16
|
+
vcloud = ::Fog::Compute::VcloudDirector.new
|
17
|
+
if identifier =~ /^vapp-[-0-9a-f]+/
|
18
|
+
vapp = Vcloud::Core::Vapp.new(identifier)
|
19
|
+
else
|
20
|
+
vapp = Vcloud::Core::Vapp.get_by_name(identifier)
|
21
|
+
end
|
22
|
+
Fog.mock! if ENV['FOG_MOCK']
|
23
|
+
task = vcloud.post_undeploy_vapp(vapp.id).body
|
24
|
+
vcloud.process_task(task)
|
25
|
+
end
|
26
|
+
|
27
|
+
arg :identifier
|
28
|
+
|
29
|
+
description "
|
30
|
+
"
|
31
|
+
|
32
|
+
go!
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib/', __FILE__)
|
4
|
+
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'vcloud/cli/utils/version'
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = 'vcloud-cli-utils'
|
9
|
+
s.version = Vcloud::CLI::Utils::VERSION
|
10
|
+
s.authors = ['Mike Pountney']
|
11
|
+
s.email = ['Mike.Pountney@gmail.com']
|
12
|
+
s.summary = 'Various simple CLI utilities to communicate with the vCloud Director API'
|
13
|
+
s.description = 'Various simple CLI utilities to communicate with the vCloud Director API. Uses vcloud-core and fog.'
|
14
|
+
s.homepage = 'http://github.com/mikepea/vcloud-cli-utils'
|
15
|
+
s.license = 'MIT'
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split($/)
|
18
|
+
s.executables = s.files.grep(%r{^bin/}) {|f| File.basename(f)}
|
19
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
20
|
+
s.require_paths = ['lib']
|
21
|
+
|
22
|
+
s.required_ruby_version = '>= 1.9.2'
|
23
|
+
|
24
|
+
s.add_runtime_dependency 'fog', '>= 1.20.0'
|
25
|
+
s.add_runtime_dependency 'methadone'
|
26
|
+
s.add_runtime_dependency 'vcloud-core', '>= 0.15.0'
|
27
|
+
s.add_development_dependency 'rake'
|
28
|
+
s.add_development_dependency 'rspec', '~> 2.14.1'
|
29
|
+
s.add_development_dependency 'rubocop', '~> 0.23.0'
|
30
|
+
s.add_development_dependency 'simplecov', '~> 0.8.2'
|
31
|
+
s.add_development_dependency 'gem_publisher', '1.2.0'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vcloud-cli-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Pountney
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fog
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.20.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.20.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: methadone
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: vcloud-core
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.15.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.15.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.14.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.14.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.23.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.23.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.8.2
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.8.2
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: gem_publisher
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.2.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.2.0
|
125
|
+
description: Various simple CLI utilities to communicate with the vCloud Director
|
126
|
+
API. Uses vcloud-core and fog.
|
127
|
+
email:
|
128
|
+
- Mike.Pountney@gmail.com
|
129
|
+
executables:
|
130
|
+
- vcloud-attach-disk
|
131
|
+
- vcloud-curl
|
132
|
+
- vcloud-curl-example.sh
|
133
|
+
- vcloud-delete-disk
|
134
|
+
- vcloud-delete-network
|
135
|
+
- vcloud-delete-vapp
|
136
|
+
- vcloud-detach-disk
|
137
|
+
- vcloud-get-entity
|
138
|
+
- vcloud-get_vms_attached_to-disk
|
139
|
+
- vcloud-make-vapp-template
|
140
|
+
- vcloud-start-vapp
|
141
|
+
- vcloud-stop-vapp
|
142
|
+
extensions: []
|
143
|
+
extra_rdoc_files: []
|
144
|
+
files:
|
145
|
+
- ".gitignore"
|
146
|
+
- CHANGELOG.md
|
147
|
+
- Gemfile
|
148
|
+
- LICENSE
|
149
|
+
- README.md
|
150
|
+
- Rakefile
|
151
|
+
- bin/vcloud-attach-disk
|
152
|
+
- bin/vcloud-curl
|
153
|
+
- bin/vcloud-curl-example.sh
|
154
|
+
- bin/vcloud-delete-disk
|
155
|
+
- bin/vcloud-delete-network
|
156
|
+
- bin/vcloud-delete-vapp
|
157
|
+
- bin/vcloud-detach-disk
|
158
|
+
- bin/vcloud-get-entity
|
159
|
+
- bin/vcloud-get_vms_attached_to-disk
|
160
|
+
- bin/vcloud-make-vapp-template
|
161
|
+
- bin/vcloud-start-vapp
|
162
|
+
- bin/vcloud-stop-vapp
|
163
|
+
- lib/vcloud/cli/utils.rb
|
164
|
+
- lib/vcloud/cli/utils/attach_disk.rb
|
165
|
+
- lib/vcloud/cli/utils/delete_disk.rb
|
166
|
+
- lib/vcloud/cli/utils/delete_network.rb
|
167
|
+
- lib/vcloud/cli/utils/delete_vapp.rb
|
168
|
+
- lib/vcloud/cli/utils/detach_disk.rb
|
169
|
+
- lib/vcloud/cli/utils/get_entity.rb
|
170
|
+
- lib/vcloud/cli/utils/get_vms_attached_to_disk.rb
|
171
|
+
- lib/vcloud/cli/utils/make_vapp_template.rb
|
172
|
+
- lib/vcloud/cli/utils/start_vapp.rb
|
173
|
+
- lib/vcloud/cli/utils/stop_vapp.rb
|
174
|
+
- lib/vcloud/cli/utils/version.rb
|
175
|
+
- vcloud-cli-utils.gemspec
|
176
|
+
homepage: http://github.com/mikepea/vcloud-cli-utils
|
177
|
+
licenses:
|
178
|
+
- MIT
|
179
|
+
metadata: {}
|
180
|
+
post_install_message:
|
181
|
+
rdoc_options: []
|
182
|
+
require_paths:
|
183
|
+
- lib
|
184
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: 1.9.2
|
189
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
requirements: []
|
195
|
+
rubyforge_project:
|
196
|
+
rubygems_version: 2.2.2
|
197
|
+
signing_key:
|
198
|
+
specification_version: 4
|
199
|
+
summary: Various simple CLI utilities to communicate with the vCloud Director API
|
200
|
+
test_files: []
|