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

VM Copy support #1210

Merged
merged 14 commits into from
Mar 7, 2024
Merged

VM Copy support #1210

merged 14 commits into from
Mar 7, 2024

Conversation

Didainius
Copy link
Collaborator

@Didainius Didainius commented Feb 13, 2024

This PR adds support for "VM Copy" operation. This allows users to create VMs from from existing VMs. This works by adding copy_from_vm_id in vcd_vapp_vm and vcd_vm resources.

There is one caveat due to a known VCD bug - when creating a Standalone VM copy and source VM is in different VDC, - destination VM must have a sizing_policy_id specified, as otherwise it will return an error (this is also highlighted in docs)

Flow diagram for create functions of vcd_vapp_vm and vcd_vm (updated from PR #901 version to reflect latest changes)

  • Purple shows the main flow of code for Create
  • Green blocks signify API call definition for each of VM types that are being created.
  • Yellow blocks signify where additional code can be hooked up for particular scope
flowchart TD
    S[VM Create]
    S ==> AAAA
    AAAA{Standanlone or vApp VM?}
    AAAA --> |resource vcd_vm| AA{vApp VM or Standalone}
    AAAA --> |resource vcd_vapp_vm| A{vApp VM or Standalone}

    AA[func resourceVcdStandaloneVmCreate] --> B[func genericResourceVmCreate]
    A[func resourceVcdVAppVmCreate] -->|lock parent vApp\n defer unlock| B[func genericResourceVmCreate]

    BB{Is template, empty, or VM Copy}

    B --> BB

    BB -->|"isVmFromTemplate || isVmCopy"| D[func createVmFromImage]
    D --> D3[func lookupSourceImage]
    D3 -->|"isVmFromTemplate"| D4[func lookupSourceCatalogTemplate]
    D3 -->|"isVmCopy"| D5[func lookupSourceVm]

    D4 --> D7[Source Image Identified]
    D5 --> D7

    BB -->|isEmptyVm| E[func createVmEmpty]

    DDD([vApp VM from template])
    DDDD(Standalone VM from template)
    

    EEE(Empty vApp VM)
    EEEE(Empty Standalone VM)

    DD([Optionally perform template VM specific actions])
    EE([Optionally perform empty VM specific actions])


   DDOPTIONAL1([Optionally perform vApp VM template specific actions])
   DDOPTIONAL2([Optionally perform Standalone VM template specific actions])

   EEOPTIONAL1([Optionally perform Empty vApp VM specific actions])
   EEOPTIONAL2([Optionally perform Empty Standalone VM specific actions])


    D7 --> |Is vApp VM| DDD
    D7 --> |Is Standalone VM| DDDD

    E --> |Is vApp VM| EEE
    E --> |Is Standalone VM| EEEE

    DDD --> DDOPTIONAL1
    DDOPTIONAL1 --> DD
    DDDD --> DDOPTIONAL2
    DDOPTIONAL2 --> DD

    EEE --> EEOPTIONAL1
    EEOPTIONAL1 --> EE
    EEEE --> EEOPTIONAL2
    EEOPTIONAL2 --> EE


    F[func genericResourceVmCreate \n'Common API calls for ALL VMs' ]
    DD --> F
    EE --> F


    F ==> G
    G ==> Z
    
    G[func genericResourceVmCreate\nlast step -> power on]

    Z[VM Created]

style DDD fill:#45f248,stroke:#333,stroke-width:4px
style DDDD fill:#45f248,stroke:#333,stroke-width:4px
style EEE fill:#45f248,stroke:#333,stroke-width:4px
style EEEE fill:#45f248,stroke:#333,stroke-width:4px


style F fill:#F1EE8E,stroke:#333,stroke-width:4px
style DD fill:#F1EE8E,stroke:#333,stroke-width:4px
style EE fill:#F1EE8E,stroke:#333,stroke-width:4px
style DDOPTIONAL1 fill:#F1EE8E,stroke:#333,stroke-width:4px
style DDOPTIONAL2 fill:#F1EE8E,stroke:#333,stroke-width:4px

style EEOPTIONAL1 fill:#F1EE8E,stroke:#333,stroke-width:4px
style EEOPTIONAL2 fill:#F1EE8E,stroke:#333,stroke-width:4px

Closes #562

Acceptance tests passed in 10.4.0 and 10.5.1

Signed-off-by: Dainius Serplis <dserplis@vmware.com>
Signed-off-by: Dainius Serplis <dserplis@vmware.com>
Signed-off-by: Dainius Serplis <dserplis@vmware.com>
Signed-off-by: Dainius Serplis <dserplis@vmware.com>
Signed-off-by: Dainius Serplis <dserplis@vmware.com>
Signed-off-by: Dainius Serplis <dserplis@vmware.com>
@Didainius Didainius force-pushed the vm-copy branch 2 times, most recently from a3eb4d7 to bfbf9c3 Compare February 22, 2024 11:32
Signed-off-by: Dainius Serplis <dserplis@vmware.com>
Signed-off-by: Dainius Serplis <dserplis@vmware.com>
Signed-off-by: Dainius Serplis <dserplis@vmware.com>
@Didainius Didainius marked this pull request as ready for review February 26, 2024 05:16
Signed-off-by: Dainius Serplis <dserplis@vmware.com>
Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

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

This is great! Just a few suggestions inline.

vcd/resource_vcd_vapp_vm.go Outdated Show resolved Hide resolved
vcd/resource_vcd_vapp_vm_tools.go Outdated Show resolved Hide resolved
vcd/resource_vcd_vapp_vm.go Outdated Show resolved Hide resolved
Signed-off-by: Dainius Serplis <dserplis@vmware.com>
website/docs/r/vapp_vm.html.markdown Outdated Show resolved Hide resolved
website/docs/r/vapp_vm.html.markdown Outdated Show resolved Hide resolved
website/docs/r/vapp_vm.html.markdown Outdated Show resolved Hide resolved
website/docs/r/vapp_vm.html.markdown Outdated Show resolved Hide resolved
Signed-off-by: Dainius Serplis <dserplis@vmware.com>
Signed-off-by: Dainius Serplis <dserplis@vmware.com>
Copy link
Collaborator

@adambarreiro adambarreiro left a comment

Choose a reason for hiding this comment

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

LGTM!

Signed-off-by: Dainius Serplis <dserplis@vmware.com>
@Didainius Didainius merged commit 708ecba into vmware:main Mar 7, 2024
3 checks passed
@Didainius Didainius deleted the vm-copy branch March 7, 2024 13:57
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.

vcd_vapp_vm - Clone from running VM resource
4 participants