yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/google/regiondisk.go (about)

     1  // Copyright 2019 Yunion
     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 google
    16  
    17  import (
    18  	"fmt"
    19  	"time"
    20  )
    21  
    22  type SRegionDisk struct {
    23  	storage *SStorage
    24  
    25  	Id                     string
    26  	CreationTimestamp      time.Time
    27  	Name                   string
    28  	SizeGB                 int
    29  	Zone                   string
    30  	Status                 string
    31  	SelfLink               string
    32  	Type                   string
    33  	LastAttachTimestamp    time.Time
    34  	LastDetachTimestamp    time.Time
    35  	LabelFingerprint       string
    36  	PhysicalBlockSizeBytes string
    37  	Kind                   string
    38  }
    39  
    40  func (region *SRegion) GetRegionDisks(storageType string, maxResults int, pageToken string) ([]SRegionDisk, error) {
    41  	disks := []SRegionDisk{}
    42  	params := map[string]string{}
    43  	if len(storageType) > 0 {
    44  		params["filter"] = fmt.Sprintf(`type="%s/%s/projects/%s/regions/%s/diskTypes/%s"`, GOOGLE_COMPUTE_DOMAIN, GOOGLE_API_VERSION, region.GetProjectId(), region.Name, storageType)
    45  	}
    46  	resource := fmt.Sprintf("regions/%s/disks", region.Name)
    47  	return disks, region.List(resource, params, maxResults, pageToken, &disks)
    48  }
    49  
    50  func (region *SRegion) GetRegionDisk(id string) (*SRegionDisk, error) {
    51  	disk := &SRegionDisk{}
    52  	return disk, region.GetBySelfId(id, disk)
    53  }