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

Initial support for a Cloudstack builder #922

Conversation

mindjiver
Copy link

Add support for Apache Cloudstack (https://cloudstack.apache.org) as a
builder. Supports creating new templates of existing templates as well
as booting from ISO to PXE boot a full installation to an empty block
device.

To be able to bootstrap a template from an empty block device we need
to be able to netboot and kickstart a OS installation. To do this we
spin up a HTTP web server to send files to the virtual machine. We
assume the virtual machine will be booting from a iPXE ISO which will
chain boot off the userdata we provide when deploying the virtual
machine.

This also supports passing in templated userdata to be downloaded from
the booted virtual machine.

@mindjiver
Copy link
Author

Comments are highly appreciated.

}
}

func ipAddressToListenOn() *net.IPNet {
Copy link
Author

Choose a reason for hiding this comment

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

Not 100% pleased with this part, will always return the last unicast IP. Needed to template out the userdata which will contain the URL to a kickstart file hosted by this web server.

@mindjiver mindjiver mentioned this pull request Apr 7, 2014
Peter Jönsson and others added 10 commits April 7, 2014 22:57
Add support for Apache Cloudstack (https://cloudstack.apache.org) as a
builder. Supports creating new templates of existing templates as well
as booting from ISO to PXE boot a full installation to an empty block
device.

To be able to bootstrap a template from an empty block device we need
to be able to netboot and kickstart a OS installation. To do this we
spin up a HTTP web server to send files to the virtual machine. We
assume the virtual machine will be booting from a iPXE ISO which will
chain boot off the userdata we provide when deploying the virtual
machine.

This also supports passing in templated userdata to be downloaded from
the booted virtual machine.
CloudStack should be Cloudstack, also correct some minor spelling
nits.
Newest version of gopherstack adds option to skip certificate
validation. Should only be used for testing.
Correct bug when trying to template out userdata variables which had
not been set. We solve this by setting userdata to an empty
string. Also save dummy values for both HTTP IP and port.

Also align printout of 'SSH'.
Ensure we have the neccessary values to perform a proper
deployVirtualMachine API call.
If a cloudstack build is cancelled/halted we display a message back to
the user.
Corrected naming of Cloudstack in underlaying library. Updating usage
accordingly.
* Only detach ISOs from virtual machine if it's actually attached
* Add configuration option to specify time to wait until we detach ISO
To make debugging of HTTP server problems easier we print both the IP
adress and the port where the HTTP server has been exposed.
@mitchellh
Copy link
Contributor

This looks decent. Unfortunately, I don't want to merge this without having access to a CloudStack installation that I can use for testing. Do you know any vendors that would be willing to provide a free account for basic testing of this builder?

Until then, please make this a plugin, it would work great!

I'll work on vendors as well. Let me know if you can get me access. I'm going to close for now, but will reopen when/if I can get access. Waah!

@mitchellh mitchellh closed this Apr 22, 2014
@vogxn
Copy link
Contributor

vogxn commented Apr 22, 2014

Exoscale (exoscale.ch) has trial accounts with a free tier. Also the Apache CloudStack project might have installation endpoints with latest master / development snapshots located widely. I've reached out to the project to help with this. Hopefully, someone will come back here with the needed info.

@mindjiver
Copy link
Author

@mitchellh Thanks for the feedback. I have some contact with Exoscale and I'll try reaching out to them.

@fifthecho
Copy link

@mindjiver If you have any issues with Exoscale, we at Datapipe might be able to provide access to a CloudStack cloud.

@mitchellh
Copy link
Contributor

Exoscale sounds good. Please let me know if anything comes through. The Packer project only needs basic access (spin up and down a few machines very rarely) to test this sort of thing. Thanks!

@retrack
Copy link

retrack commented Apr 22, 2014

Hello all, this sounds great. Always happy to help. @mitchellh you can register on https://portal.exoscale.ch/register with the code PACKERROCKS

We will meet at DotScale next month. Happy testing.

@ddoc
Copy link

ddoc commented Apr 24, 2014

I can also provide access to a cloudstack instance for you.

@jwthomp
Copy link

jwthomp commented May 5, 2014

Checking to see if this is going to open back up due to offers of cloudstack access?

@mindjiver
Copy link
Author

@retrack @mitchellh Did you guys manage to meet up and get the ball rolling?

@lndbrg
Copy link

lndbrg commented May 22, 2014

How is this going? I'm interested in cloudstack support for packer as well?

@C-Duv
Copy link

C-Duv commented Jun 22, 2014

Couldn't we use apache-libcloud to make Packer support multiple cloud providers instead of having multiple PR to add single provider support?

@rickard-von-essen
Copy link
Collaborator

Using apache-libcloud would add a dependency on python and libcloud. Currently packer ships as a self contained binary in a zip file. Starting to depend on something on as complicated as python would require "real" packages, this would add lots of reoccurring work for the maintainers.

@mindjiver
Copy link
Author

What @rickard-von-essen said. However a switch to gocs as the underlaying cloudstack API library would be something to look at. But after this has been merged, if it ever gets merged 😄

@C-Duv
Copy link

C-Duv commented Jun 23, 2014

@rickard-von-essen: right, forgot this convenient binary-shipping thing :(

One could do a plugin that depends on this library (or CLI tools that uses this library)?

@mindjiver
Copy link
Author

@C-Duv to extract this builder into a stand-alone plugin for packer you mean? Sure, that would be possible if this won't be merged. To use the underlaying Golang-library in another project, that would also be possible but gopherstack was pretty tailormade for the things needed in packer.

@C-Duv
Copy link

C-Duv commented Jun 23, 2014

@mindjiver yes, but even if this PR gets merged. An apache-libcloud dependent Packer builder plugin (say "LibCloudBuilder") may provide building feature for all the LibCloud-compatible cloud providers.
This dependency could even be that the plugin internally calls a 1:1 lib-CLI tool.

But I'm realizing this PR is not the place for that.

@abayer
Copy link
Contributor

abayer commented Jul 18, 2014

Any update on this?

@mindjiver
Copy link
Author

@abayer Nope.. I have merged some PRs on my fork which now has been some more action on more Cloudstack installations, versions and hypervisors. But I still think the main issue is to get @mitchellh a good reliable account at a provider which uses Cloudstack so he can test towards it.

@dduportal
Copy link

@mindjiver I (and my company) are also interested with this cloudstack support. I'm trying to learn and build packer from your repo but do you have precompiled binaries for Windows/Unix ?

@dduportal
Copy link

ping @mindjiver @retrack Any news ?

@mindjiver
Copy link
Author

@dduportal nope, no news. I might work on making a separate builder which I will build and package for all the necessary platforms. Internally at Klarna we have been using this for over 9 months now.

@abayer
Copy link
Contributor

abayer commented Sep 24, 2014

@mindjiver Do you have docs for the CloudStack builder by any chance?

@chobbs-
Copy link

chobbs- commented Sep 25, 2014

@mindjiver I'm looking for a bit of help here as well. I was able to get packer compiled with your pull request using instructions from a mail archive but I'm wondering if you have any guidance for spinning up from ISO and PXE?

For others looking, here's what I had to do to get Packer compiled with this pull request:

Prereqs: golang, git, hg and bzr installed (hg is part of mercurial)

go get github.com/mitchellh/gox

export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$PATH
mkdir -p $GOPATH
go get github.com/mitchellh/packer # build download, build and install the
master version of packer into $GOPATH/bin
cd $GOPATH/src/github.com/mitchellh/packer/
git fetch origin refs/pull/922/head && git checkout FETCH_HEAD # will download
the HEAD of the latest version of pull request and check it out
make # will compile packer with cloudstack support and install into $GOPATH/bin

After running make for the first time, it will fail. There are two errors that need to be fixed:

Fix first error:

 1. https://code.google.com/p/google-api-go-client/source/browse/compute/v1beta16?r=2f3a11c875227040c6420113d8d1a634a489031e#v1beta16%253Fstate%253Dclosed
2. Download zip
3. unzip
4. cd go/src/code.google.com/p/google-api-go-client/compute
5. rsync -r ~/Downloads/google-api-go-client-2f3a11c87522/compute/v1beta16 ./

Fix ssh issue:

  1. cd src/code.google.com/p
  2. hg clone https://code.google.com/p/gosshold/
  3. Get patch file here: https://gist.github.com/rickard-von-essen/10444950
  4. cd $GOPATH/src/github.com/mithcellh/packer
  5. git apply < gosshold_packer.patch
  6. Manually fix builder/cloudstack/ssh.go:
    1. line 4: change ‘go.crypto’ to ‘gosshold’

Now run make again in $GOPATH/src/github.com/mitchellh/packer/ and it should successfully build and place packer under $GOPATH/bin/

Here's an example template.json:

{
"builders": [
{
"type": "cloudstack",

  "api_url": "https://server/client/api";,
  "api_key": "***", 
  "secret": "***",

  "ssh_timeout": "60s",
  "state_timeout": "100s",

  "ssh_username": "root",
  "ssh_port": 22,
  "ssh_key_path": "id_rsa",
  "http_directory": "http",

  "service_offering_id": "46446411-f9ab-4856-a046-087dc115ee30",
  "template_id": "83ca136a-f8c8-4063-812b-378b6ac9246d",
  "zone_id": "912e5efc-cc9a-4386-9b55-d438274b9b30",
  "network_ids": [ "2c5b96ce-2666-467c-88c4-d0a0575d20ca" ],
  "disk_offering_id": "eca03965-d10e-4b36-b6c4-e697ede7d136",
  "user_data": "testingsadfasd",

  "template_name": "test",
  "template_display_text": "test",
  "template_os_id": 1
}

]
}

Add "insecure_skip_verify": "true", if you don't have a valid cert on your CloudStack instance.

Hope this helps.

@mindjiver
Copy link
Author

Hi @chobbs- @abayer : I'm planning on working on releasing this a separate builder with some further instructions on how to build templates for Cloudstack using Packer. Including on how to go from an empty block device via iPXE to a auto-installed operating system. I just need some time to setup the proper infrastructure at work to get this going :)

@dduportal
Copy link

Thanks for the instructions !

I could not build packer from my compatny, because we got a corporate HTTP / HTTPS-only proxy, and the go get seems to be stuck (while git, docker, curl, wget are working perfectly. What the What ?) :

bash-4.1# make
\033[32;01m==> Installing dependencies\033[0m
code.google.com/p/go.crypto (download)
github.com/mitchellh/go-fs (download)
github.com/mitchellh/goamz (download)
github.com/vaughan0/go-ini (download)
github.com/mitchellh/multistep (download)
github.com/mindjiver/gopherstack (download)
github.com/ActiveState/tail (download)
github.com/howeyc/fsnotify (download)
Fetching https://gopkg.in/tomb.v1?go-get=1
Parsing meta tags from https://gopkg.in/tomb.v1?go-get=1 (status code 200)
get "gopkg.in/tomb.v1": found meta tag main.metaImport{Prefix:"gopkg.in/tomb.v1", VCS:"git", RepoRoot:"https://gopkg.in/tomb.v1"} at https://gopkg.in/tomb.v1?go-get=1
gopkg.in/tomb.v1 (download)
^Cmake: *** [deps] Error 2

But guess what, i'm going to publish a container on the Dockerhub like boot2docker iso, which will embed a pre-compiled version, and you will use it to rebuild if wanted :)

Wait & see some days, i'll publish the link here.

@dduportal
Copy link

OK guys, First build try (Linux 64 only at this time, i need to cross compile for Mac OS / Windows) :
https://registry.hub.docker.com/u/dduportal/packerbuild/dockerfile/

So you just have to :

docker run --rm dduportal/packerbuild:cloudstack-latest > packer
chmod a+x
./packer --help

Native build on Windows confirmed work (except the post-build script, which role is to rename packer_packer to packer).

Base testing are running

@benjimcc
Copy link

benjimcc commented Oct 9, 2014

@mindjiver Hello great work on the Cloudstack builder, just wondering if you have any existing template examples which take a Centos base iso all the way through Packer to Cloudstack using your PR.

@mindjiver
Copy link
Author

@benjimcc See the following diagram

Cloudstack automation

The special chain boot iPXE ISO was built from latest HEAD of master for iPXE with the following embedded script, see http://ipxe.org/embed for more details on how to built the ISO:

#!pxe
dhcp
chain http://${dhcp-server}/latest/userdata

The JSON payload for packer-cloudstack looks like this example:

{
  "provisioners": [
    {
      "type": "shell",
      "scripts": [
        "scripts/base.sh",
        "scripts/motd.sh",
        "scripts/version.sh",
        "scripts/chef-client11.sh",
        "scripts/setupvm.sh",
        "scripts/tuned.sh",
        "scripts/tuneio.sh",
        "scripts/xs-tools.sh",
        "scripts/vmtweaks.sh",
        "scripts/cleanup.sh",
        "scripts/zerodisk.sh"
      ]
    }
  ],
  "builders": [
    {
      "type": "cloudstack",
      "hypervisor": "xenserver",
      "service_offering_id" : "4ccec2a3-0b53-4db0-aebc-6735019581b2",
      "template_id" : "b34f2d7b-2bec-497e-a18e-06d0de94526e",
      "zone_id" : "489e5147-85ba-4f28-a78d-226bf03db47c",
      "disk_offering_id" :"ef781d7f-f8e8-4f73-985c-e0b0a8ef8d48",
      "network_ids" : ["9ab9719e-1f03-40d1-bfbe-b5dbf598e27f"],
      "ssh_username": "root",
      "ssh_key_path": "data/vagrant_insecure_private_key",
      "ssh_timeout": "15m",
      "state_timeout": "30m",
      "template_name": "centos-6.5-20gb-chef11",
      "template_display_text": "CentOS 6.5 20GB chef11",
      "template_os_id": "144",
      "http_directory": "web",
      "user_data": "#!ipxe\nkernel http://{{.HTTPIP}}:{{.HTTPPort}}/vmlinuz ks=http://{{.HTTPIP}}:{{.HTTPPort}}/ks.cfg\ninitrd http://{{.HTTPIP}}:{{.HTTPPort}}/initrd.img\nboot"
    }
  ]
}

I'm serving the vmlinuz, initrd and kickstart files form the webserver packer spins up on the local workstation that is also performing the API calls to Cloudstack.

@mindjiver
Copy link
Author

@vogxn @fifthecho @retrack @ddoc @jwthomp @C-Duv @ericlathrop @abayer @dduportal @chobbs- @benjimcc Lets move all discussion over to my initial builder release here:

https://github.com/mindjiver/packer-cloudstack

@ghost ghost locked and limited conversation to collaborators Apr 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet