Skip to content

CLOUDP-60870: Lists process disks/paritions, OM #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/cli/ops_manager_measurements.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ func OpsManagerMeasurementsBuilder() *cobra.Command {
}

cmd.AddCommand(OpsManagerMeasurementsProcessBuilder())

cmd.AddCommand(OpsManagerMeasurementsDisksBuilder())
return cmd
}
32 changes: 32 additions & 0 deletions internal/cli/ops_manager_measurements_disks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2020 MongoDB Inc
//
// 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 cli

import (
"github.com/mongodb/mongocli/internal/description"
"github.com/spf13/cobra"
)

func OpsManagerMeasurementsDisksBuilder() *cobra.Command {
cmd := &cobra.Command{
Use: "disks",
Aliases: []string{"disk"},
Short: description.Disks,
}

cmd.AddCommand(OpsManagerMeasurementsDisksListBuilder())

return cmd
}
77 changes: 77 additions & 0 deletions internal/cli/ops_manager_measurements_disks_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2020 MongoDB Inc
//
// 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 cli

import (
"github.com/mongodb/mongocli/internal/description"
"github.com/mongodb/mongocli/internal/flags"
"github.com/mongodb/mongocli/internal/json"
"github.com/mongodb/mongocli/internal/store"
"github.com/mongodb/mongocli/internal/usage"
"github.com/spf13/cobra"
)

type opsManagerMeasurementsDisksListsOpts struct {
globalOpts
listOpts
hostID string
store store.HostDisksLister
}

func (opts *opsManagerMeasurementsDisksListsOpts) init() error {
if opts.ProjectID() == "" {
return errMissingProjectID
}

var err error
opts.store, err = store.New()
return err
}

func (opts *opsManagerMeasurementsDisksListsOpts) Run() error {
listOpts := opts.newListOptions()
result, err := opts.store.HostDisks(opts.ProjectID(), opts.hostID, listOpts)

if err != nil {
return err
}

return json.PrettyPrint(result)
}

// mongocli om measurements process(es) disks lists [hostId]
func OpsManagerMeasurementsDisksListBuilder() *cobra.Command {
opts := &opsManagerMeasurementsDisksListsOpts{}
cmd := &cobra.Command{
Use: "list [hostId]",
Short: description.ListDisks,
Aliases: []string{"ls"},
Args: cobra.ExactArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.init()
},
RunE: func(cmd *cobra.Command, args []string) error {
opts.hostID = args[0]

return opts.Run()
},
}

cmd.Flags().IntVar(&opts.pageNum, flags.Page, 0, usage.Page)
cmd.Flags().IntVar(&opts.itemsPerPage, flags.Limit, 0, usage.Limit)
cmd.Flags().StringVar(&opts.projectID, flags.ProjectID, "", usage.ProjectID)

return cmd
}
46 changes: 46 additions & 0 deletions internal/cli/ops_manager_measurements_disks_list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2020 MongoDB Inc
//
// 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 cli

import (
"testing"

"github.com/golang/mock/gomock"
"github.com/mongodb/mongocli/internal/fixtures"
"github.com/mongodb/mongocli/internal/mocks"
)

func TestOpsManagerMeasurementsDisksListsOpts_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockHostDisksLister(ctrl)

defer ctrl.Finish()

expected := fixtures.ProcessDisks()

listOpts := &opsManagerMeasurementsDisksListsOpts{
hostID: "1",
store: mockStore,
}

opts := listOpts.newListOptions()
mockStore.
EXPECT().HostDisks(listOpts.projectID, listOpts.hostID, opts).
Return(expected, nil).
Times(1)

if err := listOpts.Run(); err != nil {
t.Fatalf("Run() unexpected error: %v", err)
}
}
49 changes: 49 additions & 0 deletions internal/mocks/mock_host_disks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions internal/store/host_disks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2020 MongoDB Inc
//
// 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 store

import (
"context"
"fmt"

atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas"
om "github.com/mongodb/go-client-mongodb-ops-manager/opsmngr"
"github.com/mongodb/mongocli/internal/config"
)

type HostDisksLister interface {
HostDisks(string, string, *atlas.ListOptions) (*atlas.ProcessDisksResponse, error)
}

// HostDisks encapsulate the logic to manage different cloud providers
func (s *Store) HostDisks(groupID, hostID string, opts *atlas.ListOptions) (*atlas.ProcessDisksResponse, error) {
switch s.service {
case config.OpsManagerService, config.CloudManagerService:
result, _, err := s.client.(*om.Client).HostDisks.List(context.Background(), groupID, hostID, opts)
return result, err
default:
return nil, fmt.Errorf("unsupported service: %s", s.service)
}
}