Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

blockstorage: add manage-existing and unmanage api call #3332

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
Loading
from

Conversation

TOMOFUMI-KONDO
Copy link

@TOMOFUMI-KONDO TOMOFUMI-KONDO commented Mar 20, 2025

Nice to meet you. I always appreciate your developments.
I have this pull request ready to do, so could you please review it?

I implemented a missing blockstorage API call to manage an existing volume and unmanage a volume.
API document for the endpoints are these:

I wrote the unit and acceptance tests and checked that they worked.

Therefore, I tested the new code with the environment and the script below.

  • cinder-api/noble-updates,now 2:25.0.0-0ubuntu1~cloud0 all [installed]
  • cinder-volume/noble-updates,now 2:25.0.0-0ubuntu1~cloud0 all [installed]
  • using cinder lvm driver
package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"time"

	"github.com/gophercloud/gophercloud/v2"
	"github.com/gophercloud/gophercloud/v2/openstack"
	"github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/manageablevolumes"
	"github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/volumes"
	"github.com/gophercloud/gophercloud/v2/openstack/config"
)

func main() {
	ctx := context.Background()

	authOpts := gophercloud.AuthOptions{
		IdentityEndpoint: os.Getenv("OS_AUTH_URL"),
		Username:         os.Getenv("OS_USERNAME"),
		Password:         os.Getenv("OS_PASSWORD"),
		DomainName:       os.Getenv("OS_USER_DOMAIN_NAME"),
		Scope: &gophercloud.AuthScope{
			ProjectID: os.Getenv("OS_PROJECT_ID"),
		},
	}
	endpointOpts := gophercloud.EndpointOpts{
		Region: os.Getenv("OS_REGION_NAME"),
	}
	providerClient, err := config.NewProviderClient(ctx, authOpts)
	if err != nil {
		log.Fatal(err)
	}
	client, err := openstack.NewBlockStorageV3(providerClient, endpointOpts)
	if err != nil {
		log.Fatal(err)
	}
	// Manage existing volume requires microversion at least 3.8
	client.Microversion = "3.8"

	createOpts := volumes.CreateOpts{
		Name:             "New Volume",
		Size:             8,
		AvailabilityZone: "nova",
		Description:      "Volume newly created",
		VolumeType:       "lvm",
		Metadata:         map[string]string{"key1": "value1"},
	}
	created, err := volumes.Create(ctx, client, createOpts, nil).Extract()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Created volume: %+v\n", created)

	time.Sleep(3 * time.Second)

	if err := volumes.Unmanage(ctx, client, created.ID).ExtractErr(); err != nil {
		log.Fatal(err)
	}
	fmt.Println("Unmanaged volume")

	time.Sleep(3 * time.Second)

	manageOpts := manageablevolumes.ManageExistingOpts{
		Host:             "storage01@lvm#LVM",
		Ref:              map[string]string{"source-name": fmt.Sprintf("volume-%s", created.ID)},
		Name:             "Managed Volume",
		AvailabilityZone: "nova",
		Description:      "Volume imported from existingLV",
		VolumeType:       "lvm",
		Bootable:         false,
		Metadata:         map[string]string{"key1": "value1"},
	}
	managed, err := manageablevolumes.ManageExisting(ctx, client, manageOpts).Extract()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Managed volume: %+v\n", managed)
}

And it worked.

$ cinder get-pools
+----------+-------------------+
| Property | Value             |
+----------+-------------------+
| name     | storage01@lvm#LVM |
+----------+-------------------+

$ go run .
Created volume: &{ID:b62ccb65-0261-473d-924e-c40717fd8b5a Status:creating Size:8 AvailabilityZone:nova CreatedAt:2025-03-23 15:17:34.787783 +0000 UTC UpdatedAt:0001-01-01 00:00:00 +0000 UTC Attachments:[] Name:New Volume Description:Volume newly created VolumeType:lvm SnapshotID: SourceVolID: BackupID:<nil> Metadata:map[key1:value1] UserID:149dd9648b9647c8b4e6cbf509f2078f Bootable:false Encrypted:false ReplicationStatus: ConsistencyGroupID: Multiattach:false VolumeImageMetadata:map[] Host: TenantID:}
Unmanaged volume
Managed volume: &{ID:b9ecbba7-fce5-4198-ae67-1b1b7163b761 Status:creating Size:0 AvailabilityZone:nova CreatedAt:2025-03-23 15:17:40.952282 +0000 UTC UpdatedAt:0001-01-01 00:00:00 +0000 UTC Attachments:[] Name:Managed Volume Description:Volume imported from existingLV VolumeType:lvm SnapshotID: SourceVolID: BackupID:<nil> Metadata:map[key1:value1] UserID:149dd9648b9647c8b4e6cbf509f2078f Bootable:false Encrypted:false ReplicationStatus: ConsistencyGroupID: Multiattach:false VolumeImageMetadata:map[] Host: TenantID:}

$ openstack volume list
+--------------------------------------+-------------+-----------+------+--------------------------------------+
| ID                                   | Name        | Status    | Size | Attached to                          |
+--------------------------------------+-------------+-----------+------+--------------------------------------+
| b9ecbba7-fce5-4198-ae67-1b1b7163b761 | Managed Volume | available |    8 |                                      |
+--------------------------------------+-------------+-----------+------+--------------------------------------+

Fixes #3324

Links to the line numbers/files in the OpenStack source code that support the
code in this PR:

API doc

source code

@github-actions github-actions bot added edit:blockstorage This PR updates blockstorage code semver:minor Backwards-compatible change labels Mar 20, 2025
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for submitting your first PR! Be sure that we will be looking at it but keep in mind
this sometimes takes a while.
Please let the maintainers know if your PR has not got enough attention after a few days.
If any doubt, please consult our PR tutorial.

@TOMOFUMI-KONDO TOMOFUMI-KONDO changed the title blockstorage: add manage-existing api call blockstorage: add manage-existing and unmanage api call Mar 23, 2025
@TOMOFUMI-KONDO TOMOFUMI-KONDO marked this pull request as draft March 23, 2025 13:17
@TOMOFUMI-KONDO TOMOFUMI-KONDO changed the title blockstorage: add manage-existing and unmanage api call (WIP) blockstorage: add manage-existing and unmanage api call Mar 23, 2025
@TOMOFUMI-KONDO TOMOFUMI-KONDO force-pushed the blockstorage-manage-exsiting branch 2 times, most recently from cd71982 to 8477643 Compare March 24, 2025 14:49
Added acceptance test for managing a existing volume and unmanaging a
volume api calls.
@TOMOFUMI-KONDO TOMOFUMI-KONDO force-pushed the blockstorage-manage-exsiting branch from 8477643 to 6fb7d11 Compare March 24, 2025 15:02
@TOMOFUMI-KONDO TOMOFUMI-KONDO marked this pull request as ready for review March 24, 2025 15:11
@TOMOFUMI-KONDO TOMOFUMI-KONDO changed the title (WIP) blockstorage: add manage-existing and unmanage api call blockstorage: add manage-existing and unmanage api call Mar 24, 2025
@TOMOFUMI-KONDO
Copy link
Author

Any problems? If there are things to be fixed, I'd like to know.

@EmilienM
Copy link
Contributor

There is no problem at all, sorry for the time it takes. The team has been very busy lately. We'll wait to see how CI works here and we'll make a review in a timely manner.

@coveralls
Copy link

Coverage Status

coverage: 78.704% (+0.01%) from 78.69%
when pulling 6fb7d11 on TOMOFUMI-KONDO:blockstorage-manage-exsiting
into 9e4535f on gophercloud:main.

@TOMOFUMI-KONDO
Copy link
Author

Thank you for responding! I'm very appreciative for your team's development despite busy schedule.

Copy link
Contributor

@EmilienM EmilienM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

thanks

@bhavin192
Copy link

Hey @EmilienM would be great if this gets merged, I'm working on something which relies on Cinder Manage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
edit:blockstorage This PR updates blockstorage code semver:minor Backwards-compatible change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cinder "manage existing volume" feature
4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.