@@ -46,6 +46,11 @@ const (
4646 disableFailoverFlagName = "disable-auto-failover"
4747 enableDeleteProtectionFlagName = "enable-delete-protection"
4848 tagFlagName = "tag"
49+ capacityModeFlagName = "capacity-mode"
50+ capacityValueFlagName = "capacity-value"
51+
52+ provisionedCapacityMode = "provisioned"
53+ onDemandCapacityMode = "on_demand"
4954)
5055
5156const (
@@ -166,6 +171,28 @@ var (
166171 Aliases : []string {"ids" },
167172 Required : false ,
168173 }
174+
175+ capacityModeFlag = & cli.StringFlag {
176+ Name : capacityModeFlagName ,
177+ Usage : fmt .Sprintf ("The capacity mode to use for the namespace. Valid values are '%s' and '%s'" , onDemandCapacityMode , provisionedCapacityMode ),
178+ Aliases : []string {"cm" },
179+ Required : false ,
180+ Action : func (_ * cli.Context , s string ) error {
181+ switch s {
182+ case "" , onDemandCapacityMode , provisionedCapacityMode :
183+ return nil
184+ default :
185+ return fmt .Errorf ("invalid capacity mode %s, valid values are 'on_demand' and 'provisioned'" , s )
186+ }
187+ },
188+ }
189+
190+ capacityValueFlag = & cli.Float64Flag {
191+ Name : capacityValueFlagName ,
192+ Usage : "The capacity value to use for the namespace. Required if capacity mode is 'provisioned', ignored otherwise" ,
193+ Aliases : []string {"cv" },
194+ Required : false ,
195+ }
169196)
170197
171198type NamespaceClient struct {
@@ -362,6 +389,28 @@ func (c *NamespaceClient) updateNamespace(ctx *cli.Context, n *namespace.Namespa
362389 return PrintProto (res )
363390}
364391
392+ func (c * NamespaceClient ) updateNamespaceCloudApi (ctx * cli.Context , n * cloudNamespace.Namespace ) error {
393+ resourceVersion := n .ResourceVersion
394+ if v := ctx .String (ResourceVersionFlagName ); v != "" {
395+ resourceVersion = v
396+ }
397+
398+ res , err := c .cloudAPIClient .UpdateNamespace (c .ctx , & cloudservice.UpdateNamespaceRequest {
399+ AsyncOperationId : ctx .String (RequestIDFlagName ),
400+ Namespace : n .Namespace ,
401+ ResourceVersion : resourceVersion ,
402+ Spec : n .Spec ,
403+ })
404+ if err != nil {
405+ if isNothingChangedErr (ctx , err ) {
406+ return nil
407+ }
408+ return err
409+ }
410+
411+ return PrintProto (res )
412+ }
413+
365414func (c * NamespaceClient ) updateNamespaceTags (ctx * cli.Context , tagsToUpsert map [string ]string , tagsToRemove []string ) error {
366415 namespace := ctx .String (NamespaceFlagName )
367416 if len (namespace ) == 0 {
@@ -1812,6 +1861,58 @@ func NewNamespaceCommand(getNamespaceClientFn GetNamespaceClientFn) (CommandOut,
18121861 },
18131862 },
18141863 },
1864+ {
1865+ Name : "update-capacity" ,
1866+ Usage : "Set the capacity of a given namespace." ,
1867+ Aliases : []string {"uc" },
1868+ Flags : []cli.Flag {
1869+ NamespaceFlag ,
1870+ capacityModeFlag ,
1871+ capacityValueFlag ,
1872+ RequestIDFlag ,
1873+ ResourceVersionFlag ,
1874+ },
1875+ Action : func (ctx * cli.Context ) error {
1876+ nsID := ctx .String (NamespaceFlagName )
1877+ mode := ctx .String (capacityModeFlagName )
1878+ value := ctx .Float64 (capacityValueFlagName )
1879+ if mode == "" {
1880+ return fmt .Errorf ("capacity mode must be specified (either '%s' or '%s')" , onDemandCapacityMode , provisionedCapacityMode )
1881+ }
1882+ if mode == provisionedCapacityMode && value <= 0 {
1883+ return fmt .Errorf ("capacity value must be greater than 0 when capacity mode is '%s'" , provisionedCapacityMode )
1884+ }
1885+ var capacitySpec * cloudNamespace.CapacitySpec
1886+ switch mode {
1887+ case onDemandCapacityMode :
1888+ capacitySpec = & cloudNamespace.CapacitySpec {
1889+ Spec : & cloudNamespace.CapacitySpec_OnDemand_ {
1890+ OnDemand : & cloudNamespace.CapacitySpec_OnDemand {},
1891+ },
1892+ }
1893+ case provisionedCapacityMode :
1894+ capacitySpec = & cloudNamespace.CapacitySpec {
1895+ Spec : & cloudNamespace.CapacitySpec_Provisioned_ {
1896+ Provisioned : & cloudNamespace.CapacitySpec_Provisioned {
1897+ Value : value ,
1898+ },
1899+ },
1900+ }
1901+ }
1902+ nsResp , err := c .cloudAPIClient .GetNamespace (c .ctx , & cloudservice.GetNamespaceRequest {
1903+ Namespace : nsID ,
1904+ }) // TODO: Use getNamespaceCloudApi
1905+ if err != nil {
1906+ return err
1907+ }
1908+ ns := nsResp .GetNamespace ()
1909+ if ns != nil && ns .Spec == nil {
1910+ ns .Spec = & cloudNamespace.NamespaceSpec {}
1911+ }
1912+ ns .Spec .CapacitySpec = capacitySpec
1913+ return c .updateNamespaceCloudApi (ctx , ns )
1914+ },
1915+ },
18151916 }
18161917
18171918 // Export Related Command
0 commit comments