Skip to content
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

How to get all pyhical disks, and create virtual disks? #164

Open
wahello opened this issue Jan 26, 2022 · 4 comments
Open

How to get all pyhical disks, and create virtual disks? #164

wahello opened this issue Jan 26, 2022 · 4 comments

Comments

@wahello
Copy link

wahello commented Jan 26, 2022

How to get all pyhical disks, and create virtual disks?

Is there any examples?

@stmcginnis
Copy link
Owner

Hey @wahello - there are actually a few different paths to get to the physical drives, depending on what association you are trying to use. The most common I think would be through either the Chassis or System objects. Here's an example of getting all drives in a Chassis:

//
// SPDX-License-Identifier: BSD-3-Clause
//
package main

import (
	"fmt"

	"github.com/stmcginnis/gofish"
)

func main() {
	// Create a new instance of gofish client, ignoring self-signed certs
	config := gofish.ClientConfig{
		Endpoint: "https://bmc-ip",
		Username: "my-username",
		Password: "my-password",
		Insecure: true,
	}
	c, err := gofish.Connect(config)
	if err != nil {
		panic(err)
	}
	defer c.Logout()

	// Retrieve the service root
	service := c.Service

	// Query the chassis data using the session token
	chassis, err := service.Chassis()
	if err != nil {
		panic(err)
	}

	for _, chass := range chassis {
		fmt.Printf("Chassis: %#v\n\n", chass)
		drives, err := chass.Drives()
		if err == nil {
			for i, drive := range drives {
				fmt.Printf("    Drive %d: %#v\n", i, drive)
			}
		}
	}
}

@stmcginnis
Copy link
Owner

As far as creating a virtual disk, I have not done that myself, so I'm not sure. Looks like it may be an operation on the System's StorageController, but I don't have a good example handy. It may be that we should get a new call added to the gofish library to handle this.

@wahello
Copy link
Author

wahello commented Jan 27, 2022

Thanks.

@rohitmahadevan
Copy link

rohitmahadevan commented Apr 19, 2023

Hi, I don't know if this helps here's what I did to get the same.

    Config := gofish.ClientConfig{
        Endpoint: "https://" + values.IP,
        Username: values.Username,
        Password: values.Password,
        Insecure: true,
    }
    // Create client connection
    connect, err := gofish.Connect(Config)

    // Create service Root
    service := connect.Service

    // Get system instances
    system, err := service.Systems()
    if err != nil {
        fmt.Println(err)
        continue
    }
    for _, value := range system {
        var physicaldisk []string
        var virtualdisk []string
        storage, err := value.Storage()
        for _, vs := range storage {
            vols, _ := vs.Volumes()
            for _, vols := range vols {
                if strings.Contains(vols.ODataID, ".Virtual.0") {
                    virtualdisk = append(virtualdisk, vols.ODataID)
                }
            }
            drives, _ := vs.Drives()
            for _, vd := range drives {
                physicaldisk = append(physicaldisk, vd.Name)    
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants