diff --git a/hcloud/image.go b/hcloud/image.go index 87e9271b..43912006 100644 --- a/hcloud/image.go +++ b/hcloud/image.go @@ -32,6 +32,7 @@ type Image struct { Protection ImageProtection Deprecated time.Time // The zero value denotes the image is not deprecated. Labels map[string]string + Deleted time.Time } // IsDeprecated returns whether the image is deprecated. @@ -39,6 +40,11 @@ func (image *Image) IsDeprecated() bool { return !image.Deprecated.IsZero() } +// IsDeleted returns whether the image is deleted. +func (image *Image) IsDeleted() bool { + return !image.Deleted.IsZero() +} + // ImageProtection represents the protection level of an image. type ImageProtection struct { Delete bool diff --git a/hcloud/schema.go b/hcloud/schema.go index a50cafe0..940fefc2 100644 --- a/hcloud/schema.go +++ b/hcloud/schema.go @@ -291,6 +291,7 @@ func ImageFromSchema(s schema.Image) *Image { Delete: s.Protection.Delete, }, Deprecated: s.Deprecated, + Deleted: s.Deleted, } if s.Name != nil { i.Name = *s.Name diff --git a/hcloud/schema/image.go b/hcloud/schema/image.go index c354d9ea..7a3be887 100644 --- a/hcloud/schema/image.go +++ b/hcloud/schema/image.go @@ -19,6 +19,7 @@ type Image struct { RapidDeploy bool `json:"rapid_deploy"` Protection ImageProtection `json:"protection"` Deprecated time.Time `json:"deprecated"` + Deleted time.Time `json:"deleted"` Labels map[string]string `json:"labels"` } diff --git a/hcloud/schema_test.go b/hcloud/schema_test.go index a76c1c78..76895a9f 100644 --- a/hcloud/schema_test.go +++ b/hcloud/schema_test.go @@ -925,6 +925,7 @@ func TestImageFromSchema(t *testing.T) { "delete": true }, "deprecated": "2018-02-28T00:00:00+00:00", + "deleted": "2016-01-30T23:55:01+00:00", "labels": { "key": "value", "key2": "value2" @@ -961,6 +962,9 @@ func TestImageFromSchema(t *testing.T) { if !image.Created.Equal(time.Date(2016, 1, 30, 23, 55, 1, 0, time.UTC)) { t.Errorf("unexpected Created: %v", image.Created) } + if !image.Deleted.Equal(time.Date(2016, 1, 30, 23, 55, 1, 0, time.UTC)) { + t.Errorf("unexpected Deleted: %v", image.Deleted) + } if image.CreatedFrom == nil || image.CreatedFrom.ID != 1 || image.CreatedFrom.Name != "my-server1" { t.Errorf("unexpected CreatedFrom: %v", image.CreatedFrom) }