Skip to content

Instantly share code, notes, and snippets.

ems = ExtManagementSystem.find_by(:name => "my_ems")
vms = ems.vms
vm_count = vms.count
raise "Expected #{1234} VMs but got #{vm_count}" if vm_count != 1234
vms.each do |vm|
raise "Invalid availability zone for VM #{vm.ems_ref}" if vm.availability_zone.nil?
raise "Invalid flavor for VM #{vm.ems_ref}" if vm.flavor.nil?
#!/usr/bin/env ruby
require 'trollop'
require 'rbvmomi'
require 'rbvmomi/pbm'
require 'rbvmomi/trollop'
VIM = RbVmomi::VIM
PBM = RbVmomi::PBM
@agrare
agrare / record_ems_inventory.rb
Last active May 25, 2017 20:39
record_ems_inventory.rb
require 'vcr'
ems_name, _ = ARGV
raise "You must pass an ems name" if ems_name.nil?
VCR.configure do |config|
config.cassette_library_dir = Rails.root.join('vcr_cassettes')
config.hook_into :webmock
end
require 'rbvmomi'
require 'trollop'
def connect(host, user, password)
vim_opts = {
:ns => 'urn:vim25',
:rev => '4.1',
:host => host,
:ssl => true,
:insecure => true,
require "manageiq-messaging"
ManageIQ::Messaging.logger = Logger.new(STDOUT)
ManageIQ::Messaging::Client.open(
:host => "localhost",
:port => 61616,
:user => "admin",
:password => "smartvm",
:client_ref => "event_handler",
) do |client|
15:32:48,664 WARN [io.netty.channel.DefaultChannelPipeline] An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.: io.netty.handler.codec.DecoderException: java.lang.NullPointerException
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:442) [netty-all-4.1.9.Final.jar:4.1.9.Final]
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:248) [netty-all-4.1.9.Final.jar:4.1.9.Final]
at org.apache.activemq.artemis.core.protocol.ProtocolHandler$ProtocolDecoder.channelRead(ProtocolHandler.java:128) [artemis-server-2.2.0.jar:2.2.0]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [netty-all-4.1.9.Final.jar:4.1.9.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [netty-all-4.1.9.Final.jar:4.1.9.Final]
at io.netty.channel
/home/agrare/.bundle/ruby/2.3.0/manageiq-gems-pending-17ba45c6a0ed/lib/gems/pending/util/win32/miq-powershell.rb:216:in `process_root': undefined method `each_element' for nil:NilClass (NoMethodError)
from /home/agrare/.bundle/ruby/2.3.0/manageiq-gems-pending-17ba45c6a0ed/lib/gems/pending/util/win32/miq-powershell.rb:207:in `to_h'
from /home/agrare/workspace/redhat/manageiq/plugins/manageiq-providers-scvmm/app/models/manageiq/providers/microsoft/infra_manager/powershell.rb:39:in `powershell_xml_to_hash'
from /home/agrare/workspace/redhat/manageiq/plugins/manageiq-providers-scvmm/app/models/manageiq/providers/microsoft/infra_manager/powershell.rb:34:in `powershell_results_to_hash'
from /home/agrare/workspace/redhat/manageiq/plugins/manageiq-providers-scvmm/app/models/manageiq/providers/microsoft/infra_manager/powershell.rb:12:in `execute_powershell'
from plugins/manageiq-providers-scvmm/spec/tools/scvmm_data/generate_data.rb:38:in `<top (required)>'
#<Kubeclient::Common::WatchNotice type="MODIFIED", object={:kind=>"Pod", :apiVersion=>"v1", :metadata=>{:name=>"prometheus-2214073710-xh6k4", :generateName=>"prometheus-2214073710-", :namespace=>"prometheus", :selfLink=>"/api/v1/namespaces/prometheus/pods/prometheus-2214073710-xh6k4", :uid=>"5b2e929c-a756-11e7-8a08-001a4a162711", :resourceVersion=>"1096765", :creationTimestamp=>"2017-10-02T09:44:59Z", :labels=>{:app=>"prometheus", :"pod-template-hash"=>"2214073710"}, :annotations=>{:"kubernetes.io/created-by"=>"{\"kind\":\"SerializedReference\",\"apiVersion\":\"v1\",\"reference\":{\"kind\":\"ReplicaSet\",\"namespace\":\"prometheus\",\"name\":\"prometheus-2214073710\",\"uid\":\"5b2b1df9-a756-11e7-8a08-001a4a162711\",\"apiVersion\":\"extensions\",\"resourceVersion\":\"75480\"}}\n", :"openshift.io/scc"=>"restricted"}, :ownerReferences=>[{"apiVersion"=>"extensions/v1beta1", "kind"=>"ReplicaSet", "name"=>"prometheus-2214073710", "uid"=>"5b2b1df9-a756-11e7-8a08-001a4a162711", "controller"=>true, "blockOwnerDeletion
[----] D, [2017-10-25T16:08:26.573349 #5743:2ae9810130d4] DEBUG -- : Q-task_id([miq_provision_4]) MIQ(ManageIQ::Providers::Microsoft::InfraManager#run_powershell_script) Execute Powershell Script...
[----] D, [2017-10-25T16:09:21.639565 #5743:2ae9810130d4] DEBUG -- : Q-task_id([miq_provision_4]) MIQ(ManageIQ::Providers::Microsoft::InfraManager#run_powershell_script) Execute Powershell script... Complete - T
imings: {:execution=>55.06603479385376}
[----] D, [2017-10-25T16:09:21.704838 #5743:2ae9810130d4] DEBUG -- : Q-task_id([miq_provision_4]) $json = ConvertFrom-Json -InputObject '{"ID":"d25eaeb0-5354-4d5e-b82c-3635db0d66c7"}
'; $vm = Get-SCVirtualMachine -ID $json.ID;
Set-SCVirtualMachine -VM $vm -CPUCount 1 -DynamicMemoryEnabled $false -MemoryMB 1024 | Out-Null; $adapter = $vm | SCVirtualNetworkAdapter; Set-SCVirtualNetworkAdapter
-VirtualNetworkAdapter $adapter -LogicalNetwork (Get-SCLogicalNetwork -Name 'test-vm-network') -VMNetwork (Get-S
require 'winrm'
def log(level, message)
@method = 'migration'
$evm.log(level, "#{@method} - #{message}")
end
prov = $evm.root['miq_provision']
vm = prov.destination