yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/google/network.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  	"time"
    19  
    20  	"yunion.io/x/onecloud/pkg/util/rbacutils"
    21  	"yunion.io/x/pkg/util/netutils"
    22  
    23  	api "yunion.io/x/cloudmux/pkg/apis/compute"
    24  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    25  )
    26  
    27  type SNetwork struct {
    28  	GoogleTags
    29  	wire *SWire
    30  }
    31  
    32  func (network *SNetwork) GetProjectId() string {
    33  	return network.wire.vpc.region.GetProjectId()
    34  }
    35  
    36  func (self *SNetwork) GetName() string {
    37  	return self.wire.vpc.GetName()
    38  }
    39  
    40  func (self *SNetwork) GetId() string {
    41  	return self.wire.vpc.GetId()
    42  }
    43  
    44  func (self *SNetwork) GetGlobalId() string {
    45  	return self.wire.vpc.GetGlobalId()
    46  }
    47  
    48  func (self *SNetwork) Refresh() error {
    49  	return self.wire.vpc.Refresh()
    50  }
    51  
    52  func (network *SNetwork) IsEmulated() bool {
    53  	return false
    54  }
    55  
    56  func (network *SNetwork) GetStatus() string {
    57  	return api.NETWORK_INTERFACE_STATUS_AVAILABLE
    58  }
    59  
    60  func (network *SNetwork) GetCreatedAt() time.Time {
    61  	return time.Time{}
    62  }
    63  
    64  func (network *SNetwork) Delete() error {
    65  	return network.wire.vpc.Delete()
    66  }
    67  
    68  func (network *SNetwork) GetAllocTimeoutSeconds() int {
    69  	return 300
    70  }
    71  
    72  func (network *SNetwork) GetIWire() cloudprovider.ICloudWire {
    73  	return network.wire
    74  }
    75  
    76  func (self *SNetwork) GetIpStart() string {
    77  	pref, _ := netutils.NewIPV4Prefix(self.wire.vpc.IpCidrRange)
    78  	startIp := pref.Address.NetAddr(pref.MaskLen) // 0
    79  	startIp = startIp.StepUp()                    // 1
    80  	return startIp.String()
    81  }
    82  
    83  func (self *SNetwork) GetIpEnd() string {
    84  	pref, _ := netutils.NewIPV4Prefix(self.wire.vpc.IpCidrRange)
    85  	endIp := pref.Address.BroadcastAddr(pref.MaskLen) // 255
    86  	endIp = endIp.StepDown()                          // 254
    87  	return endIp.String()
    88  }
    89  
    90  func (self *SNetwork) GetIpMask() int8 {
    91  	pref, _ := netutils.NewIPV4Prefix(self.wire.vpc.IpCidrRange)
    92  	return pref.MaskLen
    93  }
    94  
    95  func (self *SNetwork) GetGateway() string {
    96  	return self.wire.vpc.GatewayAddress
    97  }
    98  
    99  func (network *SNetwork) GetServerType() string {
   100  	return api.NETWORK_TYPE_GUEST
   101  }
   102  
   103  func (network *SNetwork) GetIsPublic() bool {
   104  	return true
   105  }
   106  
   107  func (network *SNetwork) GetPublicScope() rbacutils.TRbacScope {
   108  	return rbacutils.ScopeDomain
   109  }