Skip to content
Draft
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 cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (c Cmd) Execute() (cmdErr error) {
return NewVMsCmd(deps.UI, c.director(), c.BoshOpts.Parallel).Run(*opts)

case *OrphanedVMsOpts:
return NewOrphanedVMsCmd(deps.UI, c.director()).Run()
return NewOrphanedVMsCmd(deps.UI, c.director()).Run(*opts)

case *InstancesOpts:
return NewInstancesCmd(deps.UI, c.director(), c.BoshOpts.Parallel).Run(*opts)
Expand Down
12 changes: 9 additions & 3 deletions cmd/instance_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type InstanceTableValues struct {
VMType boshtbl.Value
Active boshtbl.Value
IPs boshtbl.Value
IPs_cidr boshtbl.Value
Deployment boshtbl.Value

// Details
Expand Down Expand Up @@ -58,6 +59,7 @@ var InstanceTableHeader = InstanceTableValues{
VMType: boshtbl.NewValueString("VM Type"),
Active: boshtbl.NewValueString("Active"),
IPs: boshtbl.NewValueString("IPs"),
IPs_cidr: boshtbl.NewValueString("IPs"),
Deployment: boshtbl.NewValueString("Deployment"),

// Details
Expand Down Expand Up @@ -91,7 +93,7 @@ var InstanceTableHeader = InstanceTableValues{
}

type InstanceTable struct {
Processes, VMDetails, DeploymentDetails, Details, Stemcell, Vitals, CloudProperties bool
Processes, VMDetails, DeploymentDetails, Details, Stemcell, Vitals, CloudProperties, Cidr bool
}

func (t InstanceTable) Headers() []boshtbl.Header {
Expand Down Expand Up @@ -134,6 +136,7 @@ func (t InstanceTable) ForVMInfo(i boshdir.VMInfo) InstanceTableValues {
VMType: boshtbl.NewValueString(i.VMType),
Active: boshtbl.NewValueString(activeStatus),
IPs: boshtbl.NewValueStrings(i.IPs),
IPs_cidr: boshtbl.NewValueStrings(i.IPs_cidr),
Deployment: boshtbl.NewValueString(i.Deployment),

// Details
Expand Down Expand Up @@ -211,8 +214,11 @@ func (t InstanceTable) AsValues(v InstanceTableValues) []boshtbl.Value {
if t.Processes {
result = append(result, v.Process)
}

result = append(result, []boshtbl.Value{v.ProcessState, v.AZ, v.IPs}...)
if t.Cidr {
result = append(result, []boshtbl.Value{v.ProcessState, v.AZ, v.IPs_cidr}...)
} else {
result = append(result, []boshtbl.Value{v.ProcessState, v.AZ, v.IPs}...)
}

if t.DeploymentDetails {
result = append(result, v.Deployment)
Expand Down
1 change: 1 addition & 0 deletions cmd/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (c InstancesCmd) Run(opts InstancesOpts) error {
Processes: opts.Processes,
Details: opts.Details,
Vitals: opts.Vitals,
Cidr: opts.Cidr,
}

if len(opts.Deployment) > 0 {
Expand Down
3 changes: 3 additions & 0 deletions cmd/opts/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ type InstancesOpts struct {
Vitals bool `long:"vitals" description:"Show vitals"`
Processes bool `long:"ps" short:"p" description:"Show processes"`
Failing bool `long:"failing" short:"f" description:"Only show failing instances"`
Cidr bool `long:"cidr" description:"show the CIDR notation of the network IP Addresses"`
Deployment string
cmd
}
Expand All @@ -815,6 +816,7 @@ type VMsOpts struct {
Vitals bool `long:"vitals" description:"Show vitals"`
CloudProperties bool `long:"cloud-properties" description:"Show cloud properties"`
Deployment string
Cidr bool `long:"cidr" description:"show the CIDR notation of the network IP Addresses"`
cmd
}

Expand Down Expand Up @@ -844,6 +846,7 @@ type RecoverArgs struct {
}

type OrphanedVMsOpts struct {
Cidr bool `long:"cidr" description:"show the CIDR notation of the network IP Addresses"`
cmd
}

Expand Down
16 changes: 12 additions & 4 deletions cmd/orphaned_vms.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
. "github.com/cloudfoundry/bosh-cli/v7/cmd/opts" //nolint:staticcheck
"github.com/cloudfoundry/bosh-cli/v7/director"
"github.com/cloudfoundry/bosh-cli/v7/ui"
"github.com/cloudfoundry/bosh-cli/v7/ui/table"
Expand All @@ -15,18 +16,25 @@ func NewOrphanedVMsCmd(ui ui.UI, director director.Director) OrphanedVMsCmd {
return OrphanedVMsCmd{ui: ui, director: director}
}

func (c OrphanedVMsCmd) Run() error {
func (c OrphanedVMsCmd) Run(opts OrphanedVMsOpts) error {
orphanedVMs, err := c.director.OrphanedVMs()
if err != nil {
return err
}

printOrphanedVmTable(c.ui, orphanedVMs)
printOrphanedVmTable(c.ui, orphanedVMs, opts)

return nil
}

func printOrphanedVmTable(ui ui.UI, orphanedVMs []director.OrphanedVM) {
func formatIPAddress(orphanedVM director.OrphanedVM, opts OrphanedVMsOpts) []string {
if opts.Cidr {
return orphanedVM.IPAddressesCidr
}
return orphanedVM.IPAddresses
}

func printOrphanedVmTable(ui ui.UI, orphanedVMs []director.OrphanedVM, opts OrphanedVMsOpts) {
tbl := table.Table{
Content: "orphaned_vms",
Header: []table.Header{
Expand All @@ -46,7 +54,7 @@ func printOrphanedVmTable(ui ui.UI, orphanedVMs []director.OrphanedVM) {
table.NewValueString(vm.DeploymentName),
table.NewValueString(vm.InstanceName),
table.NewValueString(vm.AZName),
table.NewValueStrings(vm.IPAddresses),
table.NewValueStrings(formatIPAddress(vm, opts)),
table.NewValueTime(vm.OrphanedAt),
})
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/orphaned_vms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
. "github.com/onsi/gomega"

"github.com/cloudfoundry/bosh-cli/v7/cmd"
"github.com/cloudfoundry/bosh-cli/v7/cmd/opts"
boshdir "github.com/cloudfoundry/bosh-cli/v7/director"
fakedir "github.com/cloudfoundry/bosh-cli/v7/director/directorfakes"
fakeui "github.com/cloudfoundry/bosh-cli/v7/ui/fakes"
Expand Down Expand Up @@ -57,7 +58,7 @@ var _ = Describe("OrphanedVMsCmd", func() {
})

It("lists VMs for the deployment", func() {
Expect(command.Run()).ToNot(HaveOccurred())
Expect(command.Run(opts.OrphanedVMsOpts{})).ToNot(HaveOccurred())

Expect(ui.Table).To(Equal(boshtbl.Table{
Content: "orphaned_vms",
Expand Down Expand Up @@ -101,7 +102,7 @@ var _ = Describe("OrphanedVMsCmd", func() {
})

It("returns an error", func() {
err := command.Run()
err := command.Run(opts.OrphanedVMsOpts{})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("potato"))
})
Expand Down
1 change: 1 addition & 0 deletions cmd/vms.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (c VMsCmd) Run(opts VMsOpts) error {
DeploymentDetails: false,
Details: false,
Stemcell: true,
Cidr: opts.Cidr,
Vitals: opts.Vitals,
CloudProperties: opts.CloudProperties,
}
Expand Down
26 changes: 14 additions & 12 deletions director/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ type DirectorImpl struct {
}

type OrphanedVMResponse struct {
AZName string `json:"az"`
CID string `json:"cid"`
DeploymentName string `json:"deployment_name"`
IPAddresses []string `json:"ip_addresses"`
InstanceName string `json:"instance_name"`
OrphanedAt string `json:"orphaned_at"`
AZName string `json:"az"`
CID string `json:"cid"`
DeploymentName string `json:"deployment_name"`
IPAddresses []string `json:"ip_addresses"`
IPAddressesCidr []string `json:"ip_addresses_cidr"`
InstanceName string `json:"instance_name"`
OrphanedAt string `json:"orphaned_at"`
}

func (d DirectorImpl) WithContext(id string) Director {
Expand Down Expand Up @@ -47,12 +48,13 @@ func transformOrphanedVMs(resps []OrphanedVMResponse) ([]OrphanedVM, error) {
}

orphanedVMs = append(orphanedVMs, OrphanedVM{
CID: r.CID,
DeploymentName: r.DeploymentName,
InstanceName: r.InstanceName,
AZName: r.AZName,
IPAddresses: r.IPAddresses,
OrphanedAt: orphanedAt,
CID: r.CID,
DeploymentName: r.DeploymentName,
InstanceName: r.InstanceName,
AZName: r.AZName,
IPAddresses: r.IPAddresses,
IPAddressesCidr: r.IPAddressesCidr,
OrphanedAt: orphanedAt,
})
}
return orphanedVMs, nil
Expand Down
13 changes: 7 additions & 6 deletions director/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,13 @@ type OrphanNetwork interface {
}

type OrphanedVM struct {
CID string
DeploymentName string
InstanceName string
AZName string
IPAddresses []string
OrphanedAt time.Time
CID string
DeploymentName string
InstanceName string
AZName string
IPAddresses []string
IPAddressesCidr []string
OrphanedAt time.Time
}

type EventsFilter struct {
Expand Down
1 change: 1 addition & 0 deletions director/vms.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type VMInfo struct {
Bootstrap bool

IPs []string `json:"ips"`
IPs_cidr []string `json:"ips_cidr"`
Deployment string `json:"deployment_name"`

AZ string `json:"az"`
Expand Down