Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save martinpovolny/b08a799e2174551a4d7fc6f4bac85ad2 to your computer and use it in GitHub Desktop.
Save martinpovolny/b08a799e2174551a4d7fc6f4bac85ad2 to your computer and use it in GitHub Desktop.
# 1. Create the Generic Object Definition record in Rails console -
go_def = GenericObjectDefinition.create(
:name => "LoadBalancerTest2",
:properties => {
:attributes => {:max_vms => "integer", :location => "string", :active => "boolean"},
:associations => {:vms => "Vm", :abc => "Service"},
:methods => [:add_vm, :remove_vm]
}
)
# 2. Create a Generic Object instance
$evm = MiqAeMethodService::MiqAeService.new(MiqAeEngine::MiqAeWorkspaceRuntime.new)
f = $evm.vmdb(:generic_object_definition).find_by(:name => "LoadBalancerTest2")
go2 = f.create_object(:name => "Test Load Balancer", :location => "Mahwah")
service2 = Service.create(:name => "My Service2", :description => "My Description2")
go2.instance_variable_set(:@ae_user, User.first)
go2.abc = [service]
go2.save
# 3. Add GO Resource to the Service Object
service.add_resource(go2)
service.save!
# Like `Service`, you can associate any other Reportable model with the GO object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment