2018-04-05 18:39:20 +00:00
/*
Copyright 2018 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
2018-10-17 09:56:47 -06:00
"time"
2018-05-18 14:32:20 -07:00
rook "github.com/rook/rook/cmd/rook/rook"
2018-04-05 18:39:20 +00:00
"github.com/rook/rook/pkg/daemon/discover"
2018-10-17 09:56:47 -06:00
"github.com/rook/rook/pkg/util/flags"
2018-04-05 18:39:20 +00:00
"github.com/spf13/cobra"
)
2018-10-17 09:56:47 -06:00
var (
discoverCmd = & cobra . Command {
2023-04-10 13:31:38 -06:00
Use : "discover" ,
Short : "Discover devices" ,
Hidden : true , // do not advertise to end users
2018-10-17 09:56:47 -06:00
}
// interval between discovering devices
discoverDevicesInterval time . Duration
2019-10-07 11:14:43 +02:00
// Uses ceph-volume inventory to extend devices information
usesCVInventory bool
2018-10-17 09:56:47 -06:00
)
2018-04-05 18:39:20 +00:00
func init () {
2018-10-17 09:56:47 -06:00
discoverCmd . Flags (). DurationVar ( & discoverDevicesInterval , "discover-interval" , 60 * time . Minute , "interval between discovering devices (default 60m)" )
2019-10-07 11:14:43 +02:00
discoverCmd . Flags (). BoolVar ( & usesCVInventory , "use-ceph-volume" , false , "Use ceph-volume inventory to extend storage devices information (default false)" )
2018-10-17 09:56:47 -06:00
flags . SetFlagsFromEnv ( discoverCmd . Flags (), rook . RookEnvVarPrefix )
2018-04-05 18:39:20 +00:00
discoverCmd . RunE = startDiscover
}
func startDiscover ( cmd * cobra . Command , args [] string ) error {
2018-05-18 14:32:20 -07:00
rook . SetLogLevel ()
2018-04-05 18:39:20 +00:00
2018-05-18 14:32:20 -07:00
rook . LogStartupInfo ( discoverCmd . Flags ())
2018-04-05 18:39:20 +00:00
2019-06-05 10:23:07 +03:00
context := rook . NewContext ()
2022-02-21 13:03:51 +05:30
ctx := cmd . Context ()
2018-04-05 18:39:20 +00:00
2022-02-21 13:03:51 +05:30
err := discover . Run ( ctx , context , discoverDevicesInterval , usesCVInventory )
2018-04-05 18:39:20 +00:00
if err != nil {
2018-05-18 14:32:20 -07:00
rook . TerminateFatal ( err )
2018-04-05 18:39:20 +00:00
}
return nil
}