From e658320cb5a3fb1c12688074bb9bae9bf4e2e73f Mon Sep 17 00:00:00 2001 From: Jan Orel Date: Sun, 5 Apr 2020 19:50:45 +0200 Subject: [PATCH] F #3859: Adapt azure+ec2 driver to new monitoring system(#4481) --- install.sh | 65 +- share/install_gems/CentOS7/Gemfile.lock | 38 +- share/install_gems/CentOS8/Gemfile.lock | 42 +- share/install_gems/Debian10/Gemfile.lock | 42 +- share/install_gems/Debian9/Gemfile.lock | 42 +- share/install_gems/Gemfile | 2 +- share/install_gems/Ubuntu1604/Gemfile.lock | 42 +- share/install_gems/Ubuntu1804/Gemfile.lock | 42 +- share/install_gems/Ubuntu1904/Gemfile.lock | 42 +- share/install_gems/Ubuntu1910/Gemfile.lock | 42 +- .../host/monitor/probe_host_monitor.rb} | 21 +- .../host/system/probe_host_system.rb | 45 + .../vm/monitor/probe_vm_monitor.rb | 45 + .../az-probes.d/vm/status/probe_vm_status.rb | 49 + src/im_mad/remotes/az.d/monitord-client.rb | 1 + .../remotes/az.d/monitord-client_control.sh | 1 + .../remotes/common.d/monitord-client.rb | 33 +- .../common.d/monitord-client_control.sh | 2 +- .../host/monitor/probe_host_monitor.rb} | 16 +- .../host/system/probe_host_system.rb | 47 + .../vm/monitor/probe_vm_monitor.rb | 46 + .../ec2-probes.d/vm/status/probe_vm_status.rb | 49 + src/im_mad/remotes/ec2.d/monitord-client.rb | 1 + .../remotes/ec2.d/monitord-client_control.sh | 1 + .../firecracker-probes.d/vm/status/state.rb | 4 +- .../remotes/kvm-probes.d/vm/status/state.rb | 4 +- src/im_mad/remotes/lib/firecracker.rb | 2 +- src/im_mad/remotes/lib/kvm.rb | 6 +- src/im_mad/remotes/lib/probe_db.rb | 25 +- .../remotes/lxd-probes.d/vm/status/state.rb | 10 +- src/mad/ruby/PublicCloudDriver.rb | 264 +++++ src/vmm_mad/remotes/az/az_driver.conf | 6 +- src/vmm_mad/remotes/az/az_driver.rb | 499 +++++----- src/vmm_mad/remotes/az/save | 35 +- src/vmm_mad/remotes/ec2/ec2_driver.conf | 6 +- src/vmm_mad/remotes/ec2/ec2_driver.rb | 939 +++++++++--------- src/vmm_mad/remotes/ec2/save | 37 +- 37 files changed, 1577 insertions(+), 1016 deletions(-) rename src/im_mad/remotes/{az.d/poll => az-probes.d/host/monitor/probe_host_monitor.rb} (69%) create mode 100755 src/im_mad/remotes/az-probes.d/host/system/probe_host_system.rb create mode 100755 src/im_mad/remotes/az-probes.d/vm/monitor/probe_vm_monitor.rb create mode 100755 src/im_mad/remotes/az-probes.d/vm/status/probe_vm_status.rb create mode 120000 src/im_mad/remotes/az.d/monitord-client.rb create mode 120000 src/im_mad/remotes/az.d/monitord-client_control.sh rename src/im_mad/remotes/{ec2.d/poll => ec2-probes.d/host/monitor/probe_host_monitor.rb} (72%) create mode 100755 src/im_mad/remotes/ec2-probes.d/host/system/probe_host_system.rb create mode 100755 src/im_mad/remotes/ec2-probes.d/vm/monitor/probe_vm_monitor.rb create mode 100755 src/im_mad/remotes/ec2-probes.d/vm/status/probe_vm_status.rb create mode 120000 src/im_mad/remotes/ec2.d/monitord-client.rb create mode 120000 src/im_mad/remotes/ec2.d/monitord-client_control.sh create mode 100644 src/mad/ruby/PublicCloudDriver.rb diff --git a/install.sh b/install.sh index cf23d17bb7..14070a0993 100755 --- a/install.sh +++ b/install.sh @@ -305,7 +305,15 @@ VAR_DIRS="$VAR_LOCATION/remotes \ $VAR_LOCATION/remotes/im/firecracker-probes.d/vm/status \ $VAR_LOCATION/remotes/im/vcenter.d \ $VAR_LOCATION/remotes/im/ec2.d \ + $VAR_LOCATION/remotes/im/ec2-probes.d/host/monitor \ + $VAR_LOCATION/remotes/im/ec2-probes.d/host/system \ + $VAR_LOCATION/remotes/im/ec2-probes.d/vm/monitor \ + $VAR_LOCATION/remotes/im/ec2-probes.d/vm/status \ $VAR_LOCATION/remotes/im/az.d \ + $VAR_LOCATION/remotes/im/az-probes.d/host/monitor \ + $VAR_LOCATION/remotes/im/az-probes.d/host/system \ + $VAR_LOCATION/remotes/im/az-probes.d/vm/monitor \ + $VAR_LOCATION/remotes/im/az-probes.d/vm/status \ $VAR_LOCATION/remotes/im/one.d \ $VAR_LOCATION/remotes/im/packet.d \ $VAR_LOCATION/remotes/pm \ @@ -486,6 +494,11 @@ INSTALL_FILES=( IM_PROBES_FIRECRACKER_FILES:$VAR_LOCATION/remotes/im/firecracker.d IM_PROBES_DUMMY_FILES:$VAR_LOCATION/remotes/im/dummy.d IM_PROBES_LXD_FILES:$VAR_LOCATION/remotes/im/lxd.d + IM_PROBES_VCENTER_FILES:$VAR_LOCATION/remotes/im/vcenter.d + IM_PROBES_EC2_FILES:$VAR_LOCATION/remotes/im/ec2.d + IM_PROBES_AZ_FILES:$VAR_LOCATION/remotes/im/az.d + IM_PROBES_ONE_FILES:$VAR_LOCATION/remotes/im/one.d + IM_PROBES_PACKET_FILES:$VAR_LOCATION/remotes/im/packet.d IM_PROBES_KVM_HOST_BEACON_FILES:$VAR_LOCATION/remotes/im/kvm-probes.d/host/beacon IM_PROBES_KVM_HOST_MONITOR_FILES:$VAR_LOCATION/remotes/im/kvm-probes.d/host/monitor IM_PROBES_KVM_HOST_SYSTEM_FILES:$VAR_LOCATION/remotes/im/kvm-probes.d/host/system @@ -504,11 +517,14 @@ INSTALL_FILES=( IM_PROBES_LXD_VM_STATUS_FILES:$VAR_LOCATION/remotes/im/lxd-probes.d/vm/status IM_PROBES_LXD_PROBES_FILES:$VAR_LOCATION/remotes/im/lxd-probes.d IM_PROBES_ETC_LXD_PROBES_FILES:$VAR_LOCATION/remotes/etc/im/lxd-probes.d - IM_PROBES_VCENTER_FILES:$VAR_LOCATION/remotes/im/vcenter.d - IM_PROBES_EC2_FILES:$VAR_LOCATION/remotes/im/ec2.d - IM_PROBES_AZ_FILES:$VAR_LOCATION/remotes/im/az.d - IM_PROBES_ONE_FILES:$VAR_LOCATION/remotes/im/one.d - IM_PROBES_PACKET_FILES:$VAR_LOCATION/remotes/im/packet.d + IM_PROBES_AZ_HOST_MONITOR_FILES:$VAR_LOCATION/remotes/im/az-probes.d/host/monitor + IM_PROBES_AZ_HOST_SYSTEM_FILES:$VAR_LOCATION/remotes/im/az-probes.d/host/system + IM_PROBES_AZ_VM_MONITOR_FILES:$VAR_LOCATION/remotes/im/az-probes.d/vm/monitor + IM_PROBES_AZ_VM_STATUS_FILES:$VAR_LOCATION/remotes/im/az-probes.d/vm/status + IM_PROBES_EC2_HOST_MONITOR_FILES:$VAR_LOCATION/remotes/im/ec2-probes.d/host/monitor + IM_PROBES_EC2_HOST_SYSTEM_FILES:$VAR_LOCATION/remotes/im/ec2-probes.d/host/system + IM_PROBES_EC2_VM_MONITOR_FILES:$VAR_LOCATION/remotes/im/ec2-probes.d/vm/monitor + IM_PROBES_EC2_VM_STATUS_FILES:$VAR_LOCATION/remotes/im/ec2-probes.d/vm/status IM_PROBES_VERSION:$VAR_LOCATION/remotes IM_PROBES_FIRECRACKER_HOST_BEACON_FILES:$VAR_LOCATION/remotes/im/firecracker-probes.d/host/beacon IM_PROBES_FIRECRACKER_HOST_MONITOR_FILES:$VAR_LOCATION/remotes/im/firecracker-probes.d/host/monitor @@ -789,6 +805,7 @@ RUBY_LIB_FILES="src/mad/ruby/ActionManager.rb \ src/mad/ruby/CommandManager.rb \ src/mad/ruby/OpenNebulaDriver.rb \ src/mad/ruby/VirtualMachineDriver.rb \ + src/mad/ruby/PublicCloudDriver.rb \ src/mad/ruby/DriverExecHelper.rb \ src/mad/ruby/ssh_stream.rb \ src/vnm_mad/one_vnm.rb \ @@ -1067,7 +1084,6 @@ VMM_EXEC_EC2_SCRIPTS="src/vmm_mad/remotes/ec2/cancel \ src/vmm_mad/remotes/ec2/reboot \ src/vmm_mad/remotes/ec2/reset \ src/vmm_mad/remotes/ec2/save \ - src/vmm_mad/remotes/ec2/poll \ src/vmm_mad/remotes/ec2/shutdown \ src/vmm_mad/remotes/ec2/reconfigure \ src/vmm_mad/remotes/ec2/prereconfigure \ @@ -1091,7 +1107,6 @@ VMM_EXEC_AZ_SCRIPTS="src/vmm_mad/remotes/az/cancel \ src/vmm_mad/remotes/az/reboot \ src/vmm_mad/remotes/az/reset \ src/vmm_mad/remotes/az/save \ - src/vmm_mad/remotes/az/poll \ src/vmm_mad/remotes/az/shutdown \ src/vmm_mad/remotes/az/reconfigure \ src/vmm_mad/remotes/az/prereconfigure \ @@ -1273,9 +1288,41 @@ IM_PROBES_ETC_FIRECRACKER_PROBES_FILES="src/im_mad/remotes/lib/probe_db.conf" IM_PROBES_VCENTER_FILES="src/im_mad/remotes/vcenter.d/poll" -IM_PROBES_EC2_FILES="src/im_mad/remotes/ec2.d/poll" +# EC2 monitord-client +IM_PROBES_EC2_FILES="\ + src/im_mad/remotes/ec2.d/monitord-client_control.sh \ + src/im_mad/remotes/ec2.d/monitord-client.rb" -IM_PROBES_AZ_FILES="src/im_mad/remotes/az.d/poll" +# EC2 probes +IM_PROBES_EC2_HOST_MONITOR_FILES="\ + src/im_mad/remotes/ec2-probes.d/host/monitor/probe_host_monitor.rb" + +IM_PROBES_EC2_HOST_SYSTEM_FILES="\ + src/im_mad/remotes/ec2-probes.d/host/system/probe_host_system.rb" + +IM_PROBES_EC2_VM_MONITOR_FILES="\ + src/im_mad/remotes/ec2-probes.d/vm/monitor/probe_vm_monitor.rb" + +IM_PROBES_EC2_VM_STATUS_FILES="\ + src/im_mad/remotes/ec2-probes.d/vm/status/probe_vm_status.rb" + +# AZ monitord-client +IM_PROBES_AZ_FILES="\ + src/im_mad/remotes/az.d/monitord-client_control.sh \ + src/im_mad/remotes/az.d/monitord-client.rb" + +# AZ probes +IM_PROBES_AZ_HOST_MONITOR_FILES="\ + src/im_mad/remotes/az-probes.d/host/monitor/probe_host_monitor.rb" + +IM_PROBES_AZ_HOST_SYSTEM_FILES="\ + src/im_mad/remotes/az-probes.d/host/system/probe_host_system.rb" + +IM_PROBES_AZ_VM_MONITOR_FILES="\ + src/im_mad/remotes/az-probes.d/vm/monitor/probe_vm_monitor.rb" + +IM_PROBES_AZ_VM_STATUS_FILES="\ + src/im_mad/remotes/az-probes.d/vm/status/probe_vm_status.rb" IM_PROBES_ONE_FILES="src/im_mad/remotes/one.d/poll" diff --git a/share/install_gems/CentOS7/Gemfile.lock b/share/install_gems/CentOS7/Gemfile.lock index bce7b0049d..4846ba09b0 100644 --- a/share/install_gems/CentOS7/Gemfile.lock +++ b/share/install_gems/CentOS7/Gemfile.lock @@ -12,24 +12,26 @@ GEM xml-simple (>= 1.0.12) augeas (0.6.4) aws-eventstream (1.0.3) - aws-sdk (2.11.446) - aws-sdk-resources (= 2.11.446) - aws-sdk-core (2.11.446) - aws-sigv4 (~> 1.0) - jmespath (~> 1.0) - aws-sdk-resources (2.11.446) - aws-sdk-core (= 2.11.446) - aws-sigv4 (1.1.0) + aws-partitions (1.289.0) + aws-sdk-core (3.92.0) aws-eventstream (~> 1.0, >= 1.0.2) - azure_mgmt_compute (0.19.0) + aws-partitions (~> 1, >= 1.239.0) + aws-sigv4 (~> 1.1) + jmespath (~> 1.0) + aws-sdk-ec2 (1.151.0) + aws-sdk-core (~> 3, >= 3.71.0) + aws-sigv4 (~> 1.1) + aws-sigv4 (1.1.1) + aws-eventstream (~> 1.0, >= 1.0.2) + azure_mgmt_compute (0.19.1) ms_rest_azure (~> 0.11.1) azure_mgmt_monitor (0.17.5) ms_rest_azure (~> 0.11.1) - azure_mgmt_network (0.23.0) + azure_mgmt_network (0.23.1) ms_rest_azure (~> 0.11.1) azure_mgmt_resources (0.17.8) ms_rest_azure (~> 0.11.1) - azure_mgmt_storage (0.19.2) + azure_mgmt_storage (0.19.3) ms_rest_azure (~> 0.11.1) builder (3.2.4) chunky_png (1.3.11) @@ -69,15 +71,15 @@ GEM mime-types-data (3.2019.1009) mini_portile2 (2.1.0) minitest (5.11.3) - ms_rest (0.7.5) + ms_rest (0.7.6) concurrent-ruby (~> 1.0) - faraday (~> 0.9) + faraday (>= 0.9, < 2.0.0) timeliness (~> 0.3.10) - ms_rest_azure (0.11.1) + ms_rest_azure (0.11.2) concurrent-ruby (~> 1.0) - faraday (~> 0.9) + faraday (>= 0.9, < 2.0.0) faraday-cookie_jar (~> 0.0.6) - ms_rest (~> 0.7.4) + ms_rest (~> 0.7.6) unf_ext (= 0.0.7.2) multipart-post (2.1.1) mysql2 (0.5.3) @@ -102,7 +104,7 @@ GEM rqrcode (0.10.1) chunky_png (~> 1.0) scrub_rb (1.0.1) - sequel (5.29.0) + sequel (5.30.0) sinatra (1.4.8) rack (~> 1.5) rack-protection (~> 1.4) @@ -138,7 +140,7 @@ DEPENDENCIES activesupport (~> 4.2) amazon-ec2 augeas (~> 0.6) - aws-sdk (~> 2.5) + aws-sdk-ec2 (>= 1.151) azure_mgmt_compute azure_mgmt_monitor azure_mgmt_network diff --git a/share/install_gems/CentOS8/Gemfile.lock b/share/install_gems/CentOS8/Gemfile.lock index 668638efd2..bbe6b74060 100644 --- a/share/install_gems/CentOS8/Gemfile.lock +++ b/share/install_gems/CentOS8/Gemfile.lock @@ -12,24 +12,26 @@ GEM xml-simple (>= 1.0.12) augeas (0.6.4) aws-eventstream (1.0.3) - aws-sdk (2.11.446) - aws-sdk-resources (= 2.11.446) - aws-sdk-core (2.11.446) - aws-sigv4 (~> 1.0) - jmespath (~> 1.0) - aws-sdk-resources (2.11.446) - aws-sdk-core (= 2.11.446) - aws-sigv4 (1.1.0) + aws-partitions (1.290.0) + aws-sdk-core (3.92.0) aws-eventstream (~> 1.0, >= 1.0.2) - azure_mgmt_compute (0.19.0) + aws-partitions (~> 1, >= 1.239.0) + aws-sigv4 (~> 1.1) + jmespath (~> 1.0) + aws-sdk-ec2 (1.151.0) + aws-sdk-core (~> 3, >= 3.71.0) + aws-sigv4 (~> 1.1) + aws-sigv4 (1.1.1) + aws-eventstream (~> 1.0, >= 1.0.2) + azure_mgmt_compute (0.19.1) ms_rest_azure (~> 0.11.1) azure_mgmt_monitor (0.17.5) ms_rest_azure (~> 0.11.1) - azure_mgmt_network (0.23.0) + azure_mgmt_network (0.23.1) ms_rest_azure (~> 0.11.1) azure_mgmt_resources (0.17.8) ms_rest_azure (~> 0.11.1) - azure_mgmt_storage (0.19.2) + azure_mgmt_storage (0.19.3) ms_rest_azure (~> 0.11.1) builder (3.2.4) chunky_png (1.3.11) @@ -69,22 +71,22 @@ GEM mime-types-data (3.2019.1009) mini_portile2 (2.4.0) minitest (5.14.0) - ms_rest (0.7.5) + ms_rest (0.7.6) concurrent-ruby (~> 1.0) - faraday (~> 0.9) + faraday (>= 0.9, < 2.0.0) timeliness (~> 0.3.10) - ms_rest_azure (0.11.1) + ms_rest_azure (0.11.2) concurrent-ruby (~> 1.0) - faraday (~> 0.9) + faraday (>= 0.9, < 2.0.0) faraday-cookie_jar (~> 0.0.6) - ms_rest (~> 0.7.4) + ms_rest (~> 0.7.6) unf_ext (= 0.0.7.2) multipart-post (2.1.1) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) mysql2 (0.5.3) net-ldap (0.16.2) - nokogiri (1.10.8) + nokogiri (1.10.9) mini_portile2 (~> 2.4.0) optimist (3.0.0) ox (2.13.2) @@ -104,9 +106,9 @@ GEM rqrcode (1.1.2) chunky_png (~> 1.0) rqrcode_core (~> 0.1) - rqrcode_core (0.1.1) + rqrcode_core (0.1.2) ruby2_keywords (0.0.2) - sequel (5.29.0) + sequel (5.30.0) sinatra (2.0.8.1) mustermann (~> 1.0) rack (~> 2.0) @@ -144,7 +146,7 @@ DEPENDENCIES activesupport (~> 4.2) amazon-ec2 augeas (~> 0.6) - aws-sdk (~> 2.5) + aws-sdk-ec2 (>= 1.151) azure_mgmt_compute azure_mgmt_monitor azure_mgmt_network diff --git a/share/install_gems/Debian10/Gemfile.lock b/share/install_gems/Debian10/Gemfile.lock index 668638efd2..bbe6b74060 100644 --- a/share/install_gems/Debian10/Gemfile.lock +++ b/share/install_gems/Debian10/Gemfile.lock @@ -12,24 +12,26 @@ GEM xml-simple (>= 1.0.12) augeas (0.6.4) aws-eventstream (1.0.3) - aws-sdk (2.11.446) - aws-sdk-resources (= 2.11.446) - aws-sdk-core (2.11.446) - aws-sigv4 (~> 1.0) - jmespath (~> 1.0) - aws-sdk-resources (2.11.446) - aws-sdk-core (= 2.11.446) - aws-sigv4 (1.1.0) + aws-partitions (1.290.0) + aws-sdk-core (3.92.0) aws-eventstream (~> 1.0, >= 1.0.2) - azure_mgmt_compute (0.19.0) + aws-partitions (~> 1, >= 1.239.0) + aws-sigv4 (~> 1.1) + jmespath (~> 1.0) + aws-sdk-ec2 (1.151.0) + aws-sdk-core (~> 3, >= 3.71.0) + aws-sigv4 (~> 1.1) + aws-sigv4 (1.1.1) + aws-eventstream (~> 1.0, >= 1.0.2) + azure_mgmt_compute (0.19.1) ms_rest_azure (~> 0.11.1) azure_mgmt_monitor (0.17.5) ms_rest_azure (~> 0.11.1) - azure_mgmt_network (0.23.0) + azure_mgmt_network (0.23.1) ms_rest_azure (~> 0.11.1) azure_mgmt_resources (0.17.8) ms_rest_azure (~> 0.11.1) - azure_mgmt_storage (0.19.2) + azure_mgmt_storage (0.19.3) ms_rest_azure (~> 0.11.1) builder (3.2.4) chunky_png (1.3.11) @@ -69,22 +71,22 @@ GEM mime-types-data (3.2019.1009) mini_portile2 (2.4.0) minitest (5.14.0) - ms_rest (0.7.5) + ms_rest (0.7.6) concurrent-ruby (~> 1.0) - faraday (~> 0.9) + faraday (>= 0.9, < 2.0.0) timeliness (~> 0.3.10) - ms_rest_azure (0.11.1) + ms_rest_azure (0.11.2) concurrent-ruby (~> 1.0) - faraday (~> 0.9) + faraday (>= 0.9, < 2.0.0) faraday-cookie_jar (~> 0.0.6) - ms_rest (~> 0.7.4) + ms_rest (~> 0.7.6) unf_ext (= 0.0.7.2) multipart-post (2.1.1) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) mysql2 (0.5.3) net-ldap (0.16.2) - nokogiri (1.10.8) + nokogiri (1.10.9) mini_portile2 (~> 2.4.0) optimist (3.0.0) ox (2.13.2) @@ -104,9 +106,9 @@ GEM rqrcode (1.1.2) chunky_png (~> 1.0) rqrcode_core (~> 0.1) - rqrcode_core (0.1.1) + rqrcode_core (0.1.2) ruby2_keywords (0.0.2) - sequel (5.29.0) + sequel (5.30.0) sinatra (2.0.8.1) mustermann (~> 1.0) rack (~> 2.0) @@ -144,7 +146,7 @@ DEPENDENCIES activesupport (~> 4.2) amazon-ec2 augeas (~> 0.6) - aws-sdk (~> 2.5) + aws-sdk-ec2 (>= 1.151) azure_mgmt_compute azure_mgmt_monitor azure_mgmt_network diff --git a/share/install_gems/Debian9/Gemfile.lock b/share/install_gems/Debian9/Gemfile.lock index d47e984175..4143482d15 100644 --- a/share/install_gems/Debian9/Gemfile.lock +++ b/share/install_gems/Debian9/Gemfile.lock @@ -12,24 +12,26 @@ GEM xml-simple (>= 1.0.12) augeas (0.6.4) aws-eventstream (1.0.3) - aws-sdk (2.11.446) - aws-sdk-resources (= 2.11.446) - aws-sdk-core (2.11.446) - aws-sigv4 (~> 1.0) - jmespath (~> 1.0) - aws-sdk-resources (2.11.446) - aws-sdk-core (= 2.11.446) - aws-sigv4 (1.1.0) + aws-partitions (1.290.0) + aws-sdk-core (3.92.0) aws-eventstream (~> 1.0, >= 1.0.2) - azure_mgmt_compute (0.19.0) + aws-partitions (~> 1, >= 1.239.0) + aws-sigv4 (~> 1.1) + jmespath (~> 1.0) + aws-sdk-ec2 (1.151.0) + aws-sdk-core (~> 3, >= 3.71.0) + aws-sigv4 (~> 1.1) + aws-sigv4 (1.1.1) + aws-eventstream (~> 1.0, >= 1.0.2) + azure_mgmt_compute (0.19.1) ms_rest_azure (~> 0.11.1) azure_mgmt_monitor (0.17.5) ms_rest_azure (~> 0.11.1) - azure_mgmt_network (0.23.0) + azure_mgmt_network (0.23.1) ms_rest_azure (~> 0.11.1) azure_mgmt_resources (0.17.8) ms_rest_azure (~> 0.11.1) - azure_mgmt_storage (0.19.2) + azure_mgmt_storage (0.19.3) ms_rest_azure (~> 0.11.1) builder (3.2.4) chunky_png (1.3.11) @@ -69,22 +71,22 @@ GEM mime-types-data (3.2019.1009) mini_portile2 (2.4.0) minitest (5.14.0) - ms_rest (0.7.5) + ms_rest (0.7.6) concurrent-ruby (~> 1.0) - faraday (~> 0.9) + faraday (>= 0.9, < 2.0.0) timeliness (~> 0.3.10) - ms_rest_azure (0.11.1) + ms_rest_azure (0.11.2) concurrent-ruby (~> 1.0) - faraday (~> 0.9) + faraday (>= 0.9, < 2.0.0) faraday-cookie_jar (~> 0.0.6) - ms_rest (~> 0.7.4) + ms_rest (~> 0.7.6) unf_ext (= 0.0.7.2) multipart-post (2.1.1) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) mysql2 (0.5.3) net-ldap (0.16.2) - nokogiri (1.10.8) + nokogiri (1.10.9) mini_portile2 (~> 2.4.0) optimist (3.0.0) ox (2.13.2) @@ -104,9 +106,9 @@ GEM rqrcode (1.1.2) chunky_png (~> 1.0) rqrcode_core (~> 0.1) - rqrcode_core (0.1.1) + rqrcode_core (0.1.2) ruby2_keywords (0.0.2) - sequel (5.29.0) + sequel (5.30.0) sinatra (2.0.8.1) mustermann (~> 1.0) rack (~> 2.0) @@ -143,7 +145,7 @@ DEPENDENCIES activesupport (~> 4.2) amazon-ec2 augeas (~> 0.6) - aws-sdk (~> 2.5) + aws-sdk-ec2 (>= 1.151) azure_mgmt_compute azure_mgmt_monitor azure_mgmt_network diff --git a/share/install_gems/Gemfile b/share/install_gems/Gemfile index d8b3b1d35b..202561bed3 100644 --- a/share/install_gems/Gemfile +++ b/share/install_gems/Gemfile @@ -68,7 +68,7 @@ gem 'azure_mgmt_resources' # hybrid gem 'azure_mgmt_storage' # hybrid gem 'rbvmomi', '~> 2.2.0' # vmware gem 'parse-cron' # oneflow -gem 'aws-sdk', '~> 2.5' # ec2_hybrid +gem 'aws-sdk-ec2', '>=1.151' # ec2_hybrid gem 'ox' # oca gem 'highline', '~> 1.7' # oneprovision gem 'faraday', '~> 0.15' # packethost diff --git a/share/install_gems/Ubuntu1604/Gemfile.lock b/share/install_gems/Ubuntu1604/Gemfile.lock index d47e984175..4143482d15 100644 --- a/share/install_gems/Ubuntu1604/Gemfile.lock +++ b/share/install_gems/Ubuntu1604/Gemfile.lock @@ -12,24 +12,26 @@ GEM xml-simple (>= 1.0.12) augeas (0.6.4) aws-eventstream (1.0.3) - aws-sdk (2.11.446) - aws-sdk-resources (= 2.11.446) - aws-sdk-core (2.11.446) - aws-sigv4 (~> 1.0) - jmespath (~> 1.0) - aws-sdk-resources (2.11.446) - aws-sdk-core (= 2.11.446) - aws-sigv4 (1.1.0) + aws-partitions (1.290.0) + aws-sdk-core (3.92.0) aws-eventstream (~> 1.0, >= 1.0.2) - azure_mgmt_compute (0.19.0) + aws-partitions (~> 1, >= 1.239.0) + aws-sigv4 (~> 1.1) + jmespath (~> 1.0) + aws-sdk-ec2 (1.151.0) + aws-sdk-core (~> 3, >= 3.71.0) + aws-sigv4 (~> 1.1) + aws-sigv4 (1.1.1) + aws-eventstream (~> 1.0, >= 1.0.2) + azure_mgmt_compute (0.19.1) ms_rest_azure (~> 0.11.1) azure_mgmt_monitor (0.17.5) ms_rest_azure (~> 0.11.1) - azure_mgmt_network (0.23.0) + azure_mgmt_network (0.23.1) ms_rest_azure (~> 0.11.1) azure_mgmt_resources (0.17.8) ms_rest_azure (~> 0.11.1) - azure_mgmt_storage (0.19.2) + azure_mgmt_storage (0.19.3) ms_rest_azure (~> 0.11.1) builder (3.2.4) chunky_png (1.3.11) @@ -69,22 +71,22 @@ GEM mime-types-data (3.2019.1009) mini_portile2 (2.4.0) minitest (5.14.0) - ms_rest (0.7.5) + ms_rest (0.7.6) concurrent-ruby (~> 1.0) - faraday (~> 0.9) + faraday (>= 0.9, < 2.0.0) timeliness (~> 0.3.10) - ms_rest_azure (0.11.1) + ms_rest_azure (0.11.2) concurrent-ruby (~> 1.0) - faraday (~> 0.9) + faraday (>= 0.9, < 2.0.0) faraday-cookie_jar (~> 0.0.6) - ms_rest (~> 0.7.4) + ms_rest (~> 0.7.6) unf_ext (= 0.0.7.2) multipart-post (2.1.1) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) mysql2 (0.5.3) net-ldap (0.16.2) - nokogiri (1.10.8) + nokogiri (1.10.9) mini_portile2 (~> 2.4.0) optimist (3.0.0) ox (2.13.2) @@ -104,9 +106,9 @@ GEM rqrcode (1.1.2) chunky_png (~> 1.0) rqrcode_core (~> 0.1) - rqrcode_core (0.1.1) + rqrcode_core (0.1.2) ruby2_keywords (0.0.2) - sequel (5.29.0) + sequel (5.30.0) sinatra (2.0.8.1) mustermann (~> 1.0) rack (~> 2.0) @@ -143,7 +145,7 @@ DEPENDENCIES activesupport (~> 4.2) amazon-ec2 augeas (~> 0.6) - aws-sdk (~> 2.5) + aws-sdk-ec2 (>= 1.151) azure_mgmt_compute azure_mgmt_monitor azure_mgmt_network diff --git a/share/install_gems/Ubuntu1804/Gemfile.lock b/share/install_gems/Ubuntu1804/Gemfile.lock index 668638efd2..bbe6b74060 100644 --- a/share/install_gems/Ubuntu1804/Gemfile.lock +++ b/share/install_gems/Ubuntu1804/Gemfile.lock @@ -12,24 +12,26 @@ GEM xml-simple (>= 1.0.12) augeas (0.6.4) aws-eventstream (1.0.3) - aws-sdk (2.11.446) - aws-sdk-resources (= 2.11.446) - aws-sdk-core (2.11.446) - aws-sigv4 (~> 1.0) - jmespath (~> 1.0) - aws-sdk-resources (2.11.446) - aws-sdk-core (= 2.11.446) - aws-sigv4 (1.1.0) + aws-partitions (1.290.0) + aws-sdk-core (3.92.0) aws-eventstream (~> 1.0, >= 1.0.2) - azure_mgmt_compute (0.19.0) + aws-partitions (~> 1, >= 1.239.0) + aws-sigv4 (~> 1.1) + jmespath (~> 1.0) + aws-sdk-ec2 (1.151.0) + aws-sdk-core (~> 3, >= 3.71.0) + aws-sigv4 (~> 1.1) + aws-sigv4 (1.1.1) + aws-eventstream (~> 1.0, >= 1.0.2) + azure_mgmt_compute (0.19.1) ms_rest_azure (~> 0.11.1) azure_mgmt_monitor (0.17.5) ms_rest_azure (~> 0.11.1) - azure_mgmt_network (0.23.0) + azure_mgmt_network (0.23.1) ms_rest_azure (~> 0.11.1) azure_mgmt_resources (0.17.8) ms_rest_azure (~> 0.11.1) - azure_mgmt_storage (0.19.2) + azure_mgmt_storage (0.19.3) ms_rest_azure (~> 0.11.1) builder (3.2.4) chunky_png (1.3.11) @@ -69,22 +71,22 @@ GEM mime-types-data (3.2019.1009) mini_portile2 (2.4.0) minitest (5.14.0) - ms_rest (0.7.5) + ms_rest (0.7.6) concurrent-ruby (~> 1.0) - faraday (~> 0.9) + faraday (>= 0.9, < 2.0.0) timeliness (~> 0.3.10) - ms_rest_azure (0.11.1) + ms_rest_azure (0.11.2) concurrent-ruby (~> 1.0) - faraday (~> 0.9) + faraday (>= 0.9, < 2.0.0) faraday-cookie_jar (~> 0.0.6) - ms_rest (~> 0.7.4) + ms_rest (~> 0.7.6) unf_ext (= 0.0.7.2) multipart-post (2.1.1) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) mysql2 (0.5.3) net-ldap (0.16.2) - nokogiri (1.10.8) + nokogiri (1.10.9) mini_portile2 (~> 2.4.0) optimist (3.0.0) ox (2.13.2) @@ -104,9 +106,9 @@ GEM rqrcode (1.1.2) chunky_png (~> 1.0) rqrcode_core (~> 0.1) - rqrcode_core (0.1.1) + rqrcode_core (0.1.2) ruby2_keywords (0.0.2) - sequel (5.29.0) + sequel (5.30.0) sinatra (2.0.8.1) mustermann (~> 1.0) rack (~> 2.0) @@ -144,7 +146,7 @@ DEPENDENCIES activesupport (~> 4.2) amazon-ec2 augeas (~> 0.6) - aws-sdk (~> 2.5) + aws-sdk-ec2 (>= 1.151) azure_mgmt_compute azure_mgmt_monitor azure_mgmt_network diff --git a/share/install_gems/Ubuntu1904/Gemfile.lock b/share/install_gems/Ubuntu1904/Gemfile.lock index 668638efd2..bbe6b74060 100644 --- a/share/install_gems/Ubuntu1904/Gemfile.lock +++ b/share/install_gems/Ubuntu1904/Gemfile.lock @@ -12,24 +12,26 @@ GEM xml-simple (>= 1.0.12) augeas (0.6.4) aws-eventstream (1.0.3) - aws-sdk (2.11.446) - aws-sdk-resources (= 2.11.446) - aws-sdk-core (2.11.446) - aws-sigv4 (~> 1.0) - jmespath (~> 1.0) - aws-sdk-resources (2.11.446) - aws-sdk-core (= 2.11.446) - aws-sigv4 (1.1.0) + aws-partitions (1.290.0) + aws-sdk-core (3.92.0) aws-eventstream (~> 1.0, >= 1.0.2) - azure_mgmt_compute (0.19.0) + aws-partitions (~> 1, >= 1.239.0) + aws-sigv4 (~> 1.1) + jmespath (~> 1.0) + aws-sdk-ec2 (1.151.0) + aws-sdk-core (~> 3, >= 3.71.0) + aws-sigv4 (~> 1.1) + aws-sigv4 (1.1.1) + aws-eventstream (~> 1.0, >= 1.0.2) + azure_mgmt_compute (0.19.1) ms_rest_azure (~> 0.11.1) azure_mgmt_monitor (0.17.5) ms_rest_azure (~> 0.11.1) - azure_mgmt_network (0.23.0) + azure_mgmt_network (0.23.1) ms_rest_azure (~> 0.11.1) azure_mgmt_resources (0.17.8) ms_rest_azure (~> 0.11.1) - azure_mgmt_storage (0.19.2) + azure_mgmt_storage (0.19.3) ms_rest_azure (~> 0.11.1) builder (3.2.4) chunky_png (1.3.11) @@ -69,22 +71,22 @@ GEM mime-types-data (3.2019.1009) mini_portile2 (2.4.0) minitest (5.14.0) - ms_rest (0.7.5) + ms_rest (0.7.6) concurrent-ruby (~> 1.0) - faraday (~> 0.9) + faraday (>= 0.9, < 2.0.0) timeliness (~> 0.3.10) - ms_rest_azure (0.11.1) + ms_rest_azure (0.11.2) concurrent-ruby (~> 1.0) - faraday (~> 0.9) + faraday (>= 0.9, < 2.0.0) faraday-cookie_jar (~> 0.0.6) - ms_rest (~> 0.7.4) + ms_rest (~> 0.7.6) unf_ext (= 0.0.7.2) multipart-post (2.1.1) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) mysql2 (0.5.3) net-ldap (0.16.2) - nokogiri (1.10.8) + nokogiri (1.10.9) mini_portile2 (~> 2.4.0) optimist (3.0.0) ox (2.13.2) @@ -104,9 +106,9 @@ GEM rqrcode (1.1.2) chunky_png (~> 1.0) rqrcode_core (~> 0.1) - rqrcode_core (0.1.1) + rqrcode_core (0.1.2) ruby2_keywords (0.0.2) - sequel (5.29.0) + sequel (5.30.0) sinatra (2.0.8.1) mustermann (~> 1.0) rack (~> 2.0) @@ -144,7 +146,7 @@ DEPENDENCIES activesupport (~> 4.2) amazon-ec2 augeas (~> 0.6) - aws-sdk (~> 2.5) + aws-sdk-ec2 (>= 1.151) azure_mgmt_compute azure_mgmt_monitor azure_mgmt_network diff --git a/share/install_gems/Ubuntu1910/Gemfile.lock b/share/install_gems/Ubuntu1910/Gemfile.lock index 668638efd2..bbe6b74060 100644 --- a/share/install_gems/Ubuntu1910/Gemfile.lock +++ b/share/install_gems/Ubuntu1910/Gemfile.lock @@ -12,24 +12,26 @@ GEM xml-simple (>= 1.0.12) augeas (0.6.4) aws-eventstream (1.0.3) - aws-sdk (2.11.446) - aws-sdk-resources (= 2.11.446) - aws-sdk-core (2.11.446) - aws-sigv4 (~> 1.0) - jmespath (~> 1.0) - aws-sdk-resources (2.11.446) - aws-sdk-core (= 2.11.446) - aws-sigv4 (1.1.0) + aws-partitions (1.290.0) + aws-sdk-core (3.92.0) aws-eventstream (~> 1.0, >= 1.0.2) - azure_mgmt_compute (0.19.0) + aws-partitions (~> 1, >= 1.239.0) + aws-sigv4 (~> 1.1) + jmespath (~> 1.0) + aws-sdk-ec2 (1.151.0) + aws-sdk-core (~> 3, >= 3.71.0) + aws-sigv4 (~> 1.1) + aws-sigv4 (1.1.1) + aws-eventstream (~> 1.0, >= 1.0.2) + azure_mgmt_compute (0.19.1) ms_rest_azure (~> 0.11.1) azure_mgmt_monitor (0.17.5) ms_rest_azure (~> 0.11.1) - azure_mgmt_network (0.23.0) + azure_mgmt_network (0.23.1) ms_rest_azure (~> 0.11.1) azure_mgmt_resources (0.17.8) ms_rest_azure (~> 0.11.1) - azure_mgmt_storage (0.19.2) + azure_mgmt_storage (0.19.3) ms_rest_azure (~> 0.11.1) builder (3.2.4) chunky_png (1.3.11) @@ -69,22 +71,22 @@ GEM mime-types-data (3.2019.1009) mini_portile2 (2.4.0) minitest (5.14.0) - ms_rest (0.7.5) + ms_rest (0.7.6) concurrent-ruby (~> 1.0) - faraday (~> 0.9) + faraday (>= 0.9, < 2.0.0) timeliness (~> 0.3.10) - ms_rest_azure (0.11.1) + ms_rest_azure (0.11.2) concurrent-ruby (~> 1.0) - faraday (~> 0.9) + faraday (>= 0.9, < 2.0.0) faraday-cookie_jar (~> 0.0.6) - ms_rest (~> 0.7.4) + ms_rest (~> 0.7.6) unf_ext (= 0.0.7.2) multipart-post (2.1.1) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) mysql2 (0.5.3) net-ldap (0.16.2) - nokogiri (1.10.8) + nokogiri (1.10.9) mini_portile2 (~> 2.4.0) optimist (3.0.0) ox (2.13.2) @@ -104,9 +106,9 @@ GEM rqrcode (1.1.2) chunky_png (~> 1.0) rqrcode_core (~> 0.1) - rqrcode_core (0.1.1) + rqrcode_core (0.1.2) ruby2_keywords (0.0.2) - sequel (5.29.0) + sequel (5.30.0) sinatra (2.0.8.1) mustermann (~> 1.0) rack (~> 2.0) @@ -144,7 +146,7 @@ DEPENDENCIES activesupport (~> 4.2) amazon-ec2 augeas (~> 0.6) - aws-sdk (~> 2.5) + aws-sdk-ec2 (>= 1.151) azure_mgmt_compute azure_mgmt_monitor azure_mgmt_network diff --git a/src/im_mad/remotes/az.d/poll b/src/im_mad/remotes/az-probes.d/host/monitor/probe_host_monitor.rb similarity index 69% rename from src/im_mad/remotes/az.d/poll rename to src/im_mad/remotes/az-probes.d/host/monitor/probe_host_monitor.rb index 5ae91bcd73..a70b3fd462 100755 --- a/src/im_mad/remotes/az.d/poll +++ b/src/im_mad/remotes/az-probes.d/host/monitor/probe_host_monitor.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # -------------------------------------------------------------------------- # -# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems # +# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems # # # # 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 # @@ -16,14 +16,14 @@ # limitations under the License. # # -------------------------------------------------------------------------- # -ONE_LOCATION = ENV['ONE_LOCATION'] if !defined?(ONE_LOCATION) +ONE_LOCATION ||= ENV['ONE_LOCATION'] if !defined? ONE_LOCATION if !ONE_LOCATION - RUBY_LIB_LOCATION = '/usr/lib/one/ruby' if !defined?(RUBY_LIB_LOCATION) - GEMS_LOCATION = '/usr/share/one/gems' if !defined?(GEMS_LOCATION) + RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby' + GEMS_LOCATION ||= '/usr/share/one/gems' else - RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' if !defined?(RUBY_LIB_LOCATION) - GEMS_LOCATION = ONE_LOCATION + '/share/gems' if !defined?(GEMS_LOCATION) + RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby' + GEMS_LOCATION ||= ONE_LOCATION + '/share/gems' end if File.directory?(GEMS_LOCATION) @@ -34,11 +34,12 @@ $LOAD_PATH << RUBY_LIB_LOCATION require 'az_driver' -host = ARGV[-1] -az_drv = AzureDriver.new(host) +host = ARGV[-1] +host_id = ARGV[-2] +az_drv = AzureDriver.new(host, host_id) begin - az_drv.monitor_all_vms + puts az_drv.probe_host_monitor rescue => e - OpenNebula.handle_driver_exception("im poll", e, host) + OpenNebula.handle_driver_exception("im probe_host_monitor", e, host) end diff --git a/src/im_mad/remotes/az-probes.d/host/system/probe_host_system.rb b/src/im_mad/remotes/az-probes.d/host/system/probe_host_system.rb new file mode 100755 index 0000000000..241abc68c2 --- /dev/null +++ b/src/im_mad/remotes/az-probes.d/host/system/probe_host_system.rb @@ -0,0 +1,45 @@ +#!/usr/bin/env ruby + +# -------------------------------------------------------------------------- # +# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems # +# # +# 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 !defined? ONE_LOCATION + +if !ONE_LOCATION + RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby' + GEMS_LOCATION ||= '/usr/share/one/gems' +else + RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby' + GEMS_LOCATION ||= ONE_LOCATION + '/share/gems' +end + +if File.directory?(GEMS_LOCATION) + Gem.use_paths(GEMS_LOCATION) +end + +$LOAD_PATH << RUBY_LIB_LOCATION + +require 'az_driver' + +host = ARGV[-1] +host_id = ARGV[-2] +az_drv = AzureDriver.new(host, host_id) + +begin + puts az_drv.probe_host_system +rescue => e + OpenNebula.handle_driver_exception("im probe_host_system", e, host) +end diff --git a/src/im_mad/remotes/az-probes.d/vm/monitor/probe_vm_monitor.rb b/src/im_mad/remotes/az-probes.d/vm/monitor/probe_vm_monitor.rb new file mode 100755 index 0000000000..887ad5cf8e --- /dev/null +++ b/src/im_mad/remotes/az-probes.d/vm/monitor/probe_vm_monitor.rb @@ -0,0 +1,45 @@ +#!/usr/bin/env ruby + +# -------------------------------------------------------------------------- # +# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems # +# # +# 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 !defined? ONE_LOCATION + +if !ONE_LOCATION + RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby' + GEMS_LOCATION ||= '/usr/share/one/gems' +else + RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby' + GEMS_LOCATION ||= ONE_LOCATION + '/share/gems' +end + +if File.directory?(GEMS_LOCATION) + Gem.use_paths(GEMS_LOCATION) +end + +$LOAD_PATH << RUBY_LIB_LOCATION + +require 'az_driver' + +host = ARGV[-1] +host_id = ARGV[-2] +az_drv = AzureDriver.new(host, host_id) + +begin + puts az_drv.probe_vm_monitor +rescue => e + OpenNebula.handle_driver_exception("im probe_vm_monitor", e, host) +end diff --git a/src/im_mad/remotes/az-probes.d/vm/status/probe_vm_status.rb b/src/im_mad/remotes/az-probes.d/vm/status/probe_vm_status.rb new file mode 100755 index 0000000000..58ac85cb2b --- /dev/null +++ b/src/im_mad/remotes/az-probes.d/vm/status/probe_vm_status.rb @@ -0,0 +1,49 @@ +#!/usr/bin/env ruby + +# -------------------------------------------------------------------------- # +# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems # +# # +# 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 !defined? ONE_LOCATION + +if !ONE_LOCATION + RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby' + GEMS_LOCATION ||= '/usr/share/one/gems' +else + RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby' + GEMS_LOCATION ||= ONE_LOCATION + '/share/gems' +end + +if File.directory?(GEMS_LOCATION) + Gem.use_paths(GEMS_LOCATION) +end + +$LOAD_PATH << RUBY_LIB_LOCATION + +require 'az_driver' +require_relative '../../../lib/probe_db' + +host = ARGV[-1] +host_id = ARGV[-2] + +begin + vmdb = VirtualMachineDB.new('az', + :missing_state => 'UNKNOWN', + :sync => 180) + vmdb.purge + puts vmdb.to_status(host, host_id) +rescue => e + OpenNebula.handle_driver_exception("im probe_vm_status", e, host) +end diff --git a/src/im_mad/remotes/az.d/monitord-client.rb b/src/im_mad/remotes/az.d/monitord-client.rb new file mode 120000 index 0000000000..83ff041040 --- /dev/null +++ b/src/im_mad/remotes/az.d/monitord-client.rb @@ -0,0 +1 @@ +../common.d/monitord-client.rb \ No newline at end of file diff --git a/src/im_mad/remotes/az.d/monitord-client_control.sh b/src/im_mad/remotes/az.d/monitord-client_control.sh new file mode 120000 index 0000000000..23e6d7e502 --- /dev/null +++ b/src/im_mad/remotes/az.d/monitord-client_control.sh @@ -0,0 +1 @@ +../common.d/monitord-client_control.sh \ No newline at end of file diff --git a/src/im_mad/remotes/common.d/monitord-client.rb b/src/im_mad/remotes/common.d/monitord-client.rb index 57f4c47e19..b54a98ac4e 100644 --- a/src/im_mad/remotes/common.d/monitord-client.rb +++ b/src/im_mad/remotes/common.d/monitord-client.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # -------------------------------------------------------------------------- # -# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems # +# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems # # # # 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 # @@ -29,9 +29,10 @@ require 'rexml/document' require_relative '../lib/probe_db' +#------------------------------------------------------------------------------- # This class represents a monitord client. It handles udp and tcp connections # and send update messages to monitord -# +#------------------------------------------------------------------------------- class MonitorClient # Defined in src/monitor/include/MonitorDriverMessages.h @@ -110,9 +111,10 @@ class MonitorClient end +#------------------------------------------------------------------------------- # This class wraps the execution of a probe directory and sends data to # monitord (optionally) -# +#------------------------------------------------------------------------------- class ProbeRunner def initialize(hyperv, path, stdin) @@ -212,26 +214,32 @@ class ProbeRunner end +#------------------------------------------------------------------------------- +# Script helper functions and gLobals +#------------------------------------------------------------------------------- +LOCAL_HYPERVISOR = %w[az ec2 packet].freeze + +def local?(hypervisor) + LOCAL_HYPERVISOR.include?(hypervisor) +end + #------------------------------------------------------------------------------- # Configuration (from monitord) #------------------------------------------------------------------------------- xml_txt = STDIN.read begin - config = REXML::Document.new(xml_txt).root + hyperv = ARGV[0].split(' ')[0] + + xml_txt = Base64.decode64(xml_txt) if local? hyperv + config = REXML::Document.new(xml_txt).root host = config.elements['UDP_LISTENER/MONITOR_ADDRESS'].text.to_s port = config.elements['UDP_LISTENER/PORT'].text.to_s pubkey = config.elements['UDP_LISTENER/PUBKEY'].text.to_s hostid = config.elements['HOST_ID'].text.to_s - hyperv = ARGV[0].split(' ')[0] probes = { - :beacon_host_udp => { - :period => config.elements['PROBES_PERIOD/BEACON_HOST'].text.to_s, - :path => 'host/beacon' - }, - :system_host_udp => { :period => config.elements['PROBES_PERIOD/SYSTEM_HOST'].text.to_s, :path => 'host/system' @@ -253,6 +261,11 @@ begin } } + probes[:beacon_host_udp] = { + :period => config.elements['PROBES_PERIOD/BEACON_HOST'].text.to_s, + :path => 'host/beacon' + } unless local? hyperv + if !pubkey.empty? exp = /(-+BEGIN RSA PUBLIC KEY-+)([^-]*)(-+END RSA PUBLIC KEY-+)/ m = pubkey.match(exp) diff --git a/src/im_mad/remotes/common.d/monitord-client_control.sh b/src/im_mad/remotes/common.d/monitord-client_control.sh index f3bfb85ade..fa6611a003 100755 --- a/src/im_mad/remotes/common.d/monitord-client_control.sh +++ b/src/im_mad/remotes/common.d/monitord-client_control.sh @@ -1,7 +1,7 @@ #!/bin/bash # -------------------------------------------------------------------------- # -# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems # +# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems # # # # 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 # diff --git a/src/im_mad/remotes/ec2.d/poll b/src/im_mad/remotes/ec2-probes.d/host/monitor/probe_host_monitor.rb similarity index 72% rename from src/im_mad/remotes/ec2.d/poll rename to src/im_mad/remotes/ec2-probes.d/host/monitor/probe_host_monitor.rb index 680321dcb9..caedab7cf3 100755 --- a/src/im_mad/remotes/ec2.d/poll +++ b/src/im_mad/remotes/ec2-probes.d/host/monitor/probe_host_monitor.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # -------------------------------------------------------------------------- # -# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems # +# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems # # # # 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 # @@ -16,14 +16,14 @@ # limitations under the License. # # -------------------------------------------------------------------------- # -ONE_LOCATION = ENV['ONE_LOCATION'] if !defined?(ONE_LOCATION) +ONE_LOCATION ||= ENV['ONE_LOCATION'] if !defined? ONE_LOCATION if !ONE_LOCATION - RUBY_LIB_LOCATION = '/usr/lib/one/ruby' if !defined?(RUBY_LIB_LOCATION) - GEMS_LOCATION = '/usr/share/one/gems' if !defined?(GEMS_LOCATION) + RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby' + GEMS_LOCATION ||= '/usr/share/one/gems' else - RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' if !defined?(RUBY_LIB_LOCATION) - GEMS_LOCATION = ONE_LOCATION + '/share/gems' if !defined?(GEMS_LOCATION) + RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby' + GEMS_LOCATION ||= ONE_LOCATION + '/share/gems' end if File.directory?(GEMS_LOCATION) @@ -39,8 +39,8 @@ host_id = ARGV[-2] ec2_drv = EC2Driver.new(host, host_id) begin - ec2_drv.monitor_all_vms + puts ec2_drv.probe_host_monitor rescue Exception => e - OpenNebula.handle_driver_exception("im poll", e, host) + OpenNebula.handle_driver_exception("im probe_host_monitor", e, host) end diff --git a/src/im_mad/remotes/ec2-probes.d/host/system/probe_host_system.rb b/src/im_mad/remotes/ec2-probes.d/host/system/probe_host_system.rb new file mode 100755 index 0000000000..0997171b8e --- /dev/null +++ b/src/im_mad/remotes/ec2-probes.d/host/system/probe_host_system.rb @@ -0,0 +1,47 @@ +#!/usr/bin/env ruby + +# -------------------------------------------------------------------------- # +# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems # +# # +# 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 !defined? ONE_LOCATION + +if !ONE_LOCATION + RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby' + GEMS_LOCATION ||= '/usr/share/one/gems' +else + RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby' + GEMS_LOCATION ||= ONE_LOCATION + '/share/gems' +end + +if File.directory?(GEMS_LOCATION) + Gem.use_paths(GEMS_LOCATION) +end + +$LOAD_PATH << RUBY_LIB_LOCATION + + +require 'ec2_driver' + +host = ARGV[-1] +host_id = ARGV[-2] +ec2_drv = EC2Driver.new(host, host_id) + +begin + puts ec2_drv.probe_host_system +rescue Exception => e + + OpenNebula.handle_driver_exception("im probe_host_system", e, host) +end diff --git a/src/im_mad/remotes/ec2-probes.d/vm/monitor/probe_vm_monitor.rb b/src/im_mad/remotes/ec2-probes.d/vm/monitor/probe_vm_monitor.rb new file mode 100755 index 0000000000..f5e29376fc --- /dev/null +++ b/src/im_mad/remotes/ec2-probes.d/vm/monitor/probe_vm_monitor.rb @@ -0,0 +1,46 @@ +#!/usr/bin/env ruby + +# -------------------------------------------------------------------------- # +# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems # +# # +# 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 !defined? ONE_LOCATION + +if !ONE_LOCATION + RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby' + GEMS_LOCATION ||= '/usr/share/one/gems' +else + RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby' + GEMS_LOCATION ||= ONE_LOCATION + '/share/gems' +end + +if File.directory?(GEMS_LOCATION) + Gem.use_paths(GEMS_LOCATION) +end + +$LOAD_PATH << RUBY_LIB_LOCATION + +require 'ec2_driver' + +host = ARGV[-1] +host_id = ARGV[-2] +ec2_drv = EC2Driver.new(host, host_id) + +begin + puts ec2_drv.probe_vm_monitor +rescue Exception => e + + OpenNebula.handle_driver_exception("im probe_vm_monitor", e, host) +end diff --git a/src/im_mad/remotes/ec2-probes.d/vm/status/probe_vm_status.rb b/src/im_mad/remotes/ec2-probes.d/vm/status/probe_vm_status.rb new file mode 100755 index 0000000000..fd4bc35032 --- /dev/null +++ b/src/im_mad/remotes/ec2-probes.d/vm/status/probe_vm_status.rb @@ -0,0 +1,49 @@ +#!/usr/bin/env ruby + +# -------------------------------------------------------------------------- # +# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems # +# # +# 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 !defined? ONE_LOCATION + +if !ONE_LOCATION + RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby' + GEMS_LOCATION ||= '/usr/share/one/gems' +else + RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby' + GEMS_LOCATION ||= ONE_LOCATION + '/share/gems' +end + +if File.directory?(GEMS_LOCATION) + Gem.use_paths(GEMS_LOCATION) +end + +$LOAD_PATH << RUBY_LIB_LOCATION + +require 'ec2_driver' +require_relative '../../../lib/probe_db' + +host = ARGV[-1] +host_id = ARGV[-2] + +begin + vmdb = VirtualMachineDB.new('ec2', + :missing_state => 'UNKNOWN', + :sync => 180) + vmdb.purge + puts vmdb.to_status(host, host_id) +rescue => e + OpenNebula.handle_driver_exception("im probe_vm_status", e, host) +end diff --git a/src/im_mad/remotes/ec2.d/monitord-client.rb b/src/im_mad/remotes/ec2.d/monitord-client.rb new file mode 120000 index 0000000000..83ff041040 --- /dev/null +++ b/src/im_mad/remotes/ec2.d/monitord-client.rb @@ -0,0 +1 @@ +../common.d/monitord-client.rb \ No newline at end of file diff --git a/src/im_mad/remotes/ec2.d/monitord-client_control.sh b/src/im_mad/remotes/ec2.d/monitord-client_control.sh new file mode 120000 index 0000000000..23e6d7e502 --- /dev/null +++ b/src/im_mad/remotes/ec2.d/monitord-client_control.sh @@ -0,0 +1 @@ +../common.d/monitord-client_control.sh \ No newline at end of file diff --git a/src/im_mad/remotes/firecracker-probes.d/vm/status/state.rb b/src/im_mad/remotes/firecracker-probes.d/vm/status/state.rb index 24cdf807f2..b9c19d40b9 100755 --- a/src/im_mad/remotes/firecracker-probes.d/vm/status/state.rb +++ b/src/im_mad/remotes/firecracker-probes.d/vm/status/state.rb @@ -4,6 +4,8 @@ require_relative '../../../lib/probe_db' require_relative '../../../lib/firecracker' xml_txt = STDIN.read +host = ARGV[-1] +host_id = ARGV[-2] begin config = REXML::Document.new(xml_txt).root @@ -18,7 +20,7 @@ begin :sync => sync) vmdb.purge - puts vmdb.to_status + puts vmdb.to_status(host, host_id) rescue StandardError => e puts e end diff --git a/src/im_mad/remotes/kvm-probes.d/vm/status/state.rb b/src/im_mad/remotes/kvm-probes.d/vm/status/state.rb index 61572212bb..138042bd26 100755 --- a/src/im_mad/remotes/kvm-probes.d/vm/status/state.rb +++ b/src/im_mad/remotes/kvm-probes.d/vm/status/state.rb @@ -4,6 +4,8 @@ require_relative '../../../lib/kvm' require_relative '../../../lib/probe_db' xml_txt = STDIN.read +host = ARGV[-1] +host_id = ARGV[-2] begin config = REXML::Document.new(xml_txt).root @@ -20,7 +22,7 @@ begin :sync => sync) vmdb.purge - puts vmdb.to_status + puts vmdb.to_status(host, host_id) rescue StandardError => e puts e end diff --git a/src/im_mad/remotes/lib/firecracker.rb b/src/im_mad/remotes/lib/firecracker.rb index fb7c02032b..70924f4b21 100644 --- a/src/im_mad/remotes/lib/firecracker.rb +++ b/src/im_mad/remotes/lib/firecracker.rb @@ -385,7 +385,7 @@ module DomainList domains.to_monitor end - def self.state_info + def self.state_info(host, host_id) domains = FirecrackerDomains.new domains.state_info diff --git a/src/im_mad/remotes/lib/kvm.rb b/src/im_mad/remotes/lib/kvm.rb index a4640d2a83..b05e62a557 100644 --- a/src/im_mad/remotes/lib/kvm.rb +++ b/src/im_mad/remotes/lib/kvm.rb @@ -449,7 +449,7 @@ module DomainList domains.wilds_to_monitor end - def self.state_info + def self.state_info(host, host_id) domains = KVMDomains.new domains.state_info @@ -501,10 +501,6 @@ module DomainList end end - # Get the list of VMs (known and not known to OpenNebula) and their info - # not including process usage. - # - # @return [Hash] with KVM Domain classes indexed by their uuid def state_info info_each(false) do |name| vm = Domain.new name diff --git a/src/im_mad/remotes/lib/probe_db.rb b/src/im_mad/remotes/lib/probe_db.rb index 782af6c313..167911b5c0 100644 --- a/src/im_mad/remotes/lib/probe_db.rb +++ b/src/im_mad/remotes/lib/probe_db.rb @@ -1,7 +1,7 @@ #!/usr/bin/ruby # -------------------------------------------------------------------------- # -# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems # +# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems # # # # 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 # @@ -16,14 +16,14 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -ONE_LOCATION = ENV['ONE_LOCATION'] +ONE_LOCATION = ENV['ONE_LOCATION'] if !defined? ONE_LOCATION if !ONE_LOCATION - RUBY_LIB_LOCATION = '/usr/lib/one/ruby' - GEMS_LOCATION = '/usr/share/one/gems' + RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby' + GEMS_LOCATION ||= '/usr/share/one/gems' else - RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' - GEMS_LOCATION = ONE_LOCATION + '/share/gems' + RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby' + GEMS_LOCATION ||= ONE_LOCATION + '/share/gems' end if File.directory?(GEMS_LOCATION) @@ -89,17 +89,17 @@ class VirtualMachineDB # Returns the VM status that changed compared to the DB info as well # as VMs that have been reported as missing more than missing_times - def to_status + def to_status(host, host_id) time = Time.now.to_i last = @db.execute("SELECT MAX(timestamp) from #{@dataset}").flatten![0] last ||= 0 - return sync_status if time > (last + @conf[:sync]) && last != 0 + return sync_status(host, host_id) if time > (last + @conf[:sync]) && last != 0 status_str = '' monitor_ids = [] - vms = DomainList.state_info + vms = DomainList.state_info(host, host_id) # ---------------------------------------------------------------------- # report state changes in vms @@ -108,7 +108,8 @@ class VirtualMachineDB if vm[:id] == -1 filter = "WHERE uuid = '#{uuid}'" else - filter = "WHERE id = '#{vm[:id]}'" + # in ec2 id could first be -1 but later added, check also uuid + filter = "WHERE id = '#{vm[:id]}' OR uuid = '#{uuid}'" end vm_db = @db.execute("SELECT * FROM #{@dataset} #{filter}").first @@ -191,14 +192,14 @@ class VirtualMachineDB private - def sync_status + def sync_status(host, host_id) time = Time.now.to_i @db.execute("DELETE FROM #{@dataset}") status_str = "SYNC_STATE=yes\nMISSING_STATE=#{@conf[:missing_state]}\n" - DomainList.state_info.each do |uuid, vm| + DomainList.state_info(host, host_id).each do |uuid, vm| @db.execute( "INSERT INTO #{@dataset} VALUES (?, ?, ?, ?, ?, ?, ?)", [uuid, diff --git a/src/im_mad/remotes/lxd-probes.d/vm/status/state.rb b/src/im_mad/remotes/lxd-probes.d/vm/status/state.rb index c66216f9cf..0197abdb55 100755 --- a/src/im_mad/remotes/lxd-probes.d/vm/status/state.rb +++ b/src/im_mad/remotes/lxd-probes.d/vm/status/state.rb @@ -20,7 +20,11 @@ module DomainList } # Returns a vm hash with the containers running in LXD - def self.state_info + # @param host [String] name of the host (not used here) + # @param host_id [Integer] ID of the host (not used here) + # + # @return [Hash] with KVM Domain classes indexed by their name + def self.state_info(host, host_id) containers = Container.get_all(LXD::CLIENT) return unless containers @@ -62,6 +66,8 @@ module DomainList end xml_txt = STDIN.read +host = ARGV[-1] +host_id = ARGV[-2] begin config = REXML::Document.new(xml_txt).root @@ -76,7 +82,7 @@ begin :sync => sync) vmdb.purge - puts vmdb.to_status + puts vmdb.to_status(host, host_id) rescue StandardError => e puts e end diff --git a/src/mad/ruby/PublicCloudDriver.rb b/src/mad/ruby/PublicCloudDriver.rb new file mode 100644 index 0000000000..189e000dc2 --- /dev/null +++ b/src/mad/ruby/PublicCloudDriver.rb @@ -0,0 +1,264 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems # +# # +# 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. # +#--------------------------------------------------------------------------- # +require 'sqlite3' + +# ------------------------------------------------------------------------------ +# Class for public drivers (AZ, EC2) It provides common interface to interact +# wiht the abstract host that representats a public cloud in OpenNebula +# ------------------------------------------------------------------------------ +module PublicCloudDriver + + #--------------------------------------------------------------------------- + # MODULE Main Interface + # -------------------------------------------------------------------------- + + # Returns host monitoring data + # + # @return [String] + def probe_host_monitor(db, limit, xmlhost) + total_cpu, total_mem = host_capacity(xmlhost) + used_cpu, used_mem = used_capacity(db, limit) + + data = "HYPERVISOR=#{@hypervisor}\n" + data << "PUBLIC_CLOUD=YES\n" + data << "USEDCPU=#{used_cpu}\n" + data << "USEDMEMORY=#{used_mem}\n" + data << "FREECPU=#{total_cpu - used_cpu}\n" + data << "FREEMEMORY=#{total_mem - used_mem}" + + data + end + + # Returns host information including wild VMs + # + # @return [String] + def probe_host_system(db, limit, xmlhost) + total_cpu, total_mem = host_capacity(xmlhost) + + data = "HYPERVISOR=#{@hypervisor}\n" + data << "PUBLIC_CLOUD=YES\n" + data << "TOTALCPU=#{total_cpu}\n" + data << "TOTALMEMORY=#{total_mem}\n" + + # include wild instances + vms = vms_data(db, limit) + vms.each do |vm| + next unless vm[:id] == -1 + + vm[:import_template] = vm_to_one(vm) + vm[:vm_name] = vm[:name] + + vm.delete(:name) + + data << hash_to_template(vm, 'VM = [ ', " ]\n") + end + + data + end + + # Returns VM monitor information + # + # @return [String] + def probe_vm_monitor + vms = fetch_vms_data(true) + + data = '' + vms.each do |vm| + data << hash_to_template(vm, 'VM = [ ', " ]\n") + end + + data + end + + #--------------------------------------------------------------------------- + # MODULE Helper functions + # -------------------------------------------------------------------------- + + # Either return VMs info from cache db or from public_cloud + def vms_data(db, time_limit) + return fetch_vms_data(false) if db.expired?(time_limit) + + db.select_vms + end + + # Return the information of a host in xml format + # @param host_id [Integer] ID of the host + # + # @return [Host, nil] + def host_info(host, host_id) + client = OpenNebula::Client.new + + if host_id.nil? + pool = OpenNebula::HostPool.new(client) + pool.info + objects = pool.select {|object| object.name==host } + host_id = objects.first.id + end + + xmlhost = OpenNebula::Host.new_with_id(host_id, client) + + rc = xmlhost.info(true) + + raise rc.to_str() if OpenNebula.is_error?(rc) + + xmlhost + end + + # Return count total cpu and memory based on instance type numbers in host + # template + # @param xmlhost [OpenNebula::XMLElement] xml host object + # + # @return [Array] total cpu, total memory + def host_capacity(xmlhost) + capacity = xmlhost.retrieve_xmlelements('/HOST/TEMPLATE/CAPACITY/*') + + raise 'Missing CAPACITY section in Host template' if capacity.nil? + + total_memory = total_cpu = 0 + + capacity.each do |element| + name = element.name + value = element.text + + name = parse_inst_type(name) if self.respond_to? :parse_inst_type + + cpu, mem = instance_type_capacity(name) + + total_memory += mem * value.to_i + total_cpu += cpu * value.to_i + end + + [total_cpu, total_memory] + end + + # Count cpu + mem of running instances + # + # @return [Array] used cpu, used memory + def used_capacity(db, limit) + vms = vms_data(db, limit) + + used_memory = used_cpu = 0 + + vms.each do |vm| + cpu, mem = instance_type_capacity(vm[:type]) + + used_memory += mem + used_cpu += cpu + end + + [used_cpu, used_memory] + end + + # Build template for importation + def vm_to_one(vm) + cpu, mem = instance_type_capacity(vm[:type]) + + mem = mem.to_i / 1024 # Memory for templates expressed in MB + cpu = cpu.to_f / 100 # CPU expressed in units + + str = "NAME = \"Instance from #{vm[:name]}\"\n"\ + "CPU = \"#{cpu}\"\n"\ + "vCPU = 1\n"\ + "MEMORY = \"#{mem}\"\n"\ + "PUBLIC_CLOUD = [\n"\ + " TYPE =\"#{@hypervisor}\"\n"\ + "]\n"\ + "IMPORT_VM_ID = \"#{vm[:uuid]}\"\n"\ + "SCHED_REQUIREMENTS = \"NAME=\\\"#{@host}\\\"\"\n"\ + "DESCRIPTION = \"Imported from #{@hypervisor} from #{vm[:name]}\"\n" + + Base64.strict_encode64(str) + end + + # Hash to ONE template format + def hash_to_template(h, pref = '', post = '') + tmpl = h.to_a.map {|e| "#{e[0].to_s.upcase}=\"#{e[1]}\"" }.join(', ') + pref + tmpl + post + end +end + +# ------------------------------------------------------------------------------ +# This class implements a simple local cache to store VM information +# ------------------------------------------------------------------------------ +class InstanceCache + + def initialize(path) + @db = SQLite3::Database.new(path) + + bootstrap + end + + def execute_retry(query, tries=5, tsleep=0.5) + i=0 + while i < tries + begin + return @db.execute(query) + rescue SQLite3::BusyException + i += 1 + sleep 0.5 + end + end + end + + #TODO document DB schema + def bootstrap + sql = 'CREATE TABLE IF NOT EXISTS vms(uuid VARCHAR(128) PRIMARY KEY,' + sql << ' id INTEGER, name VARCHAR(128), state VARCHAR(128),' + sql << ' type VARCHAR(128))' + execute_retry(sql) + + sql = 'CREATE TABLE IF NOT EXISTS timestamp(ts INTEGER PRIMARY KEY)' + execute_retry(sql) + end + + def insert(instances) + execute_retry('DELETE from vms') + instances.each do |i| + sql = 'INSERT INTO vms VALUES (' + sql << "\"#{i[:uuid]}\", " + sql << "\"#{i[:id]}\", " + sql << "\"#{i[:name]}\", " + sql << "\"#{i[:state]}\", " + sql << "\"#{i[:type]}\")" + + execute_retry(sql) + end + + execute_retry('DELETE from timestamp') + execute_retry("INSERT INTO timestamp VALUES (#{Time.now.to_i})") + end + + def select_vms() + vms = [] + execute_retry('SELECT * from vms').each do |vm| + vms << Hash[[:uuid, :id, :name, :state, :type].zip(vm)] + end + + vms + end + + # return true if the cache data expired + # + # @param[Integer] time_limit time to expire cache data + # + # @return[Boolean] + def expired?(time_limit) + ts = execute_retry('SELECT * from timestamp') + + ts.empty? || (Time.now.to_i - time_limit > ts.first.first) + end + +end diff --git a/src/vmm_mad/remotes/az/az_driver.conf b/src/vmm_mad/remotes/az/az_driver.conf index 7498f1aa60..b6e6f364e8 100644 --- a/src/vmm_mad/remotes/az/az_driver.conf +++ b/src/vmm_mad/remotes/az/az_driver.conf @@ -1,6 +1,6 @@ -proxy_uri: -rgroup_name_format: one-%s-%s -instance_types: +:proxy_uri: +:rgroup_name_format: one-%s-%s +:instance_types: Standard_B1ls: memory: 0.5 cpu: 1 diff --git a/src/vmm_mad/remotes/az/az_driver.rb b/src/vmm_mad/remotes/az/az_driver.rb index c726312be2..9799c415d3 100755 --- a/src/vmm_mad/remotes/az/az_driver.rb +++ b/src/vmm_mad/remotes/az/az_driver.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby # -------------------------------------------------------------------------- # -# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems # +# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems # # # # 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 # @@ -15,20 +15,23 @@ # limitations under the License. # # -------------------------------------------------------------------------- # -ONE_LOCATION ||= ENV['ONE_LOCATION'] +ONE_LOCATION ||= ENV['ONE_LOCATION'] if !defined? ONE_LOCATION if !ONE_LOCATION RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby' GEMS_LOCATION ||= '/usr/share/one/gems' ETC_LOCATION ||= '/etc/one/' + VAR_LOCATION ||= '/var/lib/one/' else - RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby' - GEMS_LOCATION ||= ONE_LOCATION + '/share/gems' - ETC_LOCATION ||= ONE_LOCATION + '/etc/' + RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby' if !defined?(RUBY_LIB_LOCATION) + GEMS_LOCATION ||= ONE_LOCATION + '/share/gems' if !defined?(GEMS_LOCATION) + ETC_LOCATION ||= ONE_LOCATION + '/etc/' if !defined?(ETC_LOCATION) + VAR_LOCATION ||= ONE_LOCATION + '/var/' if !defined?(VAR_LOCATION) end -AZ_DRIVER_CONF = "#{ETC_LOCATION}/az_driver.conf" +AZ_DRIVER_CONF = "#{ETC_LOCATION}/az_driver.conf" AZ_DRIVER_DEFAULT = "#{ETC_LOCATION}/az_driver.default" +AZ_DATABASE_PATH = "#{VAR_LOCATION}/remotes/im/az.d/az-cache.db" if File.directory?(GEMS_LOCATION) Gem.use_paths(GEMS_LOCATION) @@ -45,31 +48,20 @@ require 'tempfile' require 'CommandManager' require 'scripts_common' require 'VirtualMachineDriver' +require 'PublicCloudDriver' require 'opennebula' -require 'azure_mgmt_compute' -require 'azure_mgmt_monitor' -require 'azure_mgmt_network' -require 'azure_mgmt_resources' -require 'azure_mgmt_storage' - +#------------------------------------------------------------------------------- # The main class for the Azure driver +#------------------------------------------------------------------------------- class AzureDriver - ACTION = VirtualMachineDriver::ACTION + include PublicCloudDriver + + # -------------------------------------------------------------------------- + # Constants + # -------------------------------------------------------------------------- POLL_ATTRIBUTE = VirtualMachineDriver::POLL_ATTRIBUTE - VM_STATE = VirtualMachineDriver::VM_STATE - - Compute = Azure::Compute::Profiles::Latest::Mgmt - Monitor = Azure::Monitor::Profiles::Latest::Mgmt - Network = Azure::Network::Profiles::Latest::Mgmt - Resources = Azure::Resources::Profiles::Latest::Mgmt - Storage = Azure::Storage::Profiles::Latest::Mgmt - - ComputeModels = Compute::Models - NetworkModels = Network::Models - ResourceModels = Resources::Models - StorageModels = Storage::Models MONITOR_METRICS = [ 'Percentage CPU', @@ -87,45 +79,126 @@ class AzureDriver IMAGE_PUBLISHER IMAGE_OFFER IMAGE_SKU IMAGE_VERSION ] + DEFAULTS = { + :rgroup_name_format => 'one-%s-%s', + :cache_expire => 120 + } + + # -------------------------------------------------------------------------- # Azure constructor, loads credentials, create azure clients - def initialize(host) - @host = host - @to_inst ={} + # @param [String] name of host in OpenNebula + # @param [String] ID of host in OpenNebula + # -------------------------------------------------------------------------- + def initialize(host, id=nil) + @hypervisor = 'azure' + @host = host - @public_cloud_az_conf = YAML.safe_load(File.read(AZ_DRIVER_CONF)) + @to_inst = {} - if @public_cloud_az_conf['proxy_uri'] - ENV['HTTP_PROXY'] = @public_cloud_az_conf['proxy_uri'] - end + load_conf = YAML.safe_load(File.read(AZ_DRIVER_CONF), [Symbol]) + @az_conf = DEFAULTS + @az_conf.merge!(load_conf) + + ENV['HTTP_PROXY'] = @az_conf[:proxy_uri] if @az_conf[:proxy_uri] + + # ---------------------------------------------------------------------- + # Init instance types + # ---------------------------------------------------------------------- + @instance_types = @az_conf[:instance_types] - @instance_types = @public_cloud_az_conf['instance_types'] @instance_types.keys.each do |key| @to_inst[key.upcase] = key end - @xmlhost = host_info - @rgroup_name, @rgroup_keep_empty = rgroup_info + # ---------------------------------------------------------------------- + # Init OpenNebula host information & AZ_RGROUP + # ---------------------------------------------------------------------- + @xmlhost = host_info(host, id) - az_conn_opts = connect_info - @region = az_conn_opts[:region] + @rgroup_name = @xmlhost['TEMPLATE/AZ_RGROUP'] + keep_empty = @xmlhost['TEMPLATE/AZ_RGROUP_KEEP_EMPTY'] - provider = MsRestAzure::ApplicationTokenProvider.new( - az_conn_opts[:tenant_id], - az_conn_opts[:client_id], - az_conn_opts[:client_secret] - ) + @rgroup_keep_empty = !keep_empty.nil? && keep_empty.upcase == 'YES' - az_conn_opts[:credentials] = MsRest::TokenCredentials.new(provider) + if !@rgroup_name + rgroup_format = @az_conf[:rgroup_name_format] - @compute_client = Compute::Client.new(az_conn_opts) - @monitor_client = Monitor::Client.new(az_conn_opts) - @network_client = Network::Client.new(az_conn_opts) - @resource_client = Resources::Client.new(az_conn_opts) - @storage_client = Storage::Client.new(az_conn_opts) + @rgroup_name = format(rgroup_format, + :NAME => @xmlhost['NAME'], + :CLUSTER => @xmlhost['CLUSTER'], + :ID => @xmlhost['ID']) + end + + # ---------------------------------------------------------------------- + # Init AZ connection options + # ---------------------------------------------------------------------- + @az_conn_opts = {} + + { + 'AZ_SUB' => :subscription_id, + 'AZ_CLIENT' => :client_id, + 'AZ_SECRET' => :client_secret, + 'AZ_TENANT' => :tenant_id, + 'AZ_REGION' => :region + }.each do |attr, opt| + @az_conn_opts[opt] = @xmlhost["TEMPLATE/#{attr}"] + + raise "Missing #{attr} in azure host" if @az_conn_opts[opt].nil? + end + + @region = @az_conn_opts[:region] + + # ---------------------------------------------------------------------- + # create or open cache db + # ---------------------------------------------------------------------- + @db = InstanceCache.new(AZ_DATABASE_PATH) end + #--------------------------------------------------------------------------- + # + #--------------------------------------------------------------------------- + def az_connect + require 'azure_mgmt_compute' + require 'azure_mgmt_monitor' + require 'azure_mgmt_network' + require 'azure_mgmt_resources' + require 'azure_mgmt_storage' + + @compute_models = Azure::Compute::Profiles::Latest::Mgmt::Models + @network_models = Azure::Network::Profiles::Latest::Mgmt::Models + + provider = MsRestAzure::ApplicationTokenProvider.new( + @az_conn_opts[:tenant_id], + @az_conn_opts[:client_id], + @az_conn_opts[:client_secret] + ) + + @az_conn_opts[:credentials] = MsRest::TokenCredentials.new(provider) + + # rubocop:disable Layout/LineLength + @compute_client = + Azure::Compute::Profiles::Latest::Mgmt::Client.new(@az_conn_opts) + + @monitor_client = + Azure::Monitor::Profiles::Latest::Mgmt::Client.new(@az_conn_opts) + + @network_client = + Azure::Network::Profiles::Latest::Mgmt::Client.new(@az_conn_opts) + + @resource_client = + Azure::Resources::Profiles::Latest::Mgmt::Client.new(@az_conn_opts) + + @storage_client = + Azure::Storage::Profiles::Latest::Mgmt::Client.new(@az_conn_opts) + # rubocop:enable Layout/LineLength + end + + # -------------------------------------------------------------------------- # DEPLOY action + # -------------------------------------------------------------------------- def deploy(id, host, xml_text, lcm_state, deploy_id) + az_connect + @rgroup = create_rgroup(@rgroup_name, @region) \ unless @resource_client.resource_groups .check_existence(@rgroup_name) @@ -154,118 +227,122 @@ class AzureDriver end end + # -------------------------------------------------------------------------- # Shutdown an Azure instance + # -------------------------------------------------------------------------- def shutdown(deploy_id, lcm_state) + az_connect + case lcm_state when 'SHUTDOWN' @compute_client.virtual_machines.power_off(@rgroup_name, deploy_id) @compute_client.virtual_machines.delete(@rgroup_name, deploy_id) + delete_vm_resources(deploy_id) when 'SHUTDOWN_POWEROFF', 'SHUTDOWN_UNDEPLOY' - @compute_client.virtual_machines.delete(@rgroup_name, deploy_id) + @compute_client.virtual_machines.power_off(@rgroup_name, deploy_id) end - delete_vm_resources(deploy_id) end + # -------------------------------------------------------------------------- # Reboot an Azure instance + # -------------------------------------------------------------------------- def reboot(deploy_id) + az_connect + i = get_instance(deploy_id) @compute_client.virtual_machines.restart(@rgroup_name, i.name) end + # -------------------------------------------------------------------------- # Cancel an Azure instance + # -------------------------------------------------------------------------- def cancel(deploy_id) + az_connect + @compute_client.virtual_machines.delete(@rgroup_name, deploy_id) delete_vm_resources(deploy_id) end - # Stop an Azure instance - def save(deploy_id) - i = get_instance(deploy_id) - @compute_client.virtual_machines.power_off(@rgroup_name, i.name) - end - + # -------------------------------------------------------------------------- # Resume an Azure instance + # -------------------------------------------------------------------------- def restore(deploy_id) + az_connect + i = get_instance(deploy_id) - return if vm_state(i) == 'running' + return if vm_state(i) == 'RUNNING' @compute_client.virtual_machines.start(@rgroup_name, i.name) end - # Get info (IP, and state) for an Azure instance - def poll(_id, deploy_id) - i = get_instance(deploy_id) - puts parse_poll(i) + #--------------------------------------------------------------------------- + # Monitor Interface + #--------------------------------------------------------------------------- + def probe_host_system + # call probe_host_system from PublicCloudDriver module + super(@db, @az_conf[:cache_expire], @xmlhost) end - # Get the info of all Aure instances. An Azure instance must have - # a name compliant with the "one-####" format, where #### are integers - def monitor_all_vms - totalmemory = 0 - totalcpu = 0 + def probe_host_monitor + # call probe_host_monitor from PublicCloudDriver module + super(@db, @az_conf[:cache_expire], @xmlhost) + end - capacity = @xmlhost.to_hash['HOST']['TEMPLATE']['CAPACITY'] + def retreive_vms_data + # call vms_data from PublicCloudDriver module + vms_data(@db, @az_conf[:cache_expire]) + end - if capacity.nil? || !capacity.is_a?(Hash) - raise 'You must define CAPACITY section properly! '\ - 'Check the VM template' + #--------------------------------------------------------------------------- + # + # + #--------------------------------------------------------------------------- + private + + # Verify az_info contains all required params + def validate_az_info(az_info) + AZ_REQUIRED_PARAMS.each do |param| + if !az_info.key? param + raise "Missing #{param} in VM template azure setting " \ + "or in #{AZ_DRIVER_DEFAULT}" + end end + end - capacity.each do |name, value| - cpu, mem = instance_type_capacity(name) - totalmemory += mem * value.to_i - totalcpu += cpu * value.to_i - end - - host_info = "HYPERVISOR=AZURE\n" - host_info << "PUBLIC_CLOUD=YES\n" - host_info << "PRIORITY=-1\n" - host_info << "TOTALMEMORY=#{totalmemory.round}\n" - host_info << "TOTALCPU=#{totalcpu}\n" - host_info << "HOSTNAME=\"#{@host}\"\n" - - vms_info = "VM_POLL=YES\n" - - usedcpu = 0 - usedmemory = 0 - + # Get VMs details from azure, include monitoring if needed + def fetch_vms_data(with_monitoring = false) + az_connect work_q = Queue.new + vms = [] if @resource_client.resource_groups.check_existence(@rgroup_name) - @compute_client.virtual_machines - .list(@rgroup_name).each {|i| work_q.push i } - workers = (0...20).map do + az_instances = @compute_client.virtual_machines.list(@rgroup_name) + az_instances.each {|i| work_q.push i } + + workers = (0...[az_instances.length, 20].min).map do Thread.new do begin while (i = work_q.pop(true)) vm_state = vm_state(i) - next if vm_state !~ /running|pending/ + next if vm_state != 'RUNNING' one_id = i.tags['ONE_ID'] if i.tags - poll_data = parse_poll(i, vm_state) + vm = { :uuid => i.vm_id, + :id => one_id || -1, + :name => i.name, + :type => i.hardware_profile.vm_size, + :state => vm_state(i) } - vm_template_to_one = vm_to_one(i) - vm_template_to_one = Base64 - .encode64(vm_template_to_one) - .gsub("\n", '') + if with_monitoring + vm[:monitor] = get_vm_monitor_data(i) + end - vms_info << "VM=[\n" - vms_info << " ID=#{one_id || -1},\n" - vms_info << " DEPLOY_ID=#{i.name},\n" - vms_info << " VM_NAME=#{i.name},\n" - vms_info << ' IMPORT_TEMPLATE='\ - "\"#{vm_template_to_one}\",\n" - vms_info << " POLL=\"#{poll_data}\" ]\n" + vms << vm - next unless one_id - - name = i.hardware_profile.vm_size - cpu, mem = instance_type_capacity(name) - usedcpu += cpu - usedmemory += mem + # next unless one_id end rescue ThreadError nil @@ -277,77 +354,10 @@ class AzureDriver workers.map(&:join) end - host_info << "USEDMEMORY=#{usedmemory.round}\n" - host_info << "USEDCPU=#{usedcpu.round}\n" - host_info << "FREEMEMORY=#{(totalmemory - usedmemory).round}\n" - host_info << "FREECPU=#{(totalcpu - usedcpu).round}\n" + # store to db + @db.insert(vms) - puts host_info - puts vms_info - end - - private - - def host_info - client = OpenNebula::Client.new - pool = OpenNebula::HostPool.new(client) - pool.info - - objects=pool.select {|object| object.name==@host } - - host_id = objects.first.id - xmlhost = OpenNebula::Host.new_with_id(host_id, client) - xmlhost.info(true) - xmlhost - end - - # Check the host template to retrieve - # conection info needed for Azure - def connect_info - ret = {} - - { 'AZ_SUB' => :subscription_id, - 'AZ_CLIENT' => :client_id, - 'AZ_SECRET' => :client_secret, - 'AZ_TENANT' => :tenant_id, - 'AZ_REGION' => :region }.each do |attr_name, conn_opt| - ret[conn_opt] = @xmlhost["TEMPLATE/#{attr_name}"] - - if ret[conn_opt].nil? - raise "Missing #{attr_name} in azure host template" - end - end - - ret - end - - # AZ resource group is either specified in host template attr AZ_GROUP - # or it is derived from the rgroup_name_format and host attributes - def rgroup_info - rgroup = @xmlhost['TEMPLATE/AZ_RGROUP'] - keep_empty = @xmlhost['TEMPLATE/AZ_RGROUP_KEEP_EMPTY'] - keep_empty = !keep_empty.nil? && keep_empty.upcase == 'YES' - - return rgroup, keep_empty if rgroup - - rgroup_name_format = @public_cloud_az_conf['rgroup_name_format'] || \ - 'one-%s-%s' - - rgroup = format(rgroup_name_format, - :NAME => @xmlhost['NAME'], - :CLUSTER => @xmlhost['CLUSTER'], - :ID => @xmlhost['ID']) - [rgroup, keep_empty] - end - - # Verify az_info contains all required params - def validate_az_info(az_info) - AZ_REQUIRED_PARAMS.each do |param| - if !az_info.key? param - raise "Missing #{param} in VM template azure setting " \ - "or in #{AZ_DRIVER_DEFAULT}" - end - end + vms end # Create azure resource group @@ -413,10 +423,10 @@ class AzureDriver end def create_public_ip(id, ip_name) - public_ip_params = NetworkModels::PublicIPAddress.new.tap do |ip| + public_ip_params = @network_models::PublicIPAddress.new.tap do |ip| ip.location = @region ip.public_ipallocation_method = - NetworkModels::IPAllocationMethod::Dynamic + @network_models::IPAllocationMethod::Dynamic ip.tags = { 'ONE_ID' => id } end @network_client.public_ipaddresses.create_or_update( @@ -428,25 +438,28 @@ class AzureDriver # rubocop:disable Layout/LineLength def create_vm(id, subnet, public_ip, az_info, ssh_public_key) vm_name = "one-#{id}" - net_ip_conf = NetworkModels::NetworkInterfaceIPConfiguration - ip_method = NetworkModels::IPAllocationMethod::Dynamic + net_ip_conf = @network_models::NetworkInterfaceIPConfiguration + ip_method = @network_models::IPAllocationMethod::Dynamic if az_info['SECURITY_GROUP'] - security_group = @network_client.network_security_groups.get(@rgroup_name, az_info['SECURITY_GROUP']) + security_group = @network_client.network_security_groups.get( + @rgroup_name, az_info['SECURITY_GROUP']) end if az_info['PROXIMITY_GROUP'] - proximity_group = @compute_client.proximity_placement_groups.get(@rgroup_name, az_info['PROXIMITY_GROUP']) + proximity_group = @compute_client.proximity_placement_groups.get( + @rgroup_name, az_info['PROXIMITY_GROUP']) end if az_info['AVAILABILITY_SET'] - availability_set = @compute_client.availability_sets.get(@rgroup_name, az_info['AVAILABILITY_SET']) + availability_set = @compute_client.availability_sets.get( + @rgroup_name, az_info['AVAILABILITY_SET']) end nic = @network_client.network_interfaces.create_or_update( @rgroup_name, "#{vm_name}-nic", - NetworkModels::NetworkInterface.new.tap do |interface| + @network_models::NetworkInterface.new.tap do |interface| interface.location = @region interface.network_security_group = security_group if security_group interface.ip_configurations = [ @@ -462,9 +475,9 @@ class AzureDriver end ) - vm_create_params = ComputeModels::VirtualMachine.new.tap do |vm| + vm_create_params = @compute_models::VirtualMachine.new.tap do |vm| vm.location = @region - vm.os_profile = ComputeModels::OSProfile.new.tap do |os_profile| + vm.os_profile = @compute_models::OSProfile.new.tap do |os_profile| os_profile.computer_name = vm_name os_profile.admin_username = az_info['VM_USER'] os_profile.admin_password = az_info['VM_PASSWORD'] @@ -473,8 +486,8 @@ class AzureDriver vm.proximity_placement_groups = proximity_group if proximity_group vm.availability_set = availability_set if availability_set - vm.storage_profile = ComputeModels::StorageProfile.new.tap do |store_profile| - store_profile.image_reference = ComputeModels::ImageReference.new.tap do |ref| + vm.storage_profile = @compute_models::StorageProfile.new.tap do |store_profile| + store_profile.image_reference = @compute_models::ImageReference.new.tap do |ref| ref.publisher = az_info['IMAGE_PUBLISHER'] ref.offer = az_info['IMAGE_OFFER'] ref.sku = az_info['IMAGE_SKU'] @@ -482,14 +495,14 @@ class AzureDriver end end - vm.hardware_profile = ComputeModels::HardwareProfile.new.tap do |hardware| - # hardware.vm_size = ComputeModels::VirtualMachineSizeTypes::StandardDS2V2 + vm.hardware_profile = @compute_models::HardwareProfile.new.tap do |hardware| + # hardware.vm_size = @compute_models::VirtualMachineSizeTypes::StandardDS2V2 hardware.vm_size = az_info['INSTANCE_TYPE'] end - vm.network_profile = ComputeModels::NetworkProfile.new.tap do |net_profile| + vm.network_profile = @compute_models::NetworkProfile.new.tap do |net_profile| net_profile.network_interfaces = [ - ComputeModels::NetworkInterfaceReference.new.tap do |ref| + @compute_models::NetworkInterfaceReference.new.tap do |ref| ref.id = nic.id ref.primary = true end @@ -498,11 +511,11 @@ class AzureDriver end if ssh_public_key - vm_create_params.os_profile.linux_configuration = ComputeModels::LinuxConfiguration.new.tap do |linux| + vm_create_params.os_profile.linux_configuration = @compute_models::LinuxConfiguration.new.tap do |linux| linux.disable_password_authentication = true - linux.ssh = ComputeModels::SshConfiguration.new.tap do |ssh_config| + linux.ssh = @compute_models::SshConfiguration.new.tap do |ssh_config| ssh_config.public_keys = [ - ComputeModels::SshPublicKey.new.tap do |pub_key| + @compute_models::SshPublicKey.new.tap do |pub_key| pub_key.key_data = ssh_public_key pub_key.path = "/home/#{az_info['VM_USER']}/.ssh/authorized_keys" end @@ -567,7 +580,7 @@ class AzureDriver (resource['memory'].to_f * 1024 * 1024).to_i] end - # Get the Azure section of the template. If more than one Azure section + # Get the Azure section of the template. def get_deployment_info(host, xml_text) xml = OpenNebula::XMLElement.new xml.initialize_xml(xml_text, 'VM') @@ -611,11 +624,23 @@ class AzureDriver [az, context.first.to_hash['CONTEXT']] end + # Return state of the instance (ONE state) def vm_state(i) az_inst_view = @compute_client.virtual_machines.instance_view( @rgroup_name, i.name ) - az_inst_view.statuses[-1].code.split('/').last + az_state = az_inst_view.statuses[-1].code.split('/').last + case az_state + when 'running', 'starting' + # return VM_STATE[:active] + 'RUNNING' + when 'suspended', 'stopping' + # return VM_STATE[:paused] + 'SHUTDOWN' + else + # return VM_STATE[:unknown] + 'UNKNOWN' + end end def get_cpu_num(instance) @@ -628,32 +653,16 @@ class AzureDriver end # Retrive the vm information from the Azure instance view - def parse_poll(instance, vm_state) - info = state = '' - - if !instance - state = VM_STATE[:deleted] - else - case vm_state - when 'running', 'starting' - state = VM_STATE[:active] - when 'suspended', 'stopping' - state = VM_STATE[:paused] - else - state = VM_STATE[:unknown] - end - end - - info << "#{POLL_ATTRIBUTE[:state]}=#{state} " - + def get_vm_monitor_data(instance) # include metrics data (azure doesn't give any info about VM memory) data = @monitor_client.metrics.list( instance.id, :metricnames => MONITOR_METRICS.join(','), - :timespan => 'PT1M', # Period time 1m + :timespan => 'PT1M', # Period time 1m :result_type => 'Data' ) + info = '' data.value.each do |e| value = e.timeseries.first.data.first.average || 0 @@ -690,7 +699,7 @@ class AzureDriver info << "\\\"#{v}\\\" " end - info + Base64.encode64(info).gsub("\n", '') end def get_instance_public_ip(vm_name) @@ -738,29 +747,6 @@ class AzureDriver instance end - # Build template for importation - def vm_to_one(vm) - cpu, mem = instance_type_capacity(vm.hardware_profile.vm_size) - - mem = mem.to_i / 1024 # Memory for templates expressed in MB - cpu = cpu.to_f / 100 # CPU expressed in units - - str = "NAME = \"Instance from #{vm.name}\"\n"\ - "CPU = \"#{cpu}\"\n"\ - "vCPU = \"#{cpu.ceil}\"\n"\ - "MEMORY = \"#{mem}\"\n"\ - "HYPERVISOR = \"AZURE\"\n"\ - "PUBLIC_CLOUD = [\n"\ - " TYPE =\"azure\"\n"\ - "]\n"\ - "IMPORT_VM_ID = \"#{vm.vm_id}\"\n"\ - "SCHED_REQUIREMENTS=\"NAME=\\\"#{@host}\\\"\"\n"\ - 'DESCRIPTION = "Instance imported from Azure, from instance'\ - " #{vm.name}\"\n" - - str - end - # Transform object to hash def examine(obj) ret = {} @@ -790,3 +776,28 @@ class AzureDriver end end + +############################################################################ +# Module Interface +# Interface for probe_db - VirtualMachineDB +############################################################################ +module DomainList + + def self.state_info(id, name) + az = AzureDriver.new(id, name) + + vms = az.retreive_vms_data + + info = {} + vms.each do |vm| + info[vm[:uuid]] = { :id => vm[:id], + :uuid => vm[:uuid], + :name => vm[:name], + :state => vm[:state], + :hyperv => 'az' } + end + + info + end + +end diff --git a/src/vmm_mad/remotes/az/save b/src/vmm_mad/remotes/az/save index c82569e536..9f65e99890 100755 --- a/src/vmm_mad/remotes/az/save +++ b/src/vmm_mad/remotes/az/save @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby +#!/bin/bash # -------------------------------------------------------------------------- # # Copyright 2002-2019, OpenNebula Project, OpenNebula Systems # @@ -14,34 +14,7 @@ # 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 !defined?(ONE_LOCATION) - -if !ONE_LOCATION - RUBY_LIB_LOCATION = '/usr/lib/one/ruby' if !defined?(RUBY_LIB_LOCATION) - GEMS_LOCATION = '/usr/share/one/gems' if !defined?(GEMS_LOCATION) -else - RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' if !defined?(RUBY_LIB_LOCATION) - GEMS_LOCATION = ONE_LOCATION + '/share/gems' if !defined?(GEMS_LOCATION) -end - -if File.directory?(GEMS_LOCATION) - Gem.use_paths(GEMS_LOCATION) -end - -$LOAD_PATH << RUBY_LIB_LOCATION -$LOAD_PATH << File.dirname(__FILE__) - -require 'az_driver' - -deploy_id = ARGV[0] -file = ARGV[1] -host = ARGV[2] - -begin - az_drv = AzureDriver.new(host) - az_drv.save(deploy_id) -rescue => e - OpenNebula.handle_driver_exception("Save", e, host, deploy_id, nil, file) -end +SCRIPT_NAME=$(basename $0) +echo "Action $SCRIPT_NAME not supported" 1>&2 diff --git a/src/vmm_mad/remotes/ec2/ec2_driver.conf b/src/vmm_mad/remotes/ec2/ec2_driver.conf index 831733c733..2c97e396f9 100644 --- a/src/vmm_mad/remotes/ec2/ec2_driver.conf +++ b/src/vmm_mad/remotes/ec2/ec2_driver.conf @@ -1,6 +1,6 @@ -proxy_uri: -state_wait_timeout_seconds: 1500 -instance_types: +:proxy_uri: +:state_wait_timeout_seconds: 1500 +:instance_types: a1.2xlarge: cpu: 8 memory: 16.0 diff --git a/src/vmm_mad/remotes/ec2/ec2_driver.rb b/src/vmm_mad/remotes/ec2/ec2_driver.rb index c89105778d..f29349ae8a 100755 --- a/src/vmm_mad/remotes/ec2/ec2_driver.rb +++ b/src/vmm_mad/remotes/ec2/ec2_driver.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby # -------------------------------------------------------------------------- # -# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems # +# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems # # # # 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 # @@ -15,24 +15,23 @@ # limitations under the License. # # -------------------------------------------------------------------------- # -ONE_LOCATION = ENV['ONE_LOCATION'] if !defined?(ONE_LOCATION) +ONE_LOCATION ||= ENV['ONE_LOCATION'] if !defined? ONE_LOCATION if !ONE_LOCATION - RUBY_LIB_LOCATION = '/usr/lib/one/ruby' if !defined?(RUBY_LIB_LOCATION) - GEMS_LOCATION = '/usr/share/one/gems' if !defined?(GEMS_LOCATION) - ETC_LOCATION = '/etc/one/' if !defined?(ETC_LOCATION) - VAR_LOCATION = '/var/lib/one/' if !defined?(VAR_LOCATION) + RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby' + GEMS_LOCATION ||= '/usr/share/one/gems' + ETC_LOCATION ||= '/etc/one/' + VAR_LOCATION ||= '/var/lib/one/' else - RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' if !defined?(RUBY_LIB_LOCATION) - GEMS_LOCATION = ONE_LOCATION + '/share/gems' if !defined?(GEMS_LOCATION) - ETC_LOCATION = ONE_LOCATION + '/etc/' if !defined?(ETC_LOCATION) - VAR_LOCATION = ONE_LOCATION + '/var/' if !defined?(VAR_LOCATION) + RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby' + GEMS_LOCATION ||= ONE_LOCATION + '/share/gems' + ETC_LOCATION ||= ONE_LOCATION + '/etc/' + VAR_LOCATION ||= ONE_LOCATION + '/var/' end -EC2_DRIVER_CONF = "#{ETC_LOCATION}/ec2_driver.conf" +EC2_DRIVER_CONF = "#{ETC_LOCATION}/ec2_driver.conf" EC2_DRIVER_DEFAULT = "#{ETC_LOCATION}/ec2_driver.default" - -STATE_WAIT_PM_TIMEOUT_SECONDS = 1500 +EC2_DATABASE_PATH = "#{VAR_LOCATION}/remotes/im/ec2.d/ec-cache.db" if File.directory?(GEMS_LOCATION) Gem.use_paths(GEMS_LOCATION) @@ -40,12 +39,9 @@ end $LOAD_PATH << RUBY_LIB_LOCATION -gem 'aws-sdk', '>= 2.0' - # Load EC2 credentials and environment require 'yaml' require 'rubygems' -require 'aws-sdk' require 'uri' require 'resolv' @@ -53,111 +49,119 @@ require 'CommandManager' require 'scripts_common' require 'rexml/document' require 'VirtualMachineDriver' +require 'PublicCloudDriver' require 'opennebula' -require 'thread' - -begin - PUBLIC_CLOUD_EC2_CONF = YAML::load(File.read(EC2_DRIVER_CONF)) -rescue Exception => e - str_error="Unable to read '#{EC2_DRIVER_CONF}'. Invalid YAML syntax:\n" + - e.message + "\n********Stack trace from EC2 IM driver*********\n" - raise str_error -end - +#------------------------------------------------------------------------------- # The main class for the EC2 driver +#------------------------------------------------------------------------------- class EC2Driver - ACTION = VirtualMachineDriver::ACTION - POLL_ATTRIBUTE = VirtualMachineDriver::POLL_ATTRIBUTE - VM_STATE = VirtualMachineDriver::VM_STATE - # Key that will be used to store the monitoring information in the template - EC2_MONITOR_KEY = "EC2DRIVER_MONITOR" + include PublicCloudDriver + + # -------------------------------------------------------------------------- + # Constants + # -------------------------------------------------------------------------- + + POLL_ATTRIBUTE = VirtualMachineDriver::POLL_ATTRIBUTE # EC2 commands constants EC2 = { :run => { :cmd => :create, :args => { - "AKI" => { + 'AKI' => { :opt => 'kernel_id' }, - "AMI" => { + 'AMI' => { :opt => 'image_id' }, - "BLOCKDEVICEMAPPING" => { + 'BLOCKDEVICEMAPPING' => { :opt => 'block_device_mappings', :proc => lambda {|str| - str.split(' ').collect { |s| + str.split(' ').collect do |s| dev, tmp = s.split('=') - hash = Hash.new + hash = {} hash[:device_name] = dev - if tmp == "none" + if tmp == 'none' hash[:no_device] = dev else - hash[:ebs] = Hash.new + hash[:ebs] = {} tmp_a = tmp.split(':') - hash[:ebs][:snapshot_id] = tmp_a[0] if tmp_a[0] && !tmp_a[0].empty? - hash[:ebs][:volume_size] = tmp_a[1].to_i if tmp_a[1] && !tmp_a[1].empty? - if tmp_a[2] == "false" + + if tmp_a[0] && !tmp_a[0].empty? + hash[:ebs][:snapshot_id] = tmp_a[0] + end + + if tmp_a[1] && !tmp_a[1].empty? + hash[:ebs][:volume_size] = tmp_a[1].to_i + end + + if tmp_a[2] == 'false' hash[:ebs][:delete_on_termination] = false - elsif tmp_a[2] == "true" + elsif tmp_a[2] == 'true' hash[:ebs][:delete_on_termination] = true end - hash[:ebs][:volume_type] = tmp_a[3] if tmp_a[3] && !tmp_a[3].empty? - hash[:ebs][:iops] = tmp_a[4].to_i if tmp_a[4] && !tmp_a[4].empty? + + if tmp_a[3] && !tmp_a[3].empty? + hash[:ebs][:volume_type] = tmp_a[3] + end + + if tmp_a[4] && !tmp_a[4].empty? + hash[:ebs][:iops] = tmp_a[4].to_i + end end hash - } + end } }, - "CLIENTTOKEN" => { + 'CLIENTTOKEN' => { :opt => 'client_token' }, - "INSTANCETYPE" => { + 'INSTANCETYPE' => { :opt => 'instance_type' }, - "KEYPAIR" => { + 'KEYPAIR' => { :opt => 'key_name' }, - "LICENSEPOOL" => { + 'LICENSEPOOL' => { :opt => 'license/pool' }, - "PLACEMENTGROUP" => { + 'PLACEMENTGROUP' => { :opt => 'placement/group_name' }, - "PRIVATEIP" => { + 'PRIVATEIP' => { :opt => 'private_ip_address' }, - "RAMDISK" => { + 'RAMDISK' => { :opt => 'ramdisk_id' }, - "SUBNETID" => { + 'SUBNETID' => { :opt => 'subnet_id' }, - "TENANCY" => { + 'TENANCY' => { :opt => 'placement/tenancy' }, - "USERDATA" => { + 'USERDATA' => { :opt => 'user_data' }, - #"USERDATAFILE" => { + # "USERDATAFILE" => { # :opt => '-f' - #}, - "SECURITYGROUPS" => { + # }, + 'SECURITYGROUPS' => { :opt => 'security_groups', - :proc => lambda {|str| str.split(/,\s*/)} + :proc => ->(str) { str.split(/,\s*/) } }, - "SECURITYGROUPIDS" => { + 'SECURITYGROUPIDS' => { :opt => 'security_group_ids', - :proc => lambda {|str| str.split(/,\s*/)} + :proc => ->(str) { str.split(/,\s*/) } }, - "AVAILABILITYZONE" => { + 'AVAILABILITYZONE' => { :opt => 'placement/availability_zone' }, - "EBS_OPTIMIZED" => { + 'EBS_OPTIMIZED' => { :opt => 'ebs_optimized', - :proc => lambda {|str| str.downcase.eql? "true"} + :proc => ->(str) { str.downcase.eql? 'true' } } } }, @@ -170,11 +174,11 @@ class EC2Driver :associate => { :cmd => :associate_address, :args => { - #"SUBNETID" => { + # "SUBNETID" => { # :opt => '-a', # :proc => lambda {|str| ''} - #}, - "ELASTICIP" => { + # }, + 'ELASTICIP' => { :opt => 'public_ip' } } @@ -182,9 +186,9 @@ class EC2Driver :authorize => { :cmd => :authorize, :args => { - "AUTHORIZEDPORTS" => { + 'AUTHORIZEDPORTS' => { :opt => '-p', - :proc => lambda {|str| str.split(',').join(' -p ')} + :proc => ->(str) { str.split(',').join(' -p ') } } } }, @@ -200,14 +204,14 @@ class EC2Driver :tags => { :cmd => :create_tags, :args => { - "TAGS" => { + 'TAGS' => { :opt => 'tags', :proc => lambda {|str| hash = {} - str.split(',').each {|s| - k,v = s.split('=') + str.split(',').each do |s| + k, v = s.split('=') hash[k] = v - } + end hash } } @@ -232,132 +236,112 @@ class EC2Driver :image_id ] + DEFAULTS = { + :state_wait_pm_timeout_seconds => 1500, + :cache_expire => 120 + } + + # -------------------------------------------------------------------------- # EC2 constructor, loads credentials and endpoint - def initialize(host, host_id=nil) - @host = host - @host_id = host_id + # @param [String] name of host in OpenNebula + # @param [String] ID of host in OpenNebula + # -------------------------------------------------------------------------- + def initialize(host, id=nil) + @hypervisor = 'ec2' + @host = host - @instance_types = PUBLIC_CLOUD_EC2_CONF['instance_types'] + load_conf = YAML.safe_load(File.read(EC2_DRIVER_CONF), [Symbol]) + @ec2_conf = DEFAULTS + @ec2_conf.merge!(load_conf) - conn_opts = get_connect_info(host, host_id) - access_key = conn_opts[:access] - secret_key = conn_opts[:secret] - region_name = conn_opts[:region] + @instance_types = @ec2_conf[:instance_types] - #sanitize region data - raise "access_key_id not defined for #{host}" if access_key.nil? - raise "secret_access_key not defined for #{host}" if secret_key.nil? - raise "region_name not defined for #{host}" if region_name.nil? + # ---------------------------------------------------------------------- + # Init OpenNebula host information + # ---------------------------------------------------------------------- + @xmlhost = host_info(host, id) + @cw_mon_time = @xmlhost['/HOST/MONITORING/CWMONTIME'] - Aws.config.merge!({ - :access_key_id => access_key, - :secret_access_key => secret_key, - :region => region_name - }) - - if (proxy_uri = PUBLIC_CLOUD_EC2_CONF['proxy_uri']) - Aws.config(:proxy_uri => proxy_uri) + if @xmlhost['TEMPLATE/PM_MAD'] + @provision_type = :host + @state_change_timeout = \ + @ec2_conf[:state_wait_pm_timeout_seconds].to_i + else + @provision_type = :vm + @state_change_timeout = \ + @ec2_conf[:state_wait_timeout_seconds].to_i end - if @provision_type == :host - if PUBLIC_CLOUD_EC2_CONF['state_wait_pm_timeout_seconds'] - @state_change_timeout = PUBLIC_CLOUD_EC2_CONF['state_wait_pm_timeout_seconds'].to_i - else - @state_change_timeout = STATE_WAIT_PM_TIMEOUT_SECONDS - end - else - @state_change_timeout = PUBLIC_CLOUD_EC2_CONF['state_wait_timeout_seconds'].to_i + tmpl_base = + @xmlhost['TEMPLATE/PROVISION'] ? 'TEMPLATE/PROVISION' : 'TEMPLATE' + + @access_key = @xmlhost["#{tmpl_base}/EC2_ACCESS"] + @secret_key = @xmlhost["#{tmpl_base}/EC2_SECRET"] + @region_name = @xmlhost["#{tmpl_base}/REGION_NAME"] + + # sanitize region data + raise "access_key_id not defined for #{host}" if @access_key.nil? + raise "secret_access_key not defined for #{host}" if @secret_key.nil? + raise "region_name not defined for #{host}" if @region_name.nil? + + # ---------------------------------------------------------------------- + # create or open cache db + # ---------------------------------------------------------------------- + @db = InstanceCache.new(EC2_DATABASE_PATH) + end + + #--------------------------------------------------------------------------- + # Load AWS sdk and connect + #--------------------------------------------------------------------------- + def ec2_connect + require 'aws-sdk-ec2' + + Aws.config.merge!({ + :access_key_id => @access_key, + :secret_access_key => @secret_key, + :region => @region_name + }) + + if (proxy_uri = @ec2_conf[:proxy_uri]) + Aws.config(:proxy_uri => proxy_uri) end @ec2 = Aws::EC2::Resource.new end - # Check the current template of host - # to retrieve connection information - # needed for Amazon - def get_connect_info(host, host_id) - conn_opts = {} - client = OpenNebula::Client.new - - if host.is_a?(String) - if !host_id - pool = OpenNebula::HostPool.new(client) - pool.info - objects = pool.select {|object| object.name==host } - host_id = objects.first.id - @host_id = host_id - end - else - host_id = host['ID'] - end - - xmlhost = OpenNebula::Host.new_with_id(host_id, client) - xmlhost.info(true) - - if xmlhost["TEMPLATE/PROVISION"] - @tmplBase = 'TEMPLATE/PROVISION' - else - @tmplBase = 'TEMPLATE' - end - - if xmlhost["TEMPLATE/PM_MAD"] - @provision_type = :host - else - @provision_type = :vm - end - - conn_opts = { - :access => xmlhost["#{@tmplBase}/EC2_ACCESS"], - :secret => xmlhost["#{@tmplBase}/EC2_SECRET"], - :region => xmlhost["#{@tmplBase}/REGION_NAME"] - } - - return conn_opts - end - - # Generate cloud-init configuration based on context variables - def generate_cc(xobj, xpath_context) - cc = "#cloud-config\n" - - ssh_key = xobj["#{xpath_context}/SSH_PUBLIC_KEY"] - if ssh_key - cc << "ssh_authorized_keys:\n" - ssh_key.split("\n").each do |key| - cc << "- #{key}\n" - end - end - - cc - end - + # -------------------------------------------------------------------------- # DEPLOY action, also sets ports and ip if needed + # -------------------------------------------------------------------------- def deploy(id, host, xml_text, lcm_state, deploy_id) - # Restore if we need to - if lcm_state != "BOOT" && lcm_state != "BOOT_FAILURE" + ec2_connect + + # Restore if we need to + if lcm_state != 'BOOT' && lcm_state != 'BOOT_FAILURE' restore(deploy_id) return deploy_id end - # Otherwise deploy the VM + # Otherwise deploy the VM begin ec2_info = get_deployment_info(host, xml_text) - rescue Exception => e + rescue StandardError => e raise e end load_default_template_values if !ec2_value(ec2_info, 'AMI') - raise "Cannot find AMI in deployment file" + raise 'Cannot find AMI in deployment file' end opts = generate_options(:run, ec2_info, { - :min_count => 1, - :max_count => 1}) + :min_count => 1, + :max_count => 1 + }) # The OpenNebula context will be only included if not USERDATA - # is provided by the user + # is provided by the user if !ec2_value(ec2_info, 'USERDATA') xml = OpenNebula::XMLElement.new xml.initialize_xml(xml_text, @provision_type == :host ? 'HOST' : 'VM') @@ -371,7 +355,7 @@ class EC2Driver context_str = xml.template_like_str('TEMPLATE/CONTEXT') if xml['TEMPLATE/CONTEXT/TOKEN'] == 'YES' - # TODO use OneGate library + # TODO: use OneGate library token_str = generate_onegate_token(xml) if token_str context_str << "\nONEGATE_TOKEN=\"#{token_str}\"" @@ -379,7 +363,7 @@ class EC2Driver end end - userdata_key = EC2[:run][:args]["USERDATA"][:opt] + userdata_key = EC2[:run][:args]['USERDATA'][:opt] opts[userdata_key] = Base64.encode64(context_str) end end @@ -389,12 +373,11 @@ class EC2Driver start_time = Time.now - while Time.now - start_time < @state_change_timeout - begin - break if instance.exists? - rescue => e - OpenNebula::log_error("RESCUE: #{e.inspect}") - end + loop do + break if instance.exists? + + raise 'Instance initialization timeouted' \ + if Time.now - start_time > @state_change_timeout sleep 2 end @@ -402,14 +385,14 @@ class EC2Driver tags = generate_options(:tags, ec2_info)[:tags] || {} tag_array = [] - tags.each{ |key,value| + tags.each do |key, value| tag_array << { :key => key, :value => value } - } + end - instance.create_tags(:tags => tag_array) if tag_array.length > 0 + instance.create_tags(:tags => tag_array) unless tag_array.empty? elastic_ip = ec2_value(ec2_info, 'ELASTICIP') @@ -432,43 +415,55 @@ class EC2Driver end if @provision_type == :host - instance.create_tags(tags: [{ - key: 'Name', - value: host['//HOST/TEMPLATE/PROVISION/HOSTNAME'] - },{ - key: 'ONE_HOST_ID', - value: 'TODO' + instance.create_tags( :tags => [{ + :key => 'Name', + :value => host['//HOST/TEMPLATE/PROVISION/HOSTNAME'] + }, { + :key => 'ONE_HOST_ID', + :value => 'TODO' }]) else - instance.create_tags(tags: [{ - key: 'ONE_ID', - value: id + instance.create_tags( :tags => [{ + :key => 'ONE_ID', + :value => id }]) end puts(instance.id) end + # -------------------------------------------------------------------------- # Shutdown a EC2 instance + # -------------------------------------------------------------------------- def shutdown(deploy_id, lcm_state) + ec2_connect + case lcm_state - when "SHUTDOWN" + when 'SHUTDOWN' ec2_action(deploy_id, :terminate) wait_state('terminated', deploy_id) - when "SHUTDOWN_POWEROFF", "SHUTDOWN_UNDEPLOY" + when 'SHUTDOWN_POWEROFF', 'SHUTDOWN_UNDEPLOY' ec2_action(deploy_id, :stop) wait_state('stopped', deploy_id) end end + # -------------------------------------------------------------------------- # Reboot a EC2 instance + # -------------------------------------------------------------------------- def reboot(deploy_id) + ec2_connect + ec2_action(deploy_id, :reboot) wait_state('running', deploy_id) end + # -------------------------------------------------------------------------- # Cancel a EC2 instance - def cancel(deploy_id, lcm_state=nil) + # -------------------------------------------------------------------------- + def cancel(deploy_id, lcm_state = nil) + ec2_connect + case lcm_state when 'SHUTDOWN_POWEROFF', 'SHUTDOWN_UNDEPLOY' ec2_action(deploy_id, :stop) @@ -479,21 +474,22 @@ class EC2Driver end end - # Save a EC2 instance - def save(deploy_id) - wait_state('running', deploy_id) - ec2_action(deploy_id, :stop) - wait_state('stopped', deploy_id) - end - + # -------------------------------------------------------------------------- # Resumes a EC2 instance + # -------------------------------------------------------------------------- def restore(deploy_id) + ec2_connect + ec2_action(deploy_id, :start) wait_state('running', deploy_id) end + # -------------------------------------------------------------------------- # Resets a EC2 instance + # -------------------------------------------------------------------------- def reset(deploy_id) + ec2_connect + ec2_action(deploy_id, :stop) wait_state('stopped', deploy_id) @@ -501,134 +497,60 @@ class EC2Driver wait_state('running', deploy_id) end - # Get info (IP, and state) for a EC2 instance - def poll(id, deploy_id) - i = get_instance(deploy_id) - vm = OpenNebula::VirtualMachine.new_with_id(id, OpenNebula::Client.new) - vm.info - cw_mon_time = vm["LAST_POLL"] ? vm["LAST_POLL"].to_i : Time.now.to_i - do_cw = (Time.now.to_i - cw_mon_time) >= 360 - puts parse_poll(i, vm, do_cw, cw_mon_time) + #--------------------------------------------------------------------------- + # Monitor Interface + #--------------------------------------------------------------------------- + def probe_host_system + # call probe_host_system from PublicCloudDriver module + super(@db, @ec2_conf[:cache_expire], @xmlhost) end + def probe_host_monitor + # call probe_host_monitor from PublicCloudDriver module + super(@db, @ec2_conf[:cache_expire], @xmlhost) + end + + def retreive_vms_data + # call vms_data from PublicCloudDriver module + vms_data(@db, @ec2_conf[:cache_expire]) + end + + #--------------------------------------------------------------------------- # Parse template instance type into # Amazon ec2 format (M1SMALL => m1.small) + #--------------------------------------------------------------------------- def parse_inst_type(type) - return type.downcase.gsub("_", ".") + type.downcase.gsub('_', '.') end - # Get the info of all the EC2 instances. An EC2 instance must include - # the ONE_ID tag, otherwise it will be ignored - def monitor_all_vms - totalmemory = 0 - totalcpu = 0 + #--------------------------------------------------------------------------- + # + #--------------------------------------------------------------------------- + private - # Get last cloudwatch monitoring time - host_obj = OpenNebula::Host.new_with_id(@host_id, - OpenNebula::Client.new) - host_obj.info - cw_mon_time = host_obj["/HOST/TEMPLATE/CWMONTIME"] - capacity = host_obj.to_hash["HOST"]["TEMPLATE"]["CAPACITY"] - if !capacity.nil? && Hash === capacity - capacity.each{ |name, value| - name = parse_inst_type(name) - cpu, mem = instance_type_capacity(name) - totalmemory += mem * value.to_i - totalcpu += cpu * value.to_i - } - else - raise "you must define CAPACITY section properly! check the template" - end + # Generate cloud-init configuration based on context variables + def generate_cc(xobj, xpath_context) + cc = "#cloud-config\n" - host_info = "HYPERVISOR=ec2\n" - host_info << "PUBLIC_CLOUD=YES\n" - host_info << "PRIORITY=-1\n" - host_info << "TOTALMEMORY=#{totalmemory.round}\n" - host_info << "TOTALCPU=#{totalcpu}\n" - host_info << "CPUSPEED=1000\n" - host_info << "HOSTNAME=\"#{@host}\"\n" - - vms_info = "VM_POLL=YES\n" - - # - # Add information for running VMs (running and pending). - # - usedcpu = 0 - usedmemory = 0 - - # Build an array of VMs and last_polls for monitoring - vpool = OpenNebula::VirtualMachinePool.new(OpenNebula::Client.new, - OpenNebula::VirtualMachinePool::INFO_ALL_VM) - vpool.info - onevm_info = {} - - - if !cw_mon_time - cw_mon_time = Time.now.to_i - else - cw_mon_time = cw_mon_time.to_i - end - - do_cw = (Time.now.to_i - cw_mon_time) >= 360 - vpool.each{ - |vm| onevm_info[vm.deploy_id] = vm - } - - - work_q = Queue.new - @ec2.instances.each{|i| work_q.push i } - workers = (0...20).map do - Thread.new do - begin - while i = work_q.pop(true) - next if i.state.name != 'pending' && i.state.name != 'running' - one_id = i.tags.find {|t| t.key == 'ONE_ID' } - one_id = one_id.value if one_id - poll_data=parse_poll(i, onevm_info[i.id], do_cw, cw_mon_time) - vm_template_to_one = vm_to_one(i) - vm_template_to_one = Base64.encode64(vm_template_to_one).gsub("\n","") - vms_info << "VM=[\n" - vms_info << " ID=#{one_id || -1},\n" - vms_info << " DEPLOY_ID=#{i.instance_id},\n" - vms_info << " VM_NAME=#{i.instance_id},\n" - vms_info << " IMPORT_TEMPLATE=\"#{vm_template_to_one}\",\n" - vms_info << " POLL=\"#{poll_data}\" ]\n" - if one_id - name = i.instance_type - cpu, mem = instance_type_capacity(name) - usedcpu += cpu - usedmemory += mem - end - end - rescue Exception => e - end + ssh_key = xobj["#{xpath_context}/SSH_PUBLIC_KEY"] + if ssh_key + cc << "ssh_authorized_keys:\n" + ssh_key.split("\n").each do |key| + cc << "- #{key}\n" end - end; "ok" - workers.map(&:join); "ok" - - host_info << "USEDMEMORY=#{usedmemory.round}\n" - host_info << "USEDCPU=#{usedcpu.round}\n" - host_info << "FREEMEMORY=#{(totalmemory - usedmemory).round}\n" - host_info << "FREECPU=#{(totalcpu - usedcpu).round}\n" - - if do_cw - host_info << "CWMONTIME=#{Time.now.to_i}" - else - host_info << "CWMONTIME=#{cw_mon_time}" end - puts host_info - puts vms_info + cc end -private - #Get the associated capacity of the instance_type as cpu (in 100 percent - #e.g. 800) and memory (in KB) + # Get the associated capacity of the instance_type as cpu (in 100 percent + # e.g. 800) and memory (in KB) def instance_type_capacity(name) return 0, 0 if @instance_types[name].nil? - return (@instance_types[name]['cpu'].to_f * 100).to_i , - (@instance_types[name]['memory'].to_f * 1024 * 1024).to_i + + [(@instance_types[name]['cpu'].to_f * 100).to_i, + (@instance_types[name]['memory'].to_f * 1024 * 1024).to_i] end # Get the EC2 section of the template. If more than one EC2 section @@ -640,24 +562,24 @@ private ec2_deprecated = nil if @provision_type == :host - all_ec2_elements = xml.root.get_elements("//TEMPLATE/PROVISION") + all_ec2_elements = xml.root.get_elements('//TEMPLATE/PROVISION') else - all_ec2_elements = xml.root.get_elements("//USER_TEMPLATE/PUBLIC_CLOUD") + all_ec2_elements = xml.root.get_elements('//USER_TEMPLATE/PUBLIC_CLOUD') end # First, let's see if we have an EC2 site that matches # our desired host name - all_ec2_elements.each { |element| - cloud=element.elements["HOST"] + all_ec2_elements.each do |element| + cloud=element.elements['HOST'] if cloud && cloud.text.upcase == host.upcase ec2 = element else - cloud=element.elements["CLOUD"] + cloud=element.elements['CLOUD'] if cloud && cloud.text.upcase == host.upcase ec2_deprecated = element end end - } + end ec2 ||= ec2_deprecated @@ -667,76 +589,131 @@ private if all_ec2_elements.size == 1 ec2 = all_ec2_elements[0] else - raise RuntimeError.new("Cannot find PUBLIC_CLOUD element in deployment "\ - " file or no HOST site matching the requested in the "\ - " template.") + raise 'Cannot find PUBLIC_CLOUD element in deployment '\ + ' file or no HOST site matching the requested in the '\ + ' template.' end end ec2 end - # Retrieve the vm information from the EC2 instance - def parse_poll(instance, onevm, do_cw, cw_mon_time) + # Return state of the instance (ONE state) + def vm_state(instance) + if !instance.exists? + 'DELETED' + else + case instance.state.name + when 'pending', 'running' + 'RUNNING' + when 'shutting-down', 'terminated' + 'SHUTDOWN' + else + 'UNKNOWN' + end + end + end + + def get_vm_monitor_data(instance, onevm, do_cw) begin if onevm if do_cw - cloudwatch_str = cloudwatch_monitor_info(instance.instance_id, - onevm, - cw_mon_time) + cloudwatch_str = cloudwatch_monitor_info(instance.instance_id, onevm) else - previous_cpu = onevm["MONITORING/CPU"] || 0 - previous_netrx = onevm["MONITORING/NETRX"] || 0 - previous_nettx = onevm["MONITORING/NETTX"] || 0 + previous_cpu = onevm['MONITORING/CPU'] || 0 + previous_netrx = onevm['MONITORING/NETRX'] || 0 + previous_nettx = onevm['MONITORING/NETTX'] || 0 cloudwatch_str = "CPU=#{previous_cpu} NETTX=#{previous_nettx} NETRX=#{previous_netrx} " end else - cloudwatch_str = "" + cloudwatch_str = '' end - mem = onevm["TEMPLATE/MEMORY"].to_s - mem=mem.to_i*1024 - info = "#{POLL_ATTRIBUTE[:memory]}=#{mem} #{cloudwatch_str}" + mem = onevm['TEMPLATE/MEMORY'].to_s + mem = mem.to_i*1024 + info = "#{POLL_ATTRIBUTE[:memory]}=#{mem} #{cloudwatch_str}" - state = "" - if !instance.exists? - state = VM_STATE[:deleted] - else - state = case instance.state.name - when 'pending' - VM_STATE[:active] - when 'running' - VM_STATE[:active] - when 'shutting-down', 'terminated' - VM_STATE[:deleted] - else - VM_STATE[:unknown] - end - end - info << "#{POLL_ATTRIBUTE[:state]}=#{state} " - - EC2_POLL_ATTRS.map { |key| + EC2_POLL_ATTRS.map do |key| value = instance.send(key) - if !value.nil? && !value.empty? - if value.is_a?(Array) - value = value.map {|v| - v.group_id if v.is_a?(Aws::EC2::Types::GroupIdentifier) - }.join(",") - end + next unless !value.nil? && !value.empty? - info << "AWS_#{key.to_s.upcase}=\\\"#{URI::encode(value)}\\\" " + if value.is_a?(Array) + value = value.map do |v| + v.group_id if v.is_a?(Aws::EC2::Types::GroupIdentifier) + end.join(',') end - } - info - rescue + info << "AWS_#{key.to_s.upcase}=\"#{URI.encode(value)}\" " + end + rescue StandardError # Unkown state if exception occurs retrieving information from # an instance - "#{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:unknown]} " + info = "#{POLL_ATTRIBUTE[:state]}=UNKNOWN" end + Base64.encode64(info).gsub("\n", '') end + def fetch_vms_data(with_monitoring = false) + ec2_connect + + # Build an array of VMs and last_polls for monitoring + vpool = OpenNebula::VirtualMachinePool.new(OpenNebula::Client.new, + OpenNebula::VirtualMachinePool::INFO_ALL_VM) + vpool.info + onevm_info = {} + + if @cw_mon_time.nil? + @cw_mon_time = Time.now.to_i + else + @cw_mon_time = cw_mon_time.to_i + end + + do_cw = (Time.now.to_i - @cw_mon_time) >= 360 + vpool.each do |vm| + onevm_info[vm.deploy_id] = vm + end + + work_q = Queue.new + @ec2.instances.each {|i| work_q.push i } + + vms = [] + workers = (0...20).map do + Thread.new do + begin + while (i = work_q.pop(true)) + vm_state = vm_state(i) + next if vm_state != 'RUNNING' + + one_id = i.tags.find {|t| t.key == 'ONE_ID' } + one_id = one_id.value if one_id + + vm = { :uuid => i.instance_id, + :id => one_id || -1, + :name => i.instance_id, + :type => i.instance_type, + :state => vm_state } + + if with_monitoring + vm[:monitor] = \ + get_vm_monitor_data(i, onevm_info[i.id], do_cw) + end + + vms << vm + end + rescue ThreadError + nil + rescue StandardError + raise + end + end + end + workers.map(&:join) + + @db.insert(vms) unless vms.empty? + + vms + end # Execute an EC2 command # +deploy_id+: String, VM id in EC2 @@ -745,7 +722,7 @@ private begin i = get_instance(deploy_id) i.send(EC2[ec2_action][:cmd]) - rescue => e + rescue StandardError => e raise e end end @@ -753,24 +730,24 @@ private # Generate the options for the given command from the xml provided in the # template. The available options for each command are defined in the EC2 # constant - def generate_options(action, xml, extra_params={}) + def generate_options(action, xml, extra_params = {}) opts = extra_params || {} if EC2[action][:args] - EC2[action][:args].each {|k,v| + EC2[action][:args].each do |k, v| str = ec2_value(xml, k, &v[:proc]) - if str - tmp = opts - last_key = nil - v[:opt].split('/').each { |key| - k = key.to_sym - tmp = tmp[last_key] if last_key - tmp[k] = {} - last_key = k - } - tmp[last_key] = str + next unless str + + tmp = opts + last_key = nil + v[:opt].split('/').each do |key| + k = key.to_sym + tmp = tmp[last_key] if last_key + tmp[k] = {} + last_key = k end - } + tmp[last_key] = str + end end opts @@ -791,189 +768,159 @@ private end def value_from_xml(xml, name) - if xml - element = xml.elements[name] - element.text.strip if element && element.text - end + return unless xml + + element = xml.elements[name] + element.text.strip if element && element.text end # Waits until ec2 machine reach the desired state - # +state+: String, is the desired state, needs to be a real state of Amazon ec2: running, stopped, terminated, pending + # +state+: String, is the desired state, needs to be a real state of Amazon + # ec2: running, stopped, terminated, pending # +deploy_id+: String, VM id in EC2 def wait_state(state, deploy_id) ready = (state == 'stopped') || (state == 'pending') || (state == 'running') || (state == 'terminated') - raise "Waiting for an invalid state" if !ready + raise 'Waiting for an invalid state' unless ready + t_init = Time.now - begin + loop do wstate = get_instance(deploy_id).state.name rescue nil - raise "Ended in invalid state" if Time.now - t_init > @state_change_timeout + + raise 'Ended in invalid state' if Time.now - t_init > @state_change_timeout + sleep 3 - end while wstate != state + break if wstate == state + end end # Load the default values that will be used to create a new instance, if - # not provided in the template. These values are defined in the EC2_CONF - # file + # not provided in the template. These values are defined in the EC2_CONF + # file def load_default_template_values - @defaults = Hash.new + return unless File.exist?(EC2_DRIVER_DEFAULT) - if File.exist?(EC2_DRIVER_DEFAULT) - fd = File.new(EC2_DRIVER_DEFAULT) - xml = REXML::Document.new fd - fd.close() + @defaults = {} + fd = File.new(EC2_DRIVER_DEFAULT) + xml = REXML::Document.new fd + fd.close - return if !xml || !xml.root + return if !xml || !xml.root - ec2 = xml.root.elements["PUBLIC_CLOUD"] + ec2 = xml.root.elements['PUBLIC_CLOUD'] - return if !ec2 + return unless ec2 - EC2.each {|action, hash| - if hash[:args] - hash[:args].each { |key, value| - @defaults[key.to_sym] = value_from_xml(ec2, key) - } - end - } + EC2.each do |_action, hash| + next unless hash[:args] + + hash[:args].each do |key, _value| + @defaults[key.to_sym] = value_from_xml(ec2, key) + end end end # Retrieve the instance from EC2 def get_instance(id) - begin - instance = @ec2.instance(id) - if instance.exists? - return instance - else - raise RuntimeError.new("Instance #{id} does not exist") - end - rescue => e - raise e - end - end + inst = @ec2.instance(id) + raise RuntimeError "Instance #{id} does not exist" unless inst.exists? - # Build template for importation - def vm_to_one(instance) - cpu, mem = instance_type_capacity(instance.instance_type) - - cpu = cpu.to_f / 100 - vcpu = cpu.ceil - mem = mem.to_i / 1024 # Memory for templates expressed in MB - - str = "NAME = \"Instance from #{instance.id}\"\n"\ - "CPU = \"#{cpu}\"\n"\ - "VCPU = \"#{vcpu}\"\n"\ - "MEMORY = \"#{mem}\"\n"\ - "HYPERVISOR = \"ec2\"\n"\ - "PUBLIC_CLOUD = [\n"\ - " TYPE =\"ec2\",\n"\ - " AMI =\"#{instance.image_id}\"\n"\ - "]\n"\ - "IMPORT_VM_ID = \"#{instance.id}\"\n"\ - "SCHED_REQUIREMENTS=\"NAME=\\\"#{@host}\\\"\"\n"\ - "DESCRIPTION = \"Instance imported from EC2, from instance"\ - " #{instance.id}, AMI #{instance.image_id}\"\n" - - str + inst end # Extract monitoring information from Cloud Watch # CPU, NETTX and NETRX - def cloudwatch_monitor_info(id, onevm, cw_mon_time) + def cloudwatch_monitor_info(id, onevm) cw=Aws::CloudWatch::Client.new # CPU begin cpu = get_cloudwatch_metric(cw, - "CPUUtilization", - cw_mon_time, - ["Average"], - "Percent", - id) - if cpu[:datapoints].size != 0 + 'CPUUtilization', + ['Average'], + 'Percent', + id) + if !cpu[:datapoints].empty? cpu = cpu[:datapoints][-1][:average] else - cpu = onevm["MONITORING/CPU"] || 0 + cpu = onevm['MONITORING/CPU'] || 0 end cpu = cpu.to_f.round(2).to_s - rescue => e - OpenNebula::log_error(e.message) + rescue StandardError => e + OpenNebula.log_error(e.message) end # NETTX nettx = 0 begin nettx_dp = get_cloudwatch_metric(cw, - "NetworkOut", - cw_mon_time, - ["Sum"], - "Bytes", + 'NetworkOut', + ['Sum'], + 'Bytes', id)[:datapoints] - previous_nettx = onevm["/VM/MONITORING/NETTX"] - nettx = previous_nettx ? previous_nettx.to_i : 0 + previous_nettx = onevm['/VM/MONITORING/NETTX'] + previous_nettx ? nettx = previous_nettx.to_i : nettx = 0 - nettx_dp.each{|dp| + nettx_dp.each do |dp| nettx += dp[:sum].to_i - } - rescue => e - OpenNebula::log_error(e.message) + end + rescue StandardError => e + OpenNebula.log_error(e.message) end # NETRX netrx = 0 begin netrx_dp = get_cloudwatch_metric(cw, - "NetworkIn", - cw_mon_time, - ["Sum"], - "Bytes", + 'NetworkIn', + ['Sum'], + 'Bytes', id)[:datapoints] - previous_netrx = onevm["/VM/MONITORING/NETRX"] - netrx = previous_netrx ? previous_netrx.to_i : 0 + previous_netrx = onevm['/VM/MONITORING/NETRX'] + previous_netrx ? netrx = previous_netrx.to_i : netrx = 0 - netrx_dp.each{|dp| + netrx_dp.each do |dp| netrx += dp[:sum].to_i - } - rescue => e - OpenNebula::log_error(e.message) + end + rescue StandardError => e + OpenNebula.log_error(e.message) end - "CPU=#{cpu.to_s} NETTX=#{nettx.to_s} NETRX=#{netrx.to_s} " + "CPU=#{cpu} NETTX=#{nettx} NETRX=#{netrx} " end # Get metric from AWS/EC2 namespace from the last poll - def get_cloudwatch_metric(cw, metric_name, last_poll, statistics, units, id) - dt = 60 # period - t0 = (Time.at(last_poll.to_i)-65) # last poll time - t = (Time.now-60) # actual time + def get_cloudwatch_metric(cw, metric_name, statistics, units, id) + dt = 60 # period + t0 = (Time.at(@cw_mon_time.to_i)-65) # last poll time + t = (Time.now-60) # actual time - while ((t - t0)/dt >= 1440) do dt+=60 end + while (t - t0)/dt >= 1440 do dt+=60 end - options={:namespace=>"AWS/EC2", + options={ :namespace=>'AWS/EC2', :metric_name=>metric_name, :start_time=> t0.iso8601, :end_time=> t.iso8601, :period=>dt, :statistics=>statistics, :unit=>units, - :dimensions=>[{:name=>"InstanceId", :value=>id}]} + :dimensions=>[{ :name=>'InstanceId', :value=>id }] } cw.get_metric_statistics(options) end - # TODO move this method to a OneGate library + # TODO: move this method to a OneGate library def generate_onegate_token(xml) - # Create the OneGate token string - vmid_str = xml["ID"] - stime_str = xml["STIME"] + # Create the OneGate token string + vmid_str = xml['ID'] + stime_str = xml['STIME'] str_to_encrypt = "#{vmid_str}:#{stime_str}" user_id = xml['TEMPLATE/CREATED_BY'] if user_id.nil? - OpenNebula::log_error("VMID:#{vNid} CREATED_BY not present" \ - " in the VM TEMPLATE") - return nil + OpenNebula.log_error("VMID:#{vNid} CREATED_BY not present" \ + ' in the VM TEMPLATE') + return end user = OpenNebula::User.new_with_id(user_id, @@ -981,25 +928,51 @@ private rc = user.info if OpenNebula.is_error?(rc) - OpenNebula::log_error("VMID:#{vmid} user.info" \ + OpenNebula.log_error("VMID:#{vmid} user.info" \ " error: #{rc.message}") - return nil + return end token_password = user['TEMPLATE/TOKEN_PASSWORD'] if token_password.nil? - OpenNebula::log_error(VMID:#{vmid} TOKEN_PASSWORD not present"\ + OpenNebula.log_error(:VMID => "#{vmid} TOKEN_PASSWORD not present"\ " in the USER:#{user_id} TEMPLATE") - return nil + return end - cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc") + cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc') cipher.encrypt cipher.key = token_password onegate_token = cipher.update(str_to_encrypt) onegate_token << cipher.final - onegate_token_64 = Base64.encode64(onegate_token).chop + Base64.encode64(onegate_token).chop end + +end + +############################################################################ +# Module Interface +# Interface for probe_db - VirtualMachineDB +############################################################################ +module DomainList + + def self.state_info(*args) + ec2 = EC2Driver.new(*args) + + vms = ec2.retreive_vms_data + + info = {} + vms.each do |vm| + info[vm[:uuid]] = { :id => vm[:id], + :uuid => vm[:uuid], + :name => vm[:name], + :state => vm[:state], + :hyperv => 'ec2' } + end + + info + end + end diff --git a/src/vmm_mad/remotes/ec2/save b/src/vmm_mad/remotes/ec2/save index 7271e755f2..9f65e99890 100755 --- a/src/vmm_mad/remotes/ec2/save +++ b/src/vmm_mad/remotes/ec2/save @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby +#!/bin/bash # -------------------------------------------------------------------------- # # Copyright 2002-2019, OpenNebula Project, OpenNebula Systems # @@ -14,36 +14,7 @@ # 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 !defined?(ONE_LOCATION) - -if !ONE_LOCATION - RUBY_LIB_LOCATION = '/usr/lib/one/ruby' if !defined?(RUBY_LIB_LOCATION) - GEMS_LOCATION = '/usr/share/one/gems' if !defined?(GEMS_LOCATION) -else - RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' if !defined?(RUBY_LIB_LOCATION) - GEMS_LOCATION = ONE_LOCATION + '/share/gems' if !defined?(GEMS_LOCATION) -end - -if File.directory?(GEMS_LOCATION) - Gem.use_paths(GEMS_LOCATION) -end - -$LOAD_PATH << RUBY_LIB_LOCATION -$LOAD_PATH << File.dirname(__FILE__) - -require 'ec2_driver' - -deploy_id = ARGV[0] -file = ARGV[1] -host = ARGV[2] - - -begin - ec2_drv = EC2Driver.new(host) - ec2_drv.save(deploy_id) -rescue Exception => e - OpenNebula.handle_driver_exception("Save", e, host, deploy_id, nil, file) -end +#--------------------------------------------------------------------------- # +SCRIPT_NAME=$(basename $0) +echo "Action $SCRIPT_NAME not supported" 1>&2