github.com/GoogleCloudPlatform/compute-image-tools/cli_tools@v0.0.0-20240516224744-de2dabc4ed1b/common/disk/disk.go (about) 1 // Copyright 2022 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License 14 15 package disk 16 17 import ( 18 "errors" 19 20 "github.com/GoogleCloudPlatform/compute-image-tools/cli_tools/common/domain" 21 "github.com/GoogleCloudPlatform/compute-image-tools/cli_tools/common/utils/daisyutils" 22 ) 23 24 type defaultDisk struct { 25 project, zone, diskName, uri string 26 } 27 28 // NewDisk constructs a convenience object for passing the disk's project, disk name, disk zone, 29 // and URI. 30 func NewDisk(project, zone, diskName string) (disk domain.Disk, err error) { 31 if project == "" || zone == "" || diskName == "" { 32 return disk, errors.New("Error creating new disk: project, zone or diskName cannot be empty") 33 } 34 35 disk = &defaultDisk{ 36 project: project, 37 diskName: diskName, 38 zone: zone, 39 uri: daisyutils.GetDiskURI(project, zone, diskName), 40 } 41 return disk, nil 42 } 43 44 // GetProject returns the project for the disk. 45 func (d *defaultDisk) GetProject() string { 46 return d.project 47 } 48 49 // GetZoneName returns the disk's zone. 50 func (d *defaultDisk) GetZone() string { 51 return d.zone 52 } 53 54 // GetDiskName returns the disk's name. 55 func (d *defaultDisk) GetDiskName() string { 56 return d.diskName 57 } 58 59 // GetURI returns the global GCP URI for the image. 60 func (d *defaultDisk) GetURI() string { 61 return d.uri 62 }