Skip to content

Instantly share code, notes, and snippets.

@AparnaKarve
Last active November 21, 2017 08:46
Show Gist options
  • Save AparnaKarve/027c777897fb217406852994b204068b to your computer and use it in GitHub Desktop.
Save AparnaKarve/027c777897fb217406852994b204068b to your computer and use it in GitHub Desktop.
1. Create the Generic Object Definition record in Rails console -
go_def = GenericObjectDefinition.create(
:name => "LoadBalancerTestWithService",
:description => "LoadBalancerTestWithService",
: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
go = GenericObject.create(:name => "Test Load Balancer With Service", :generic_object_definition_id => go_def.id)
### Instead of creating a brand-new Service (as shown below), I recommend using an existing Service from the DB and assigning it to `service`
# service = Service.create(:name => "My Service", :description => "My Description") ### Do not create a service, use existing one instead
### Assign an existing Service from the DB to `service`
service = Service.first
go.abc = [service]
go.save
3. Add GO Resource to the Service Object
service.add_resource(go)
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