diff --git a/install.sh b/install.sh index 6a7f9055a7..7a9be7e6ac 100755 --- a/install.sh +++ b/install.sh @@ -344,6 +344,7 @@ VAR_DIRS="$VAR_LOCATION/remotes \ $VAR_LOCATION/remotes/hooks \ $VAR_LOCATION/remotes/hooks/ft \ $VAR_LOCATION/remotes/hooks/vcenter \ + $VAR_LOCATION/remotes/hooks/vcenter/templates \ $VAR_LOCATION/remotes/hooks/raft \ $VAR_LOCATION/remotes/hooks/alias_ip \ $VAR_LOCATION/remotes/datastore \ @@ -532,6 +533,7 @@ INSTALL_FILES=( FOLLOWER_CLEANUP_SHARE_FILE:$SHARE_LOCATION HOOK_FT_FILES:$VAR_LOCATION/remotes/hooks/ft HOOK_VCENTER_FILES:$VAR_LOCATION/remotes/hooks/vcenter + HOOK_VCENTER_TMPLS:$VAR_LOCATION/remotes/hooks/vcenter/templates HOOK_RAFT_FILES:$VAR_LOCATION/remotes/hooks/raft HOOK_ALIAS_IP_FILES:$VAR_LOCATION/remotes/hooks/alias_ip COMMON_CLOUD_LIB_FILES:$LIB_LOCATION/ruby/cloud @@ -1682,6 +1684,14 @@ HOOK_FT_FILES="share/hooks/ft/host_error.rb \ HOOK_VCENTER_FILES="share/hooks/vcenter/create_vcenter_net.rb \ share/hooks/vcenter/delete_vcenter_net.rb" +#------------------------------------------------------------------------------- +# HOOK templates, to be installed under +# $VAR_LOCATION/remotes/hooks/vcenter/templates +#------------------------------------------------------------------------------- + +HOOK_VCENTER_TMPLS="share/hooks/vcenter/templates/create_vcenter_net.tmpl \ + share/hooks/vcenter/templates/delete_vcenter_net.tmpl" + #------------------------------------------------------------------------------- # HOOK RAFT scripts, to be installed under $VAR_LOCATION/remotes/hooks/raft #------------------------------------------------------------------------------- diff --git a/share/hooks/vcenter/templates/create_vcenter_net.tmpl b/share/hooks/vcenter/templates/create_vcenter_net.tmpl new file mode 100644 index 0000000000..7aae4c6e99 --- /dev/null +++ b/share/hooks/vcenter/templates/create_vcenter_net.tmpl @@ -0,0 +1,6 @@ +NAME = vcenter_net_create +TYPE = api +COMMAND = vcenter/create_vcenter_net.rb +CALL = "one.vn.allocate" +ARGUMENTS = "$API" +ARGUMENTS_STDIN = yes diff --git a/share/hooks/vcenter/templates/delete_vcenter_net.tmpl b/share/hooks/vcenter/templates/delete_vcenter_net.tmpl new file mode 100644 index 0000000000..94ab20b4e2 --- /dev/null +++ b/share/hooks/vcenter/templates/delete_vcenter_net.tmpl @@ -0,0 +1,6 @@ +NAME = vcenter_net_delete +TYPE = api +COMMAND = vcenter/delete_vcenter_net.rb +CALL = "one.vn.delete" +ARGUMENTS = "$API" +ARGUMENTS_STDIN = yes diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/vcenter_importer.rb b/src/vmm_mad/remotes/lib/vcenter_driver/vcenter_importer.rb index a0bffc9efe..3d84520c1d 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/vcenter_importer.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/vcenter_importer.rb @@ -15,6 +15,18 @@ #--------------------------------------------------------------------------- # module VCenterDriver + + ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION) + + if !ONE_LOCATION + RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION) + GEMS_LOCATION = '/usr/share/one/gems' unless defined?(GEMS_LOCATION) + HOOK_LOCATION = '/var/lib/one/remotes/hooks' unless defined?(HOOK_LOCATION) + else + RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION) + GEMS_LOCATION = ONE_LOCATION + '/share/gems' unless defined?(GEMS_LOCATION) + HOOK_LOCATION = ONE_LOCATION + '/remotes/hooks' unless defined?(HOOK_LOCATION) + end class VcImporter attr_accessor :list @@ -508,6 +520,8 @@ module VCenterDriver STDOUT.puts } } + VCenterDriver::VcImporter.register_hooks + rescue Interrupt => e puts "\n" exit 0 #Ctrl+C @@ -521,5 +535,21 @@ module VCenterDriver end + def self.register_hooks + hooks_path = HOOK_LOCATION + '/vcenter/templates' + client = OpenNebula::Client.new + hook = OpenNebula::Hook.new(OpenNebula::Hook.build_xml, client) + hook_pool = OpenNebula::HookPool.new(client) + rc = hook_pool.info + if OpenNebula.is_error?(rc) + STDERR.puts rc.message + exit 1 + end + hook_files = Dir["#{hooks_path}/*.tmpl"] + hook_files.each do |hook_file| + hook.allocate(File.open(hook_file).read) + end + end + end end