From f65dfdad905d3b49c7708817c06067b445dff88d Mon Sep 17 00:00:00 2001 From: Kendrick Coleman Date: Fri, 11 Mar 2016 17:09:05 -0500 Subject: [PATCH] version 0.0.1 updated everything for a non-production instance Signed-off-by: Kendrick Coleman --- .gitignore | 10 +++++++- README.md | 26 ++++++++++++++------ rackhd.go | 72 ++++++++++++++++++++++++++++++++++-------------------- 3 files changed, 74 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index 776b539..30df212 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,12 @@ _testmain.go *.prof # local dev commands -commands.md \ No newline at end of file +commands.md + +# local builds +*.darwin-amd64 +*.linux-amd64 +*.windows-amd64 +*.Darwin-x86_64 +*.Linux-x86_64 +*.Windows-x86_64 \ No newline at end of file diff --git a/README.md b/README.md index cc6ff17..47aa2a7 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,10 @@ Create Docker hosts with [RackHD](https://github.com/RackHD/RackHD). ## Installation -Not ready for use. Stay Tuned! +**Linux & Mac OSX**: +``` +curl -L https://github.com/emccode/docker-machine-rackhd/releases/download/v0.0.1/docker-machine-driver-rackhd.`uname -s`-`uname -m` >/usr/local/bin/docker-machine-driver-rackhd && chmod +x /usr/local/bin/docker-machine-driver-rackhd +``` ## Using the driver @@ -31,32 +34,41 @@ Options: | Option | Environment Variable | Default | Description | Required? | |-------------------------|:---------------------:|---------|-------------------------------------------------|:---------:| -| --rackhd-endpoint | RACKHD_ENDPOINT | localhost:9090 | RackHD Endpoint for API traffic | N | +| --rackhd-endpoint | RACKHD_ENDPOINT | localhost:8080 | RackHD Endpoint for API traffic | N | | --rackhd-node-id | RACKHD_NODE_ID | | Specify Node ID, MAC Address or IP Address | Y | | --rackhd-transport | RACKHD_TRANSPORT | http | RackHD Endpoint Transport. Specify http or https | N | | --rackhd-ssh-user | RACKHD_SSH_USER | root | SSH User Name for the node | N | | --rackhd-ssh-password | RACKHD_SSH_PASSWORD | root | SSH Password for the node | N | | --rackhd-ssh-port | RACKHD_SSH_PORT | 22 | SSH Port for the node | N | -This initial version of the driver uses explicit instructions. The user must specify the Node ID from RackHD. The NodeID is characterized as a `compute` instance. Do not use `enclosure`. +This initial version of the driver uses explicit creation instructions. The user must specify the Node ID from RackHD. The NodeID is characterized as a `compute` instance. Do not use `enclosure`. Create a Docker host using the following example. The client assumes you are using a Vagant instance. Note at this time, it will fail because the nodes being PXE booted via Vagrant do not have SSH access. SSH access is possible by creating an additional NIC, but RackHD doesn't have the capability to get the IP Address and add it to its own database if it didn't give the IP. This will work best using physical hardware and a network where Docker Machine has access to the DHCP network of RackHD ``` $ docker-machine create -d rackhd --rackhd-node-id 56c61189f21f01b608b3e594 rackhdtest Running pre-create checks... +(rackhdtest) Testing accessibility of endpoint: localhost:8080 +(rackhdtest) Test Passed. localhost:8080 is accessbile and installation will begin Creating machine... -Connection succeeded on: 172.31.128.2:22 +(rackhdtest) Connection succeeded on: 172.31.128.16:22 +(rackhdtest) Creating SSH key... +(rackhdtest) Copy public SSH key to rackhdtest [172.31.128.16] Waiting for machine to be running, this may take a few minutes... -Machine is running, waiting for SSH to be available... Detecting operating system of created instance... -Provisioning created instance... +Waiting for SSH to be available... +Detecting the provisioner... +Provisioning with centos... Copying certs to the local machine directory... Copying certs to the remote machine... Setting Docker configuration on the remote daemon... -To see how to connect Docker to this machine, run: docker-machine env rackhdtest +Configuring swarm... +Checking connection to Docker... +Docker is up and running! +To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env rackhdtest ``` +Checkout the [RackHD Vagrant + Docker Machine Example](https://github.com/emccode/machine/tree/master/rackhd) to get a complete in-depth configuration and walk-through. # Licensing Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at diff --git a/rackhd.go b/rackhd.go index 9e09781..a62519c 100644 --- a/rackhd.go +++ b/rackhd.go @@ -17,7 +17,6 @@ import ( "github.com/docker/machine/libmachine/drivers" "github.com/docker/machine/libmachine/log" "github.com/docker/machine/libmachine/mcnflag" - //"github.com/docker/machine/libmachine/mcnutils" "github.com/docker/machine/libmachine/ssh" "github.com/docker/machine/libmachine/state" @@ -81,12 +80,26 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag { Usage: "ssh port (default:22)", Value: defaultSSHPort, }, - /* TODO: Grab SSH User and PW from Workflow. - mcnflag.StringFlag{ - EnvVar: "RACKHD_WORKFLOW_ID", - Name: "rackhd-workflow-id", - Usage: "workflow ID used to extract SSH user information (optional)", - },*/ + /* + TODO: Grab SSH User and PW from Workflow. + mcnflag.StringFlag{ + EnvVar: "RACKHD_WORKFLOW_ID", + Name: "rackhd-workflow-id", + Usage: "workflow ID used to extract SSH user information (optional)", + }, + TODO: Implicit creation from a pool + mcnflag.StringFlag{ + EnvVar: "RACKHD_POOL_ID", + Name: "rackhd-POOL-id", + Usage: "POOL ID", + }, + TODO: API Authentication Values. Will be detemined for v 2.0 of API + mcnflag.StringFlag{ + EnvVar: "RACKHD_ENDPOINT_AUTH", + Name: "rackhd-ENDPOINT_AUTH, + Usage: "ENDPOINT_AUTH", + }, + */ } } @@ -137,10 +150,10 @@ func (d *Driver) PreCreateCheck() error { //Generate the client client := d.getClient() - //do a test to see if the server is available + //do a test to see if the server is available. 2nd Nil is authentication params + // that need to be determined in v2.0 of API _, err := client.Config.GetConfig(nil, nil) if err != nil { - /* THIS ERROR IS NOT OUTPUT CORRECTLY. IT SAYS "unexpected EOF" */ return fmt.Errorf("The Endpoint is not accessible. Error: %s", err) } log.Infof("Test Passed. %v is accessbile and installation will begin", d.Endpoint) @@ -151,7 +164,7 @@ func (d *Driver) Create() error { //Generate the client client := d.getClient() - // do a lookup on the ID + // do a lookup on the ID to retrieve IP information resp, err := client.Lookups.GetLookups(&lookups.GetLookupsParams{Q: d.NodeID}, nil) if err != nil { return err @@ -177,7 +190,7 @@ func (d *Driver) Create() error { return fmt.Errorf("No IP addresses are associated with the Node ID specified. Error: %s", err) } - // loop through slice and see if we can connect to the ip:port + // loop through slice and see if we can connect to the ip:ssh-port for _, ipAddy := range ipAddSlice { ipPort := ipAddy + ":" + strconv.Itoa(d.SSHPort) log.Debugf("Testing connection to: %v", ipPort) @@ -204,7 +217,7 @@ func (d *Driver) Create() error { } d.SSHKey = strings.TrimSpace(key) - //TAKEN FROM THE FUSION DRIVER TO USE SSH + //TAKEN FROM THE FUSION DRIVER TO USE SSH [THANKS!] log.Infof("Copy public SSH key to %s [%s]", d.MachineName, d.IPAddress) // create .ssh folder in users home if err := executeSSHCommand(fmt.Sprintf("mkdir -p /home/%s/.ssh", d.SSHUser), d); err != nil { @@ -267,50 +280,56 @@ func (d *Driver) GetIP() (string, error) { func (d *Driver) GetState() (state.State, error) { /* - TODO - */ - /*switch instance.State { - case "online": - return state.Running, nil - case "offline": - return state.Stopped, nil - } - return state.None, nil + TODO: THIS REQUIRES THE REDFISH API WHICH IS STILL IN DEVELOPMENT + switch instance.State { + case "online": + return state.Running, nil + case "offline": + return state.Stopped, nil + } + return state.None, nil */ return state.Running, nil } func (d *Driver) Start() error { /* - TODO + TODO: THIS REQUIRES THE REDFISH API WHICH IS STILL IN DEVELOPMENT + REMOTELY POWER ON A SERVER VIA IPMI */ return nil } func (d *Driver) Stop() error { /* - TODO + TODO: THIS REQUIRES THE REDFISH API WHICH IS STILL IN DEVELOPMENT + SEND A SIGKILL TO THE OS. OR USE THE API TO GRACEFULLY SHUTDOWN THE HOST */ return nil } func (d *Driver) Remove() error { /* - TODO + TODO: DECIDE WHETHER TO UNINSTALL DOCKER OR + 1. ADD A GENERIC WORKFLOW + 2. REBOOT THE HOST + 3. HOPE THAT GENERIC WORKFLOW WILL RESET THE HOST BACK TO A BLANK SLATE */ return nil } func (d *Driver) Restart() error { /* - TODO + TODO: THIS REQUIRES THE REDFISH API WHICH IS STILL IN DEVELOPMENT + REMOTELY RESET OFF A SERVER VIA IPMI */ return nil } func (d *Driver) Kill() error { /* - TODO + TODO: THIS REQUIRES THE REDFISH API WHICH IS STILL IN DEVELOPMENT + POWER OFF THE HOST VIA IMPI */ return nil } @@ -319,6 +338,7 @@ func (d *Driver) getClient() *apiclient.Monorail { log.Debugf("Getting RackHD Client") if d.client == nil { // create the transport + /** Will Need to determine changes for v 2.0 API **/ transport := httptransport.New(d.Endpoint, "/api/1.1", []string{d.Transport}) // create the API client, with the transport d.client = apiclient.New(transport, strfmt.Default)