mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-23 17:33:56 +03:00
feature #378: Add econe-*-volume cli
This commit is contained in:
parent
696b1844f3
commit
14fcfc9091
10
install.sh
10
install.sh
@ -1094,8 +1094,13 @@ ECO_LIB_VIEW_FILES="src/cloud/ec2/lib/views/describe_images.erb \
|
||||
|
||||
ECO_BIN_FILES="src/cloud/ec2/bin/econe-server \
|
||||
src/cloud/ec2/bin/econe-describe-images \
|
||||
src/cloud/ec2/bin/econe-describe-volumes \
|
||||
src/cloud/ec2/bin/econe-describe-instances \
|
||||
src/cloud/ec2/bin/econe-register \
|
||||
src/cloud/ec2/bin/econe-attach-volume \
|
||||
src/cloud/ec2/bin/econe-detach-volume \
|
||||
src/cloud/ec2/bin/econe-delete-volume \
|
||||
src/cloud/ec2/bin/econe-create-volume \
|
||||
src/cloud/ec2/bin/econe-run-instances \
|
||||
src/cloud/ec2/bin/econe-terminate-instances \
|
||||
src/cloud/ec2/bin/econe-describe-addresses \
|
||||
@ -1107,7 +1112,12 @@ ECO_BIN_FILES="src/cloud/ec2/bin/econe-server \
|
||||
|
||||
ECO_BIN_CLIENT_FILES="src/cloud/ec2/bin/econe-describe-images \
|
||||
src/cloud/ec2/bin/econe-describe-instances \
|
||||
src/cloud/ec2/bin/econe-describe-volumes \
|
||||
src/cloud/ec2/bin/econe-register \
|
||||
src/cloud/ec2/bin/econe-attach-volume \
|
||||
src/cloud/ec2/bin/econe-detach-volume \
|
||||
src/cloud/ec2/bin/econe-delete-volume \
|
||||
src/cloud/ec2/bin/econe-create-volume \
|
||||
src/cloud/ec2/bin/econe-run-instances \
|
||||
src/cloud/ec2/bin/econe-terminate-instances \
|
||||
src/cloud/ec2/bin/econe-describe-addresses \
|
||||
|
150
src/cloud/ec2/bin/econe-attach-volume
Executable file
150
src/cloud/ec2/bin/econe-attach-volume
Executable file
@ -0,0 +1,150 @@
|
||||
#!/usr/bin/env ruby
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
econe-attach-volume
|
||||
|
||||
Attaches a DATABLOCK to a running instance and exposes it as the specified device.
|
||||
|
||||
Usage:
|
||||
econe-attach-volume [OPTIONS] VOLUME-ID
|
||||
|
||||
Options:
|
||||
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--access-key <id>, -K <id>
|
||||
The username of the user
|
||||
|
||||
--secret-key <key>, -S <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -U <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--instance <instance_id>, -i <instance_id>
|
||||
The ID of the instance to attach the volume to
|
||||
|
||||
--device <device>, -d <device
|
||||
Specifies the device name to expose to the instance.
|
||||
Example: -d /dev/sdf
|
||||
|
||||
--headers, -H
|
||||
Display column headers
|
||||
|
||||
VOLUME-ID: The ID of the DATABLOCK
|
||||
|
||||
EOT
|
||||
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'CloudClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',GetoptLong::NO_ARGUMENT],
|
||||
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--instance', '-i',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--device', '-d',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--headers', '-H',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
headers = false
|
||||
url = nil
|
||||
access = nil
|
||||
secret = nil
|
||||
auth = nil
|
||||
instance = nil
|
||||
device = nil
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--access-key'
|
||||
access = arg
|
||||
when '--secret-key'
|
||||
secret = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--instance'
|
||||
instance = arg
|
||||
when '--headers'
|
||||
headers = true
|
||||
when '--device'
|
||||
device = arg
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
volume_id = ARGV.shift
|
||||
|
||||
if !volume_id
|
||||
puts "#{cmd_name}: missing VOLUME-ID parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
auth = "#{access}:#{secret}" if secret && access
|
||||
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.attach_volume(volume_id, instance, device)
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
fmt = "%-15s %-15s %-10s %s"
|
||||
|
||||
if headers
|
||||
puts fmt % ["volumeId", "instanceId", "status", "device"]
|
||||
puts "------------------------------------------------------------------------------"
|
||||
end
|
||||
|
||||
puts fmt % [rc['volumeId'], rc['instanceId'], rc['status'], rc['device']]
|
||||
|
||||
exit 0
|
138
src/cloud/ec2/bin/econe-create-volume
Executable file
138
src/cloud/ec2/bin/econe-create-volume
Executable file
@ -0,0 +1,138 @@
|
||||
#!/usr/bin/env ruby
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
econe-create-volume
|
||||
|
||||
Create a new DATABLOCK
|
||||
|
||||
Usage:
|
||||
econe-create-volume [OPTIONS]
|
||||
|
||||
Options:
|
||||
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--access-key <id>, -K <id>
|
||||
The username of the user
|
||||
|
||||
--secret-key <key>, -S <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -U <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--size <size>, -s <size>
|
||||
The ID of the instance to attach the volume to
|
||||
|
||||
--headers, -H
|
||||
Display column headers
|
||||
|
||||
EOT
|
||||
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'CloudClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',GetoptLong::NO_ARGUMENT],
|
||||
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--size', '-s',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--headers', '-H',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
headers = false
|
||||
url = nil
|
||||
access = nil
|
||||
secret = nil
|
||||
auth = nil
|
||||
size = nil
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--access-key'
|
||||
access = arg
|
||||
when '--secret-key'
|
||||
secret = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--size'
|
||||
size = arg
|
||||
when '--headers'
|
||||
headers = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
if !size
|
||||
puts "#{cmd_name}: missing --size option"
|
||||
exit -1
|
||||
end
|
||||
|
||||
auth = "#{access}:#{secret}" if secret && access
|
||||
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.create_volume(size)
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
fmt = "%-15s %-10s %s"
|
||||
|
||||
if headers
|
||||
puts fmt % ["volumeId", "size", "createTime"]
|
||||
puts "------------------------------------------------------------------------------"
|
||||
end
|
||||
|
||||
puts fmt % [rc['volumeId'], rc['size'], rc['createTime']]
|
||||
|
||||
exit 0
|
126
src/cloud/ec2/bin/econe-delete-volume
Executable file
126
src/cloud/ec2/bin/econe-delete-volume
Executable file
@ -0,0 +1,126 @@
|
||||
#!/usr/bin/env ruby
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
econe-delete-volume
|
||||
|
||||
Deletes a DATABLOCK
|
||||
|
||||
Usage:
|
||||
econe-delete-volume [OPTIONS] VOLUME-ID
|
||||
|
||||
Options:
|
||||
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--access-key <id>, -K <id>
|
||||
The username of the user
|
||||
|
||||
--secret-key <key>, -S <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -U <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--headers, -H
|
||||
Display column headers
|
||||
|
||||
VOLUME-ID: The ID of the DATABLOCK
|
||||
|
||||
EOT
|
||||
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'CloudClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',GetoptLong::NO_ARGUMENT],
|
||||
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--headers', '-H',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
headers = false
|
||||
url = nil
|
||||
access = nil
|
||||
secret = nil
|
||||
auth = nil
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--access-key'
|
||||
access = arg
|
||||
when '--secret-key'
|
||||
secret = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--headers'
|
||||
headers = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
volume_id = ARGV.shift
|
||||
|
||||
if !volume_id
|
||||
puts "#{cmd_name}: missing VOLUME-ID parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
auth = "#{access}:#{secret}" if secret && access
|
||||
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.delete_volume(volume_id)
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
exit 0
|
133
src/cloud/ec2/bin/econe-describe-volumes
Executable file
133
src/cloud/ec2/bin/econe-describe-volumes
Executable file
@ -0,0 +1,133 @@
|
||||
#!/usr/bin/env ruby
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
econe-describe-volumes
|
||||
|
||||
Describes your Amazon EBS volumes
|
||||
|
||||
Usage:
|
||||
econe-describe-volumes [OPTIONS]
|
||||
|
||||
Options:
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--access-key <id>, -K <id>
|
||||
The username of the user
|
||||
|
||||
--secret-key <key>, -S <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -U <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--headers, -H
|
||||
Display column headers
|
||||
|
||||
EOT
|
||||
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'CloudClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',GetoptLong::NO_ARGUMENT],
|
||||
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--headers', '-H',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
headers = false
|
||||
url = nil
|
||||
access = nil
|
||||
secret = nil
|
||||
auth = nil
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--access-key'
|
||||
access = arg
|
||||
when '--secret-key'
|
||||
secret = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--headers'
|
||||
headers = true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
auth = "#{access}:#{secret}" if secret && access
|
||||
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.describe_volumes
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
volumes = rc['volumeSet']['item']
|
||||
|
||||
fmt = "%-15s %-10s %s"
|
||||
|
||||
if headers
|
||||
puts fmt % ["volumeId", "size", "createTime"]
|
||||
puts "------------------------------------------------------------------------------"
|
||||
end
|
||||
|
||||
if volumes
|
||||
volumes.each { |vol|
|
||||
puts fmt % [vol['volumeId'], vol['size'], vol['createTime']]
|
||||
}
|
||||
end
|
||||
|
||||
exit 0
|
||||
|
156
src/cloud/ec2/bin/econe-detach-volume
Executable file
156
src/cloud/ec2/bin/econe-detach-volume
Executable file
@ -0,0 +1,156 @@
|
||||
#!/usr/bin/env ruby
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cloud"
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
econe-detach-volume
|
||||
|
||||
Detaches an Amazon EBS volume from an instance. Make sure to unmount any
|
||||
file systems on the device within your operating system before detaching the volume
|
||||
|
||||
Usage:
|
||||
econe-detach-volume [OPTIONS] VOLUME-ID
|
||||
|
||||
Options:
|
||||
|
||||
--help, -h
|
||||
Show help
|
||||
|
||||
--access-key <id>, -K <id>
|
||||
The username of the user
|
||||
|
||||
--secret-key <key>, -S <key>
|
||||
The password of the user
|
||||
|
||||
--url <url>, -U <url>
|
||||
Set url as the web service url to use
|
||||
|
||||
--instance <instance_id>, -i <instance_id>
|
||||
The ID of the instance to attach the volume to
|
||||
|
||||
--device <device>, -d <device
|
||||
Specifies the device name to expose to the instance.
|
||||
Example: -d /dev/sdf
|
||||
|
||||
--headers, -H
|
||||
Display column headers
|
||||
|
||||
VOLUME-ID: The ID of the DATABLOCK
|
||||
|
||||
EOT
|
||||
|
||||
require 'econe/EC2QueryClient'
|
||||
require 'CloudClient'
|
||||
require 'getoptlong'
|
||||
|
||||
include CloudCLI
|
||||
|
||||
opts = GetoptLong.new(
|
||||
['--help', '-h',GetoptLong::NO_ARGUMENT],
|
||||
['--version', '-v',GetoptLong::NO_ARGUMENT],
|
||||
['--access-key', '-K',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--url', '-U',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--instance', '-i',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--device', '-d',GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--headers', '-H',GetoptLong::NO_ARGUMENT]
|
||||
)
|
||||
|
||||
headers = false
|
||||
url = nil
|
||||
access = nil
|
||||
secret = nil
|
||||
auth = nil
|
||||
instance = nil
|
||||
device = nil
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
case opt
|
||||
when '--help'
|
||||
puts COMMANDS_HELP
|
||||
return
|
||||
when '--version'
|
||||
puts CloudCLI.version_text
|
||||
exit 0
|
||||
when '--access-key'
|
||||
access = arg
|
||||
when '--secret-key'
|
||||
secret = arg
|
||||
when '--url'
|
||||
url = arg
|
||||
when '--instance'
|
||||
instance = arg
|
||||
when '--headers'
|
||||
headers = true
|
||||
when '--device'
|
||||
device = arg
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit -1
|
||||
end
|
||||
|
||||
volume_id = ARGV.shift
|
||||
|
||||
if !volume_id
|
||||
puts "#{cmd_name}: missing VOLUME-ID parameter"
|
||||
exit -1
|
||||
end
|
||||
|
||||
if !instance
|
||||
puts "#{cmd_name}: missing --instance option"
|
||||
exit -1
|
||||
end
|
||||
|
||||
auth = "#{access}:#{secret}" if secret && access
|
||||
|
||||
begin
|
||||
ec2_client = EC2QueryClient::Client.new(auth,url)
|
||||
rescue Exception => e
|
||||
puts "#{cmd_name}: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
rc = ec2_client.detach_volume(volume_id, instance, device)
|
||||
|
||||
if CloudClient::is_error?(rc)
|
||||
puts "#{cmd_name}: #{rc.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
fmt = "%-15s %-15s %-10s %s"
|
||||
|
||||
if headers
|
||||
puts fmt % ["volumeId", "instanceId", "status", "device"]
|
||||
puts "------------------------------------------------------------------------------"
|
||||
end
|
||||
|
||||
puts fmt % [rc['volumeId'], rc['instanceId'], rc['status'], rc['device']]
|
||||
|
||||
exit 0
|
@ -268,7 +268,7 @@ module EC2QueryClient
|
||||
def associate_address(public_ip, instance_id)
|
||||
begin
|
||||
response = @ec2_connection.associate_address(
|
||||
:public_ip => public_ip,
|
||||
:public_ip => public_ip,
|
||||
:instance_id => instance_id)
|
||||
rescue Exception => e
|
||||
error = CloudClient::Error.new(e.message)
|
||||
@ -305,5 +305,93 @@ module EC2QueryClient
|
||||
|
||||
return response
|
||||
end
|
||||
|
||||
######################################################################
|
||||
#
|
||||
#
|
||||
######################################################################
|
||||
def describe_volumes
|
||||
begin
|
||||
response = @ec2_connection.describe_volumes
|
||||
rescue Exception => e
|
||||
error = CloudClient::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
return response
|
||||
end
|
||||
|
||||
######################################################################
|
||||
#
|
||||
#
|
||||
######################################################################
|
||||
def attach_volume(volume, instance, device)
|
||||
begin
|
||||
response = @ec2_connection.attach_volume(
|
||||
:volume_id => volume,
|
||||
:instance_id => instance,
|
||||
:device => device
|
||||
)
|
||||
rescue Exception => e
|
||||
error = CloudClient::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
return response
|
||||
end
|
||||
|
||||
######################################################################
|
||||
#
|
||||
#
|
||||
######################################################################
|
||||
def delete_volume(volume)
|
||||
begin
|
||||
response = @ec2_connection.delete_volume(
|
||||
:volume_id => volume
|
||||
)
|
||||
rescue Exception => e
|
||||
error = CloudClient::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
return response
|
||||
end
|
||||
|
||||
######################################################################
|
||||
#
|
||||
#
|
||||
######################################################################
|
||||
def detach_volume(volume, instance, device)
|
||||
begin
|
||||
response = @ec2_connection.detach_volume(
|
||||
:volume_id => volume,
|
||||
:instance_id => instance,
|
||||
:device => device
|
||||
)
|
||||
rescue Exception => e
|
||||
error = CloudClient::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
return response
|
||||
end
|
||||
|
||||
######################################################################
|
||||
#
|
||||
#
|
||||
######################################################################
|
||||
def create_volume(size)
|
||||
begin
|
||||
response = @ec2_connection.create_volume(
|
||||
:size => size,
|
||||
:availability_zone => 'default'
|
||||
)
|
||||
rescue Exception => e
|
||||
error = CloudClient::Error.new(e.message)
|
||||
return error
|
||||
end
|
||||
|
||||
return response
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user