• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

softlayer / softlayer-go / 13824212013

13 Mar 2025 12:26AM UTC coverage: 95.953% (-2.2%) from 98.143%
13824212013

Pull #201

github

web-flow
Merge 0268bb9e4 into 80a745b76
Pull Request #201: Bump golang.org/x/net from 0.23.0 to 0.36.0

36825 of 38378 relevant lines covered (95.95%)

7.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/helpers/network/network.go
1
/**
2
 * Copyright 2016 IBM Corp.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *    http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package network
18

19
import (
20
        "fmt"
21

22
        "github.com/softlayer/softlayer-go/datatypes"
23
        "github.com/softlayer/softlayer-go/filter"
24
        "github.com/softlayer/softlayer-go/services"
25
        "github.com/softlayer/softlayer-go/session"
26
)
27

28
// GetNadcLbVipByName Get a virtual ip address by name attached to a load balancer
29
// appliance like the Netscaler VPX. In the case of some load balancer appliances
30
// looking up the virtual ip address by name is necessary since they don't get
31
// assigned an id.
32
func GetNadcLbVipByName(sess *session.Session, nadcId int, vipName string, mask ...string) (*datatypes.Network_LoadBalancer_VirtualIpAddress, error) {
×
33
        service := services.GetNetworkApplicationDeliveryControllerService(sess)
×
34

×
35
        service = service.
×
36
                Id(nadcId)
×
37

×
38
        if len(mask) > 0 {
×
39
                service = service.Mask(mask[0])
×
40
        }
×
41

42
        vips, err := service.GetLoadBalancers()
×
43

×
44
        if err != nil {
×
45
                return nil, fmt.Errorf("Error getting NADC load balancers: %s", err)
×
46
        }
×
47

48
        for _, vip := range vips {
×
49
                if *vip.Name == vipName {
×
50
                        return &vip, nil
×
51
                }
×
52
        }
53

54
        return nil, fmt.Errorf("Could not find any VIPs for NADC %d matching name %s", nadcId, vipName)
×
55
}
56

57
// GetNadcLbVipServiceByName Get a load balancer service by name attached to a load balancer
58
// appliance like the Netscaler VPX. In the case of some load balancer appliances
59
// looking up the virtual ip address by name is necessary since they don't get
60
// assigned an id.
61
func GetNadcLbVipServiceByName(
62
        sess *session.Session, nadcId int, vipName string, serviceName string, mask ...string,
63
) (*datatypes.Network_LoadBalancer_Service, error) {
×
64
        vipMask := "id,name,services[name,destinationIpAddress,destinationPort,weight,healthCheck,connectionLimit]"
×
65

×
66
        if len(mask) != 0 {
×
67
                vipMask = mask[0]
×
68
        }
×
69

70
        vip, err := GetNadcLbVipByName(sess, nadcId, vipName, vipMask)
×
71
        if err != nil {
×
72
                return nil, err
×
73
        }
×
74

75
        for _, service := range vip.Services {
×
76
                if *service.Name == serviceName {
×
77
                        return &service, nil
×
78
                }
×
79
        }
80

81
        return nil, fmt.Errorf(
×
82
                "Could not find service %s in VIP %s for load balancer %d",
×
83
                serviceName, vipName, nadcId)
×
84
}
85

86
// GetOsTypeByName retrieves an object of type SoftLayer_Network_Storage_Iscsi_OS_Type.
87
// To order block storage, OS type is required as a mandatory input.
88
// GetOsTypeByName helps in getting the OS id and keyName
89
// Examples:
90
// id:6   name: Hyper-V  keyName: HYPER_V
91
// id:12  name: Linux    keyName: LINUX
92
// id:22  name: VMWare   keyName: VMWARE
93
// id:30  name: Xen      keyName: XEN
94
func GetOsTypeByName(sess *session.Session, name string, args ...interface{}) (datatypes.Network_Storage_Iscsi_OS_Type, error) {
×
95
        var mask string
×
96
        if len(args) > 0 {
×
97
                mask = args[0].(string)
×
98
        }
×
99

100
        osTypes, err := services.GetNetworkStorageIscsiOSTypeService(sess).
×
101
                Mask(mask).
×
102
                Filter(filter.New(filter.Path("name").Eq(name)).Build()).
×
103
                GetAllObjects()
×
104

×
105
        if err != nil {
×
106
                return datatypes.Network_Storage_Iscsi_OS_Type{}, err
×
107
        }
×
108

109
        // An empty filtered result set does not raise an error
110
        if len(osTypes) == 0 {
×
111
                return datatypes.Network_Storage_Iscsi_OS_Type{}, fmt.Errorf("No OS type found with name of %s", name)
×
112
        }
×
113

114
        return osTypes[0], nil
×
115
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc