Browse Source

Initial cut of standalone docker-machine driver for openstack

* Picked up the openstack driver code from docker/machine
Davanum Srinivas 2 years ago
parent
commit
36164b0ccf
11 changed files with 473 additions and 1 deletions
  1. 4
    0
      .gitignore
  2. 191
    0
      LICENSE
  3. 105
    0
      Makefile
  4. 1
    1
      driver/client.go
  5. 0
    0
      driver/openstack.go
  6. 0
    0
      driver/openstack_test.go
  7. 64
    0
      glide.lock
  8. 4
    0
      glide.yaml
  9. 10
    0
      main.go
  10. 40
    0
      tools/install-distro-packages.sh
  11. 54
    0
      tools/test-setup.sh

+ 4
- 0
.gitignore View File

@@ -0,0 +1,4 @@
1
+vendor/
2
+dist/
3
+.envrc
4
+.idea/

+ 191
- 0
LICENSE View File

@@ -0,0 +1,191 @@
1
+
2
+                                 Apache License
3
+                           Version 2.0, January 2004
4
+                        http://www.apache.org/licenses/
5
+
6
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+   1. Definitions.
9
+
10
+      "License" shall mean the terms and conditions for use, reproduction,
11
+      and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+      "Licensor" shall mean the copyright owner or entity authorized by
14
+      the copyright owner that is granting the License.
15
+
16
+      "Legal Entity" shall mean the union of the acting entity and all
17
+      other entities that control, are controlled by, or are under common
18
+      control with that entity. For the purposes of this definition,
19
+      "control" means (i) the power, direct or indirect, to cause the
20
+      direction or management of such entity, whether by contract or
21
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+      outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+      "You" (or "Your") shall mean an individual or Legal Entity
25
+      exercising permissions granted by this License.
26
+
27
+      "Source" form shall mean the preferred form for making modifications,
28
+      including but not limited to software source code, documentation
29
+      source, and configuration files.
30
+
31
+      "Object" form shall mean any form resulting from mechanical
32
+      transformation or translation of a Source form, including but
33
+      not limited to compiled object code, generated documentation,
34
+      and conversions to other media types.
35
+
36
+      "Work" shall mean the work of authorship, whether in Source or
37
+      Object form, made available under the License, as indicated by a
38
+      copyright notice that is included in or attached to the work
39
+      (an example is provided in the Appendix below).
40
+
41
+      "Derivative Works" shall mean any work, whether in Source or Object
42
+      form, that is based on (or derived from) the Work and for which the
43
+      editorial revisions, annotations, elaborations, or other modifications
44
+      represent, as a whole, an original work of authorship. For the purposes
45
+      of this License, Derivative Works shall not include works that remain
46
+      separable from, or merely link (or bind by name) to the interfaces of,
47
+      the Work and Derivative Works thereof.
48
+
49
+      "Contribution" shall mean any work of authorship, including
50
+      the original version of the Work and any modifications or additions
51
+      to that Work or Derivative Works thereof, that is intentionally
52
+      submitted to Licensor for inclusion in the Work by the copyright owner
53
+      or by an individual or Legal Entity authorized to submit on behalf of
54
+      the copyright owner. For the purposes of this definition, "submitted"
55
+      means any form of electronic, verbal, or written communication sent
56
+      to the Licensor or its representatives, including but not limited to
57
+      communication on electronic mailing lists, source code control systems,
58
+      and issue tracking systems that are managed by, or on behalf of, the
59
+      Licensor for the purpose of discussing and improving the Work, but
60
+      excluding communication that is conspicuously marked or otherwise
61
+      designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+      "Contributor" shall mean Licensor and any individual or Legal Entity
64
+      on behalf of whom a Contribution has been received by Licensor and
65
+      subsequently incorporated within the Work.
66
+
67
+   2. Grant of Copyright License. Subject to the terms and conditions of
68
+      this License, each Contributor hereby grants to You a perpetual,
69
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+      copyright license to reproduce, prepare Derivative Works of,
71
+      publicly display, publicly perform, sublicense, and distribute the
72
+      Work and such Derivative Works in Source or Object form.
73
+
74
+   3. Grant of Patent License. Subject to the terms and conditions of
75
+      this License, each Contributor hereby grants to You a perpetual,
76
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+      (except as stated in this section) patent license to make, have made,
78
+      use, offer to sell, sell, import, and otherwise transfer the Work,
79
+      where such license applies only to those patent claims licensable
80
+      by such Contributor that are necessarily infringed by their
81
+      Contribution(s) alone or by combination of their Contribution(s)
82
+      with the Work to which such Contribution(s) was submitted. If You
83
+      institute patent litigation against any entity (including a
84
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+      or a Contribution incorporated within the Work constitutes direct
86
+      or contributory patent infringement, then any patent licenses
87
+      granted to You under this License for that Work shall terminate
88
+      as of the date such litigation is filed.
89
+
90
+   4. Redistribution. You may reproduce and distribute copies of the
91
+      Work or Derivative Works thereof in any medium, with or without
92
+      modifications, and in Source or Object form, provided that You
93
+      meet the following conditions:
94
+
95
+      (a) You must give any other recipients of the Work or
96
+          Derivative Works a copy of this License; and
97
+
98
+      (b) You must cause any modified files to carry prominent notices
99
+          stating that You changed the files; and
100
+
101
+      (c) You must retain, in the Source form of any Derivative Works
102
+          that You distribute, all copyright, patent, trademark, and
103
+          attribution notices from the Source form of the Work,
104
+          excluding those notices that do not pertain to any part of
105
+          the Derivative Works; and
106
+
107
+      (d) If the Work includes a "NOTICE" text file as part of its
108
+          distribution, then any Derivative Works that You distribute must
109
+          include a readable copy of the attribution notices contained
110
+          within such NOTICE file, excluding those notices that do not
111
+          pertain to any part of the Derivative Works, in at least one
112
+          of the following places: within a NOTICE text file distributed
113
+          as part of the Derivative Works; within the Source form or
114
+          documentation, if provided along with the Derivative Works; or,
115
+          within a display generated by the Derivative Works, if and
116
+          wherever such third-party notices normally appear. The contents
117
+          of the NOTICE file are for informational purposes only and
118
+          do not modify the License. You may add Your own attribution
119
+          notices within Derivative Works that You distribute, alongside
120
+          or as an addendum to the NOTICE text from the Work, provided
121
+          that such additional attribution notices cannot be construed
122
+          as modifying the License.
123
+
124
+      You may add Your own copyright statement to Your modifications and
125
+      may provide additional or different license terms and conditions
126
+      for use, reproduction, or distribution of Your modifications, or
127
+      for any such Derivative Works as a whole, provided Your use,
128
+      reproduction, and distribution of the Work otherwise complies with
129
+      the conditions stated in this License.
130
+
131
+   5. Submission of Contributions. Unless You explicitly state otherwise,
132
+      any Contribution intentionally submitted for inclusion in the Work
133
+      by You to the Licensor shall be under the terms and conditions of
134
+      this License, without any additional terms or conditions.
135
+      Notwithstanding the above, nothing herein shall supersede or modify
136
+      the terms of any separate license agreement you may have executed
137
+      with Licensor regarding such Contributions.
138
+
139
+   6. Trademarks. This License does not grant permission to use the trade
140
+      names, trademarks, service marks, or product names of the Licensor,
141
+      except as required for reasonable and customary use in describing the
142
+      origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+   7. Disclaimer of Warranty. Unless required by applicable law or
145
+      agreed to in writing, Licensor provides the Work (and each
146
+      Contributor provides its Contributions) on an "AS IS" BASIS,
147
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+      implied, including, without limitation, any warranties or conditions
149
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+      PARTICULAR PURPOSE. You are solely responsible for determining the
151
+      appropriateness of using or redistributing the Work and assume any
152
+      risks associated with Your exercise of permissions under this License.
153
+
154
+   8. Limitation of Liability. In no event and under no legal theory,
155
+      whether in tort (including negligence), contract, or otherwise,
156
+      unless required by applicable law (such as deliberate and grossly
157
+      negligent acts) or agreed to in writing, shall any Contributor be
158
+      liable to You for damages, including any direct, indirect, special,
159
+      incidental, or consequential damages of any character arising as a
160
+      result of this License or out of the use or inability to use the
161
+      Work (including but not limited to damages for loss of goodwill,
162
+      work stoppage, computer failure or malfunction, or any and all
163
+      other commercial damages or losses), even if such Contributor
164
+      has been advised of the possibility of such damages.
165
+
166
+   9. Accepting Warranty or Additional Liability. While redistributing
167
+      the Work or Derivative Works thereof, You may choose to offer,
168
+      and charge a fee for, acceptance of support, warranty, indemnity,
169
+      or other liability obligations and/or rights consistent with this
170
+      License. However, in accepting such obligations, You may act only
171
+      on Your own behalf and on Your sole responsibility, not on behalf
172
+      of any other Contributor, and only if You agree to indemnify,
173
+      defend, and hold each Contributor harmless for any liability
174
+      incurred by, or claims asserted against, such Contributor by reason
175
+      of your accepting any such warranty or additional liability.
176
+
177
+   END OF TERMS AND CONDITIONS
178
+
179
+   Copyright 2014 Docker, Inc.
180
+
181
+   Licensed under the Apache License, Version 2.0 (the "License");
182
+   you may not use this file except in compliance with the License.
183
+   You may obtain a copy of the License at
184
+
185
+       http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+   Unless required by applicable law or agreed to in writing, software
188
+   distributed under the License is distributed on an "AS IS" BASIS,
189
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+   See the License for the specific language governing permissions and
191
+   limitations under the License.

+ 105
- 0
Makefile View File

@@ -0,0 +1,105 @@
1
+# golang-client Makefile
2
+# Follows the interface defined in the Golang CTI proposed
3
+# in https://review.openstack.org/410355
4
+
5
+#REPO_VERSION?=$(shell git describe --tags)
6
+
7
+GIT_HOST = git.openstack.org
8
+
9
+PWD := $(shell pwd)
10
+BASE_DIR := $(shell basename $(PWD))
11
+# Keep an existing GOPATH, make a private one if it is undefined
12
+GOPATH_DEFAULT := $(PWD)/.go
13
+export GOPATH ?= $(GOPATH_DEFAULT)
14
+PKG := $(shell awk  '/^package: / { print $$2 }' glide.yaml)
15
+DEST := $(GOPATH)/src/$(GIT_HOST)/openstack/$(BASE_DIR)
16
+DEST := $(GOPATH)/src/$(PKG)
17
+
18
+# CTI targets
19
+
20
+depend: work
21
+	cd $(DEST) && glide install
22
+
23
+depend-update: work
24
+	cd $(DEST) && glide update
25
+
26
+build:
27
+	cd $(DEST) && go build
28
+
29
+test: unit functional
30
+
31
+unit: depend
32
+	cd $(DEST) && go test -tags=unit $(shell glide novendor)
33
+
34
+functional:
35
+	@echo "$@ not yet implemented"
36
+
37
+fmt: work
38
+	cd $(DEST) && CGO_ENABLED=0 go fmt ./...
39
+
40
+lint:
41
+	@echo "$@ not yet implemented"
42
+
43
+cover:
44
+	@echo "$@ not yet implemented"
45
+
46
+docs:
47
+	@echo "$@ not yet implemented"
48
+
49
+godoc:
50
+	@echo "$@ not yet implemented"
51
+
52
+releasenotes:
53
+	@echo "Reno not yet implemented for this repo"
54
+
55
+translation:
56
+	@echo "$@ not yet implemented"
57
+
58
+# Do the work here
59
+
60
+# Set up the development environment
61
+env:
62
+	@echo "PWD: $(PWD)"
63
+	@echo "BASE_DIR: $(BASE_DIR)"
64
+	@echo "GOPATH: $(GOPATH)"
65
+	@echo "GOROOT: $(GOROOT)"
66
+	@echo "DEST: $(DEST)"
67
+	@echo "PKG: $(PKG)"
68
+
69
+# Get our dev/test dependencies in place
70
+bootstrap:
71
+	tools/test-setup.sh
72
+
73
+work: $(GOPATH) $(DEST)
74
+
75
+$(GOPATH):
76
+	mkdir -p $(GOPATH)
77
+
78
+$(DEST): $(GOPATH)
79
+	mkdir -p $(shell dirname $(DEST))
80
+	ln -s $(PWD) $(DEST)
81
+
82
+.bindep:
83
+	virtualenv .bindep
84
+	.bindep/bin/pip install bindep
85
+
86
+bindep: .bindep
87
+	@.bindep/bin/bindep -b -f bindep.txt || true
88
+
89
+install-distro-packages:
90
+	tools/install-distro-packages.sh
91
+
92
+clean:
93
+	rm -rf .bindep docker-machine-openstack
94
+
95
+realclean: clean
96
+	rm -rf vendor
97
+	if [ "$(GOPATH)" = "$(GOPATH_DEFAULT)" ]; then \
98
+		rm -rf $(GOPATH); \
99
+	fi
100
+
101
+shell: work
102
+	cd $(DEST) && $(SHELL) -i
103
+
104
+.PHONY: bindep build clean cover depend docs fmt functional lint realclean \
105
+	relnotes test translation

drivers/openstack/client.go → driver/client.go View File

@@ -400,7 +400,7 @@ func (c *GenericClient) getNovaNetworkFloatingIPs(d *Driver) ([]FloatingIP, erro
400 400
 	ips := []FloatingIP{}
401 401
 	err := pager.EachPage(func(page pagination.Page) (continue_paging bool, err error) {
402 402
 		continue_paging, err = true, nil
403
-		ipListing, err := compute_ips.ExtractFloatingIPs(page)
403
+		ipListing, _ := compute_ips.ExtractFloatingIPs(page)
404 404
 
405 405
 		for _, ip := range ipListing {
406 406
 			if ip.InstanceID == "" && ip.Pool == d.FloatingIpPool {

drivers/openstack/openstack.go → driver/openstack.go View File


drivers/openstack/openstack_test.go → driver/openstack_test.go View File


+ 64
- 0
glide.lock View File

@@ -0,0 +1,64 @@
1
+hash: 2ae414367804198c51ad47534bc4a00c8b68b2eddb850ffcfdf5f3a112b68b65
2
+updated: 2017-03-16T16:09:29.619642963-04:00
3
+imports:
4
+- name: github.com/docker/docker
5
+  version: a8a31eff10544860d2188dddabdee4d727545796
6
+  subpackages:
7
+  - pkg/term
8
+- name: github.com/docker/machine
9
+  version: 0f08d3c510bc8c2a2c087cabd6614d8776ca8687
10
+  subpackages:
11
+  - libmachine/drivers
12
+  - libmachine/drivers/plugin
13
+  - libmachine/drivers/plugin/localbinary
14
+  - libmachine/drivers/rpc
15
+  - libmachine/log
16
+  - libmachine/mcnflag
17
+  - libmachine/mcnutils
18
+  - libmachine/ssh
19
+  - libmachine/state
20
+  - libmachine/version
21
+  - version
22
+- name: github.com/mitchellh/mapstructure
23
+  version: 740c764bc6149d3f1806231418adb9f52c11bcbf
24
+- name: github.com/rackspace/gophercloud
25
+  version: ce0f487f6747ab43c4e4404722df25349385bebd
26
+  subpackages:
27
+  - openstack
28
+  - openstack/compute/v2/extensions/floatingip
29
+  - openstack/compute/v2/extensions/keypairs
30
+  - openstack/compute/v2/extensions/startstop
31
+  - openstack/compute/v2/flavors
32
+  - openstack/compute/v2/images
33
+  - openstack/compute/v2/servers
34
+  - openstack/identity/v2/tenants
35
+  - openstack/identity/v2/tokens
36
+  - openstack/identity/v3/tokens
37
+  - openstack/networking/v2/extensions/layer3/floatingips
38
+  - openstack/networking/v2/networks
39
+  - openstack/networking/v2/ports
40
+  - openstack/utils
41
+  - pagination
42
+  - rackspace
43
+  - rackspace/identity/v2/tokens
44
+  - testhelper
45
+  - testhelper/client
46
+- name: github.com/stretchr/testify
47
+  version: 4d4bfba8f1d1027c4fdbe371823030df51419987
48
+  subpackages:
49
+  - assert
50
+- name: golang.org/x/crypto
51
+  version: beef0f4390813b96e8e68fd78570396d0f4751fc
52
+  subpackages:
53
+  - curve25519
54
+  - ssh
55
+  - ssh/terminal
56
+testImports:
57
+- name: github.com/davecgh/go-spew
58
+  version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d
59
+  subpackages:
60
+  - spew
61
+- name: github.com/pmezard/go-difflib
62
+  version: 792786c7400a136282c1664665ae0a8db921c6c2
63
+  subpackages:
64
+  - difflib

+ 4
- 0
glide.yaml View File

@@ -0,0 +1,4 @@
1
+package: git.openstack.org/openstack/docker-machine-openstack
2
+import:
3
+- package: github.com/docker/machine
4
+- package: github.com/stretchr/testify

+ 10
- 0
main.go View File

@@ -0,0 +1,10 @@
1
+package main
2
+
3
+import (
4
+	"git.openstack.org/openstack/docker-machine-openstack/driver"
5
+	"github.com/docker/machine/libmachine/drivers/plugin"
6
+)
7
+
8
+func main() {
9
+	plugin.RegisterDriver(openstack.NewDriver("default", "path"))
10
+}

+ 40
- 0
tools/install-distro-packages.sh View File

@@ -0,0 +1,40 @@
1
+#!/bin/bash -xe
2
+
3
+# Local version to install bindep packages
4
+# Suitable for use for development
5
+
6
+function is_fedora {
7
+    [ -f /usr/bin/yum ] && cat /etc/*release | grep -q -e "Fedora"
8
+}
9
+
10
+PACKAGES=""
11
+if ! which virtualenv; then
12
+    PACKAGES="$PACKAGES virtualenv"
13
+fi
14
+if ! which make; then
15
+    PACKAGES="$PACKAGES make"
16
+fi
17
+if [[ -n $PACKAGES ]]; then
18
+    sudo apt-get -q --assume-yes install virtualenv
19
+fi
20
+
21
+# Check for bindep
22
+if ! which bindep; then
23
+    make bindep
24
+fi
25
+
26
+PACKAGES=$(make bindep || true)
27
+
28
+# inspired from project-config install-distro-packages.sh
29
+if apt-get -v >/dev/null 2>&1 ; then
30
+    sudo apt-get -qq update
31
+    sudo PATH=/usr/sbin:/sbin:$PATH DEBIAN_FRONTEND=noninteractive \
32
+        apt-get -q --option "Dpkg::Options::=--force-confold" \
33
+        --assume-yes install $PACKAGES
34
+elif emerge --version >/dev/null 2>&1 ; then
35
+    sudo emerge -uDNq --jobs=4 @world
36
+    sudo PATH=/usr/sbin:/sbin:$PATH emerge -q --jobs=4 $PACKAGES
37
+else
38
+    is_fedora && YUM=dnf || YUM=yum
39
+    sudo PATH=/usr/sbin:/sbin:$PATH $YUM install -y $PACKAGES
40
+fi

+ 54
- 0
tools/test-setup.sh View File

@@ -0,0 +1,54 @@
1
+#!/bin/bash -xe
2
+# test-setup.sh - Install required stuffs
3
+# Used in both CI jobs and locally
4
+#
5
+# Install the following tools:
6
+# * glide
7
+
8
+# Get OS
9
+case $(uname -s) in
10
+    Darwin)
11
+        OS=darwin
12
+        ;;
13
+    Linux)
14
+        if LSB_RELEASE=$(which lsb_release); then
15
+            OS=$($LSB_RELEASE -s -c)
16
+        else
17
+            # No lsb-release, trya hack or two
18
+            if which dpkg 1>/dev/null; then
19
+                OS=debian
20
+            elif which yum 1>/dev/null || which dnf 1>/dev/null; then
21
+                OS=redhat
22
+            else
23
+                echo "Linux distro not yet supported"
24
+                exit 1
25
+            fi
26
+        fi
27
+        ;;
28
+    *)
29
+        echo "Unsupported OS"
30
+        exit 1
31
+        ;;
32
+esac
33
+
34
+case $OS in
35
+    darwin)
36
+        if which brew 1>/dev/null; then
37
+            if ! which glide 1>/dev/null; then
38
+                brew install glide
39
+            fi
40
+        else
41
+            echo "Homebrew not found, install Glide from source?"
42
+        fi
43
+        ;;
44
+    xenial)
45
+        APT_GET="DEBIAN_FRONTEND=noninteractive \
46
+            apt-get -q --option "Dpkg::Options::=--force-confold" \
47
+            --assume-yes"
48
+        if ! which add-apt-repository 1>/dev/null; then
49
+            sudo $APT_GET install software-properties-common
50
+        fi
51
+        sudo add-apt-repository --yes ppa:masterminds/glide && sudo apt-get update
52
+        sudo $APT_GET install glide
53
+        ;;
54
+esac

Loading…
Cancel
Save