@@ -27,6 +27,7 @@ type ProtocolEditCommand struct {
2727 Sticky string
2828 ClientTimeout int
2929 ServerTimeout int
30+ SslId int
3031}
3132
3233func NewProtocolEditCommand (sl * metadata.SoftlayerCommand ) * ProtocolEditCommand {
@@ -37,23 +38,30 @@ func NewProtocolEditCommand(sl *metadata.SoftlayerCommand) *ProtocolEditCommand
3738 cobraCmd := & cobra.Command {
3839 Use : "protocol-edit" ,
3940 Short : T ("Edit load balancer protocol" ),
40- Long : T ("${COMMAND_NAME} sl loadbal protocol-edit (--id LOADBAL_ID) (--protocol-uuid PROTOCOL_UUID) [--front-protocol PROTOCOL] [back-protocol PROTOCOL] [--front-port PORT] [--back-port PORT] [-m, --method METHOD] [-c, --connections CONNECTIONS] [--sticky cookie | source-ip] [--client-timeout SECONDS] [--server-timeout SECONDS]" ),
41- Args : metadata .NoArgs ,
41+ Long : T (`Use '${COMMAND_NAME} sl loadbal detail' to find the --protocol-uuid values for a loadbalancer
42+ Example:
43+ ${COMMAND_NAME} sl loadbal protocol-add --id 1115129 --protocol-uuid 8ec8911a-c32d-4678-89fe-979f182c822f --ssl-id 123
44+ This command changes the SSL certificate
45+ ` ),
46+ Args : metadata .NoArgs ,
4247 RunE : func (cmd * cobra.Command , args []string ) error {
4348 return thisCmd .Run (args )
4449 },
4550 }
46- cobraCmd .Flags ().IntVar (& thisCmd .Id , "id" , 0 , T ("ID for the load balancer [required]" ))
51+ cobraCmd .Flags ().IntVar (& thisCmd .Id , "id" , - 1 , T ("ID for the load balancer [required]" ))
4752 cobraCmd .Flags ().StringVar (& thisCmd .ProtocolUuid , "protocol-uuid" , "" , T ("UUID of the protocol you want to edit." ))
48- cobraCmd .Flags ().StringVar (& thisCmd .FrontProtocol , "front-protocol" , "HTTP " , T ("Protocol type to use for incoming connections: [HTTP|HTTPS|TCP]. Default: HTTP" ))
53+ cobraCmd .Flags ().StringVar (& thisCmd .FrontProtocol , "front-protocol" , "" , T ("Protocol type to use for incoming connections: [HTTP|HTTPS|TCP]. Default: HTTP" ))
4954 cobraCmd .Flags ().StringVar (& thisCmd .BackProtocol , "back-protocol" , "" , T ("Protocol type to use when connecting to backend servers: [HTTP|HTTPS|TCP]. Defaults to whatever --front-protocol is" ))
50- cobraCmd .Flags ().IntVar (& thisCmd .FrontPort , "front-port" , 80 , T ("Internet side port" ))
51- cobraCmd .Flags ().IntVar (& thisCmd .BackPort , "back-port" , 80 , T ("Private side port" ))
52- cobraCmd .Flags ().StringVarP (& thisCmd .Method , "method" , "m" , "ROUNDROBIN " , T ("Balancing Method: [ROUNDROBIN|LEASTCONNECTION|WEIGHTED_RR]" ))
53- cobraCmd .Flags ().IntVarP (& thisCmd .Connections , "connections" , "c" , 0 , T ("Maximum number of connections to allow" ))
55+ cobraCmd .Flags ().IntVar (& thisCmd .FrontPort , "front-port" , - 1 , T ("Internet side port" ))
56+ cobraCmd .Flags ().IntVar (& thisCmd .BackPort , "back-port" , - 1 , T ("Private side port" ))
57+ cobraCmd .Flags ().StringVarP (& thisCmd .Method , "method" , "m" , "" , T ("Balancing Method: [ROUNDROBIN|LEASTCONNECTION|WEIGHTED_RR]" ))
58+ cobraCmd .Flags ().IntVarP (& thisCmd .Connections , "connections" , "c" , - 1 , T ("Maximum number of connections to allow" ))
5459 cobraCmd .Flags ().StringVar (& thisCmd .Sticky , "sticky" , "" , T ("Use 'cookie' or 'source-ip' to stick" ))
55- cobraCmd .Flags ().IntVar (& thisCmd .ClientTimeout , "client-timeout" , 0 , T ("Client side timeout setting, in seconds" ))
56- cobraCmd .Flags ().IntVar (& thisCmd .ServerTimeout , "server-timeout" , 0 , T ("Server side timeout setting, in seconds" ))
60+ cobraCmd .Flags ().IntVar (& thisCmd .ClientTimeout , "client-timeout" , - 1 , T ("Client side timeout setting, in seconds" ))
61+ cobraCmd .Flags ().IntVar (& thisCmd .ServerTimeout , "server-timeout" , - 1 , T ("Server side timeout setting, in seconds" ))
62+ cobraCmd .Flags ().IntVar (& thisCmd .SslId , "ssl-id" , - 1 , T ("Identifier of the SSL certificate to attach to this protocol. Only valid for HTTPS." ))
63+ cobraCmd .MarkFlagRequired ("id" )
64+ cobraCmd .MarkFlagRequired ("protocol-uuid" )
5765 thisCmd .Command = cobraCmd
5866 return thisCmd
5967}
@@ -62,7 +70,7 @@ func (cmd *ProtocolEditCommand) Run(args []string) error {
6270 protocolConfiguration := datatypes.Network_LBaaS_LoadBalancerProtocolConfiguration {}
6371
6472 loadbalID := cmd .Id
65- if loadbalID == 0 {
73+ if loadbalID == - 1 {
6674 return errors .NewMissingInputError ("--id" )
6775 }
6876
@@ -71,45 +79,37 @@ func (cmd *ProtocolEditCommand) Run(args []string) error {
7179 return errors .New (T ("Failed to get load balancer: {{.ERR}}." , map [string ]interface {}{"ERR" : err .Error ()}))
7280 }
7381
74- protoUUID := cmd .ProtocolUuid
75- if protoUUID == "" {
82+ if cmd .ProtocolUuid == "" {
7683 return errors .NewMissingInputError ("--protocol-uuid" )
7784 }
78- protocolConfiguration .ListenerUuid = & protoUUID
85+ protocolConfiguration .ListenerUuid = & cmd . ProtocolUuid
7986
8087 if cmd .FrontProtocol != "" {
81- frontProtocol := cmd .FrontProtocol
82- protocolConfiguration .FrontendProtocol = & frontProtocol
88+ protocolConfiguration .FrontendProtocol = & cmd .FrontProtocol
8389 }
8490
8591 if cmd .BackProtocol != "" {
86- backProtocol := cmd .BackProtocol
87- protocolConfiguration .BackendProtocol = & backProtocol
92+ protocolConfiguration .BackendProtocol = & cmd .BackProtocol
8893 }
8994
90- if cmd .FrontPort != 0 {
91- frontPort := cmd .FrontPort
92- protocolConfiguration .FrontendPort = & frontPort
95+ if cmd .FrontPort != - 1 {
96+ protocolConfiguration .FrontendPort = & cmd .FrontPort
9397 }
9498
95- if cmd .BackPort != 0 {
96- backPort := cmd .BackPort
97- protocolConfiguration .BackendPort = & backPort
99+ if cmd .BackPort != - 1 {
100+ protocolConfiguration .BackendPort = & cmd .BackPort
98101 }
99102
100103 if cmd .Method != "" {
101- method := cmd .Method
102- protocolConfiguration .LoadBalancingMethod = & method
104+ protocolConfiguration .LoadBalancingMethod = & cmd .Method
103105 }
104106
105- if cmd .ClientTimeout != 0 {
106- cTimeout := cmd .ClientTimeout
107- protocolConfiguration .ClientTimeout = & cTimeout
107+ if cmd .ClientTimeout != - 1 {
108+ protocolConfiguration .ClientTimeout = & cmd .ClientTimeout
108109 }
109110
110- if cmd .ServerTimeout != 0 {
111- sTimeout := cmd .ServerTimeout
112- protocolConfiguration .ServerTimeout = & sTimeout
111+ if cmd .ServerTimeout != - 1 {
112+ protocolConfiguration .ServerTimeout = & cmd .ServerTimeout
113113 }
114114
115115 var sessionType string
@@ -123,12 +123,17 @@ func (cmd *ProtocolEditCommand) Run(args []string) error {
123123 return errors .NewInvalidUsageError (T ("Value of option '--sticky' should be cookie or source-ip" ))
124124 }
125125
126- if cmd .Connections != 0 {
127- connections := cmd .Connections
128- protocolConfiguration .MaxConn = & connections
126+ if cmd .Connections != - 1 {
127+ protocolConfiguration .MaxConn = & cmd .Connections
129128 }
130129
131- _ , err = cmd .LoadBalancerManager .AddLoadBalancerListener (& loadbalancerUUID , []datatypes.Network_LBaaS_LoadBalancerProtocolConfiguration {protocolConfiguration })
130+ if cmd .SslId != 0 {
131+ protocolConfiguration .TlsCertificateId = & cmd .SslId
132+ }
133+
134+ _ , err = cmd .LoadBalancerManager .AddLoadBalancerListener (
135+ & loadbalancerUUID , []datatypes.Network_LBaaS_LoadBalancerProtocolConfiguration {protocolConfiguration },
136+ )
132137 if err != nil {
133138 return errors .New (T ("Failed to edit protocol: {{.Error}}.\n " , map [string ]interface {}{"Error" : err .Error ()}))
134139 }
0 commit comments