Skip to content

Baremetal: support deploy_steps for the provisioning API#2120

Merged
jtopjian merged 1 commit intogophercloud:masterfrom
dtantsur:deploy-steps
Feb 22, 2021
Merged

Baremetal: support deploy_steps for the provisioning API#2120
jtopjian merged 1 commit intogophercloud:masterfrom
dtantsur:deploy-steps

Conversation

@dtantsur
Copy link
Copy Markdown
Contributor

For: #2119

@coveralls
Copy link
Copy Markdown

coveralls commented Feb 16, 2021

Coverage Status

Coverage remained the same at 79.83% when pulling 04a5ac4 on dtantsur:deploy-steps into fec2b51 on gophercloud:master.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Feb 16, 2021

Build succeeded.

@dtantsur
Copy link
Copy Markdown
Contributor Author

HI @jtopjian! Yeah, you're on the right track. This feature was added in https://opendev.org/openstack/ironic/commit/3138acc836c933aa179b9a92c14a226a8b903fe5, its API part starts in https://opendev.org/openstack/ironic/src/commit/6ae5bc4642c4619946a48512501b4ae37246f7ff/ironic/api/controllers/v1/node.py#L850 and progresses further ending up in the code you've found. Note that there is a related concept of deploy templates which makes code hunting somewhere more complicated. This change does not implement deploy templates, only the smaller API addition from the above mentioned commit.

@dtantsur
Copy link
Copy Markdown
Contributor Author

Tested with the following code:

    client.Microversion = "1.69"

    updates := nodes.UpdateOpts {
        nodes.UpdateOperation {
            Op: nodes.AddOp,
            Path: "/instance_info/image_source",
            Value: "file:///httpboot/centos8.qcow2",
        },
    }

    _, err = nodes.Update(client, "testvm1", updates).Extract()
    if err != nil {
        panic(fmt.Sprintf("Cannot update: %s", err))
    }

    files := []struct {
        Path string `json:"path"`
        Content string `json:"content"`
    } {
        {
            Path: "/etc/motd",
            Content: "SGVsbG8gSXJvbmljIFdvcmxkIQo=",
        },
    }

    opts := nodes.ProvisionStateOpts {
        Target: nodes.TargetActive,
        DeploySteps: []nodes.DeployStep {
            nodes.DeployStep {
                Step: "inject_files",
                Interface: "deploy",
                Priority: 50,
                Args: map[string]interface{}{
                    "files": files,
                },
            },
        },
    }

    err = nodes.ChangeProvisionState(client, "testvm1", opts).ExtractErr()
    if err != nil {
        panic(fmt.Sprintf("Cannot provision: %s", err))
    }

(Note that I'm using a deploy step that has not merged yet)

@jtopjian
Copy link
Copy Markdown
Contributor

jtopjian commented Feb 22, 2021

@dtantsur Thanks! Those links helped. Notably:

https://opendev.org/openstack/ironic/src/commit/3138acc836c933aa179b9a92c14a226a8b903fe5/ironic/api/controllers/v1/utils.py#L125-L141

which defines the data model being added in this PR. I just needed to see something that showed the fields of the DeployStep struct are defined somewhere and DeployStep shouldn't be a generic map[string]interface.

It looks like the Interface field is an enum, with values defined here (sorry for linking to GitHub, I wasn't getting any results when using the "search" function in opendev).

If you wanted, you could create a custom string type called DeployStepInterface (or something similar). It would then look like:

type DeployStepInterface string

const (
  InterfaceDeploy DeployStepInterface = "deploy"
  ...
)

type DeployStep struct {
  Interface DeployStepInterface `json:"interface" required:"true"`
  ... 
}

    ....

    opts := nodes.ProvisionStateOpts {
        Target: nodes.TargetActive,
        DeploySteps: []nodes.DeployStep {
            nodes.DeployStep {
                Step: "inject_files",
                Interface: nodes.InterfaceDeploy,
                Priority: 50,
                Args: map[string]interface{}{
                    "files": files,
                },
            },
        },
    }

This is up to you, though. There are areas in Gophercloud that implement this and other areas that use a generic "string". If you prefer to use a string, let me know and I'll go ahead and merge this PR as-is.

@dtantsur
Copy link
Copy Markdown
Contributor Author

It looks like the Interface field is an enum, with values defined here

Good call, I completely forgot that we limit the interfaces supported for deploy steps (I also forgot why we do that, but that's a different conversation). Will change.

Deploy steps work similarly to clean steps but during deployment.

For: gophercloud#2119
@dtantsur
Copy link
Copy Markdown
Contributor Author

@jtopjian updated and applied the same change to clean steps.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Feb 22, 2021

Build succeeded.

Copy link
Copy Markdown
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

Copy link
Copy Markdown
Contributor

@jtopjian jtopjian left a comment

Choose a reason for hiding this comment

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

LGTM - thank you!

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

Successfully merging this pull request may close these issues.

5 participants