class ExtendedNodeStorageSerializer(NodeStorageSerializer): size_vms = s.IntegerField(read_only=True) size_snapshots = s.IntegerField(read_only=True) size_rep_snapshots = s.IntegerField(read_only=True) size_backups = s.IntegerField(read_only=True) # size_images = s.IntegerField(read_only=True) # TODO: fix size_images implementation and enable snapshots = s.IntegerField(read_only=True, source='snapshot_count') backups = s.IntegerField(read_only=True, source='backup_count') images = s.IntegerField(read_only=True, source='image_count') dcs = s.DcsField() vms = s.ArrayField(read_only=True)
class ExtendedNetworkSerializer(NetworkSerializer): _free_ip_subquery = '"vms_ipaddress"."vm_id" IS NULL AND "vms_ipaddress"."usage" = %d '\ 'AND "vms_ipaddress_vms"."vm_id" IS NULL' % IPAddress.VM ips_free_query = 'SELECT COUNT(*) FROM "vms_ipaddress" LEFT OUTER JOIN '\ '"vms_ipaddress_vms" ON ("vms_ipaddress"."id" = "vms_ipaddress_vms"."ipaddress_id") ' \ 'WHERE "vms_subnet"."uuid" = "vms_ipaddress"."subnet_id" '\ 'AND %s' % _free_ip_subquery ips_used_query = 'SELECT COUNT(*) FROM "vms_ipaddress" LEFT OUTER JOIN '\ '"vms_ipaddress_vms" ON ("vms_ipaddress"."id" = "vms_ipaddress_vms"."ipaddress_id") ' \ 'WHERE "vms_subnet"."uuid" = "vms_ipaddress"."subnet_id" '\ 'AND NOT (%s)' % _free_ip_subquery extra_select = frozendict({ 'ips_free': ips_free_query, 'ips_used': ips_used_query }) dcs = s.DcsField() ips_free = s.IntegerField(read_only=True) ips_used = s.IntegerField(read_only=True)
class ExtendedNodeSerializer(NodeSerializer): """ Extended node details serializer (read-only). """ extra_select = frozendict({ 'vms': '''SELECT COUNT(*) FROM "vms_vm" WHERE "vms_node"."uuid" = "vms_vm"."node_id"''', 'real_vms': '''SELECT COUNT(*) FROM "vms_vm" LEFT OUTER JOIN "vms_slavevm" ON ( "vms_vm"."uuid" = "vms_slavevm"."vm_id" ) WHERE "vms_node"."uuid" = "vms_vm"."node_id" AND "vms_slavevm"."id" IS NULL''', 'snapshots': '''SELECT COUNT(*) FROM "vms_snapshot" LEFT OUTER JOIN "vms_vm" ON ( "vms_vm"."uuid" = "vms_snapshot"."vm_id" ) WHERE "vms_node"."uuid" = "vms_vm"."node_id"''', 'backups': '''SELECT COUNT(*) FROM "vms_backup" WHERE "vms_node"."uuid" = "vms_backup"."node_id"''' }) dcs = s.DcsField() vms = s.IntegerField(read_only=True) snapshots = s.IntegerField(read_only=True) backups = s.IntegerField(read_only=True) real_vms = s.IntegerField(read_only=True)
class ExtendedImageSerializer(ImageSerializer): dcs = s.DcsField()
class ExtendedDomainSerializer(DomainSerializer): dcs = s.DcsField() records = s.IntegerField(read_only=True)
class ExtendedIsoSerializer(IsoSerializer): dcs = s.DcsField()
class ExtendedGroupSerializer(GroupSerializer): dcs = s.DcsField(required=False, source='dc_set')
class ExtendedTemplateSerializer(TemplateSerializer): dcs = s.DcsField()