selfprivacy.org.app/lib/logic/models/json/hetzner_server_info.dart

116 lines
2.7 KiB
Dart
Raw Normal View History

2021-03-26 15:38:39 +02:00
import 'package:json_annotation/json_annotation.dart';
part 'hetzner_server_info.g.dart';
@JsonSerializable()
class HetznerServerInfo {
2022-06-05 22:36:32 +03:00
HetznerServerInfo(
this.id,
this.name,
this.status,
this.created,
this.serverType,
this.location,
this.publicNet,
this.volumes,
);
2021-03-26 15:38:39 +02:00
final int id;
final String name;
final ServerStatus status;
final DateTime created;
final List<int> volumes;
2021-03-26 15:38:39 +02:00
@JsonKey(name: 'server_type')
final HetznerServerTypeInfo serverType;
@JsonKey(name: 'datacenter', fromJson: HetznerServerInfo.locationFromJson)
final HetznerLocation location;
@JsonKey(name: 'public_net')
final HetznerPublicNetInfo publicNet;
2022-06-05 22:36:32 +03:00
static HetznerLocation locationFromJson(final Map json) =>
2021-03-26 15:38:39 +02:00
HetznerLocation.fromJson(json['location']);
2022-06-05 22:36:32 +03:00
static HetznerServerInfo fromJson(final Map<String, dynamic> json) =>
2021-03-26 15:38:39 +02:00
_$HetznerServerInfoFromJson(json);
}
@JsonSerializable()
class HetznerPublicNetInfo {
2022-06-05 22:36:32 +03:00
HetznerPublicNetInfo(this.ipv4);
2022-08-29 21:18:07 +03:00
final HetznerIp4? ipv4;
2022-06-05 22:36:32 +03:00
static HetznerPublicNetInfo fromJson(final Map<String, dynamic> json) =>
_$HetznerPublicNetInfoFromJson(json);
}
@JsonSerializable()
class HetznerIp4 {
2022-06-05 22:36:32 +03:00
HetznerIp4(this.id, this.ip, this.blocked, this.reverseDns);
final bool blocked;
@JsonKey(name: 'dns_ptr')
final String reverseDns;
final int id;
final String ip;
2022-06-05 22:36:32 +03:00
static HetznerIp4 fromJson(final Map<String, dynamic> json) =>
_$HetznerIp4FromJson(json);
}
2021-03-26 15:38:39 +02:00
enum ServerStatus {
running,
initializing,
starting,
stopping,
off,
deleting,
migrating,
rebuilding,
unknown,
}
@JsonSerializable()
class HetznerServerTypeInfo {
2022-06-05 22:36:32 +03:00
HetznerServerTypeInfo(this.cores, this.memory, this.disk, this.prices);
2021-03-26 15:38:39 +02:00
final int cores;
final num memory;
final int disk;
final List<HetznerPriceInfo> prices;
2022-06-05 22:36:32 +03:00
static HetznerServerTypeInfo fromJson(final Map<String, dynamic> json) =>
2021-03-26 15:38:39 +02:00
_$HetznerServerTypeInfoFromJson(json);
}
@JsonSerializable()
class HetznerPriceInfo {
HetznerPriceInfo(this.hourly, this.monthly);
@JsonKey(name: 'price_hourly', fromJson: HetznerPriceInfo.getPrice)
final double hourly;
@JsonKey(name: 'price_monthly', fromJson: HetznerPriceInfo.getPrice)
final double monthly;
2022-06-05 22:36:32 +03:00
static HetznerPriceInfo fromJson(final Map<String, dynamic> json) =>
2021-03-26 15:38:39 +02:00
_$HetznerPriceInfoFromJson(json);
static double getPrice(final Map json) =>
double.parse(json['gross'] as String);
2021-03-26 15:38:39 +02:00
}
@JsonSerializable()
class HetznerLocation {
2022-06-05 22:36:32 +03:00
HetznerLocation(this.country, this.city, this.description, this.zone);
2021-03-26 15:38:39 +02:00
final String country;
final String city;
final String description;
@JsonKey(name: 'network_zone')
final String zone;
2022-06-05 22:36:32 +03:00
static HetznerLocation fromJson(final Map<String, dynamic> json) =>
2021-03-26 15:38:39 +02:00
_$HetznerLocationFromJson(json);
}