mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-19 11:22:55 +09:00
115 lines
4.4 KiB
Ruby
Executable File
115 lines
4.4 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
# -------------------------------------------------------------------------- #
|
|
# Copyright 2002-2011, 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+"/cli"
|
|
|
|
require 'command_parser'
|
|
require 'one_helper/onevnet_helper'
|
|
|
|
cmd=CommandParser::CmdParser.new(ARGV) do
|
|
usage "onevnet COMMAND [args..] [options..]"
|
|
|
|
helper = OneVNetHelper.new
|
|
|
|
########################################################################
|
|
# Global Options
|
|
########################################################################
|
|
set :option, CommandParser::OPTIONS
|
|
|
|
########################################################################
|
|
# Formatters for arguments
|
|
########################################################################
|
|
oneid_desc='OpenNebula Virtual Network name or id'
|
|
set :format, :vnetid, oneid_desc do |arg|
|
|
helper.to_id(arg)
|
|
end
|
|
|
|
onelistid_desc='Comma-separated list of OpenNebula Virtual Network names or ids'
|
|
set :format, :vnetid_list, onelistid_desc do |arg|
|
|
helper.list_to_id(arg)
|
|
end
|
|
|
|
filterflag_desc=<<-EOT
|
|
a, all --> all the known Virtual Networks
|
|
m, mine --> the Virtual Networks belonging to the user in ONE_AUTH
|
|
g, group --> 'mine' plus the Virtual Networks belonging to the groups
|
|
the user is member of
|
|
uid --> Virtual Networks of the user identified by this uid
|
|
user --> Virtual Networks of the user identified by the username
|
|
EOT
|
|
set :format, :filterflag, filterflag_desc do |arg|
|
|
helper.filterflag_to_i(arg)
|
|
end
|
|
|
|
########################################################################
|
|
# Commands
|
|
########################################################################
|
|
command :create, 'Create a new Virtual Network', :file do
|
|
helper.create_resource(args.shift, options)
|
|
end
|
|
|
|
command :show, 'Gets info from a Virtual Network', :oneid,
|
|
:options=>OpenNebulaHelper::XML do
|
|
helper.show_resource(args.shift,options)
|
|
end
|
|
|
|
command :list, 'Lists Virtual Networks in the pool', [:filterflag, nil],
|
|
:options=>CLIHelper::OPTIONS<<OpenNebulaHelper::XML do
|
|
helper.list_pool(options)
|
|
end
|
|
|
|
command :publish, 'Publishes a Virtual Network', [:range,:vnetid_list] do
|
|
helper.perform_actions(args[0],nil,options,"published") do |vn|
|
|
vn.publish
|
|
end
|
|
end
|
|
|
|
command :unpublish, 'Unpublishes a Virtual Network', [:range,:vnetid_list] do
|
|
helper.perform_actions(args[0],nil,options,"unpublished") do |vn|
|
|
vn.unpublish
|
|
end
|
|
end
|
|
|
|
command :addleases, 'Adds a lease to the Virtual Network', :oneid, :text, [:text, nil] do
|
|
helper.perform_action(args.shift,args,options,"lease added") do |vn|
|
|
vn.addleases(args[0], args[1])
|
|
end
|
|
end
|
|
|
|
command :rmleases, 'Removes a lease from the Virtual Network', :oneid, :text do
|
|
helper.perform_action(args.shift,args,options,"lease removed") do |vn|
|
|
vn.rmleases(args[0])
|
|
end
|
|
end
|
|
|
|
command :delete, 'Removes a Virtual Network', [:range, :vnetid_list] do
|
|
helper.perform_actions(args[0],nil,options,"deleted") do |vn|
|
|
vn.delete
|
|
end
|
|
end
|
|
end
|