We have many tables to display resources in our UI, and we keep copying and pasting the same code. Some of these tables also have incorrectly copied styles. When we want to make changes to a table, it requires updating multiple places. The new component will help us solve these issues. We have a similar `kv_data_card` component for displaying resource details, and I find it very useful.
38 lines
960 B
Ruby
38 lines
960 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Serializers::Vm < Serializers::Base
|
|
def self.serialize_internal(vm, options = {})
|
|
base = {
|
|
id: vm.ubid,
|
|
name: vm.name,
|
|
state: vm.display_state,
|
|
location: vm.display_location,
|
|
size: vm.display_size,
|
|
unix_user: vm.unix_user,
|
|
storage_size_gib: vm.storage_size_gib,
|
|
ip6: vm.ephemeral_net6&.nth(2),
|
|
ip4_enabled: vm.ip4_enabled,
|
|
ip4: vm.ephemeral_net4
|
|
}
|
|
|
|
if options[:include_path]
|
|
base[:path] = vm.path
|
|
end
|
|
|
|
if options[:detailed]
|
|
base.merge!(
|
|
firewalls: Serializers::Firewall.serialize(vm.firewalls, {include_path: true}),
|
|
private_ipv4: vm.nics.first.private_ipv4.network,
|
|
private_ipv6: vm.nics.first.private_ipv6.nth(2),
|
|
subnet: vm.nics.first.private_subnet.name
|
|
)
|
|
end
|
|
|
|
if options[:load_balancer]
|
|
base[:load_balancer_state] = vm.load_balancers_vms.state
|
|
end
|
|
|
|
base
|
|
end
|
|
end
|