yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/google/machinetype.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 "yunion.io/x/cloudmux/pkg/cloudprovider" 22 ) 23 24 type SMachineType struct { 25 Id string 26 CreationTimestamp time.Time 27 Name string 28 Description string 29 GuestCpus int 30 MemoryMb int 31 ImageSpaceGb int 32 MaximumPersistentDisks int 33 MaximumPersistentDisksSizeGb int 34 Zone string 35 SelfLink string 36 IsSharedCpu bool 37 Kind string 38 } 39 40 func (region *SRegion) GetMachineTypes(zone string, maxResults int, pageToken string) ([]SMachineType, error) { 41 machines := []SMachineType{} 42 params := map[string]string{} 43 if len(zone) == 0 { 44 return nil, cloudprovider.ErrNotFound 45 } 46 resource := fmt.Sprintf("zones/%s/machineTypes", zone) 47 return machines, region.List(resource, params, maxResults, pageToken, &machines) 48 } 49 50 func (region *SRegion) GetMachineType(id string) (*SMachineType, error) { 51 machine := &SMachineType{} 52 err := region.client.ecsGet("machineTypes", id, machine) 53 if err != nil { 54 return nil, err 55 } 56 return machine, nil 57 }