Browse Source

Merge "Changed vagrant file so that installation can be easier"

Jenkins 3 years ago
parent
commit
3df93aa053

+ 3
- 1
.gitignore View File

@@ -9,6 +9,7 @@ __pycache__/
9 9
 .Python
10 10
 .testrepository/
11 11
 .venv/
12
+.vagrant/
12 13
 env/
13 14
 bin/
14 15
 build/
@@ -22,10 +23,11 @@ sdist/
22 23
 var/
23 24
 covhtml/
24 25
 cover/
26
+tools/vagrant/ubuntu/leapbin
25 27
 *.egg-info/
26 28
 .installed.cfg
27 29
 *.egg
28
-
30
+.DS_Store
29 31
 # Installer logs
30 32
 pip-log.txt
31 33
 pip-delete-this-directory.txt

+ 6
- 17
ChangeLog View File

@@ -1,18 +1,7 @@
1
-CHANGES
2
-=======
1
+kiloeyes (1.0)
3 2
 
4
-* ES now returns timestamp as milliseconds vs seconds
5
-* enable bulk message post on persister
6
-* Added more instructions
7
-* bulk insert can not be done implicitly
8
-* fix the partitions data type error
9
-* Updated the installation instructions
10
-* added more instruction on how to create an all-in-one kiloeyes
11
-* unit test passed for py27
12
-* Add Vagrant sample file to ease development environment bootstrap
13
-* Make the server more flexible with configuration files
14
-* remove old openstack incubator project reference
15
-* remove old oslo.config and use new oslo_config
16
-* Make minor modifications in the README
17
-* seeding the project
18
-* Added .gitreview
3
+    * Initial project setup
4
+      Choose framework of wsgiref, pasteDeploy, falcon.
5
+      The server will be wsgiref server like any other OpenStack server
6
+      Use PasteDeploy to allow WSGI pipelines
7
+      Use Falcon framework to implement ReSTful API services

+ 0
- 330
tools/colorizer.py View File

@@ -1,330 +0,0 @@
1
-#!/usr/bin/env python
2
-
3
-# Copyright (c) 2013, Nebula, Inc.
4
-# Copyright 2010 United States Government as represented by the
5
-# Administrator of the National Aeronautics and Space Administration.
6
-# All Rights Reserved.
7
-#
8
-#    Licensed under the Apache License, Version 2.0 (the "License"); you may
9
-#    not use this file except in compliance with the License. You may obtain
10
-#    a copy of the License at
11
-#
12
-#         http://www.apache.org/licenses/LICENSE-2.0
13
-#
14
-#    Unless required by applicable law or agreed to in writing, software
15
-#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
-#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
-#    License for the specific language governing permissions and limitations
18
-#    under the License.
19
-#
20
-# Colorizer Code is borrowed from Twisted:
21
-# Copyright (c) 2001-2010 Twisted Matrix Laboratories.
22
-#
23
-#    Permission is hereby granted, free of charge, to any person obtaining
24
-#    a copy of this software and associated documentation files (the
25
-#    "Software"), to deal in the Software without restriction, including
26
-#    without limitation the rights to use, copy, modify, merge, publish,
27
-#    distribute, sublicense, and/or sell copies of the Software, and to
28
-#    permit persons to whom the Software is furnished to do so, subject to
29
-#    the following conditions:
30
-#
31
-#    The above copyright notice and this permission notice shall be
32
-#    included in all copies or substantial portions of the Software.
33
-#
34
-#    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35
-#    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
-#    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37
-#    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38
-#    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39
-#    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40
-#    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41
-
42
-"""Display a subunit stream through a colorized unittest test runner."""
43
-
44
-import heapq
45
-import sys
46
-import unittest
47
-
48
-import subunit
49
-import testtools
50
-
51
-
52
-class _AnsiColorizer(object):
53
-    """A colorizer is an object that loosely wraps around a stream.
54
-
55
-    That allows callers to write text to the stream in a particular color.
56
-    Colorizer classes must implement C{supported()} and C{write(text, color)}.
57
-    """
58
-    _colors = dict(black=30, red=31, green=32, yellow=33,
59
-                   blue=34, magenta=35, cyan=36, white=37)
60
-
61
-    def __init__(self, stream):
62
-        self.stream = stream
63
-
64
-    @staticmethod
65
-    def supported(stream=sys.stdout):
66
-        """Method that checks if the current terminal supports coloring.
67
-
68
-        Returns True or False.
69
-        """
70
-        if not stream.isatty():
71
-            return False  # auto color only on TTYs
72
-        try:
73
-            import curses
74
-        except ImportError:
75
-            return False
76
-        else:
77
-            try:
78
-                try:
79
-                    return curses.tigetnum("colors") > 2
80
-                except curses.error:
81
-                    curses.setupterm()
82
-                    return curses.tigetnum("colors") > 2
83
-            except Exception:
84
-                # guess false in case of error
85
-                return False
86
-
87
-    def write(self, text, color):
88
-        """Write the given text to the stream in the given color.
89
-
90
-        @param text: Text to be written to the stream.
91
-
92
-        @param color: A string label for a color. e.g. 'red', 'white'.
93
-
94
-        """
95
-        color = self._colors[color]
96
-        self.stream.write('\x1b[%s;1m%s\x1b[0m' % (color, text))
97
-
98
-
99
-class _Win32Colorizer(object):
100
-    """See _AnsiColorizer docstring."""
101
-    def __init__(self, stream):
102
-        import win32console
103
-        red, green, blue, bold = (win32console.FOREGROUND_RED,
104
-                                  win32console.FOREGROUND_GREEN,
105
-                                  win32console.FOREGROUND_BLUE,
106
-                                  win32console.FOREGROUND_INTENSITY)
107
-        self.stream = stream
108
-        self.screenBuffer = win32console.GetStdHandle(
109
-            win32console.STD_OUT_HANDLE)
110
-        self._colors = {
111
-            'normal': red | green | blue,
112
-            'red': red | bold,
113
-            'green': green | bold,
114
-            'blue': blue | bold,
115
-            'yellow': red | green | bold,
116
-            'magenta': red | blue | bold,
117
-            'cyan': green | blue | bold,
118
-            'white': red | green | blue | bold
119
-        }
120
-
121
-    @staticmethod
122
-    def supported(stream=sys.stdout):
123
-        try:
124
-            import win32console
125
-            screenBuffer = win32console.GetStdHandle(
126
-                win32console.STD_OUT_HANDLE)
127
-        except ImportError:
128
-            return False
129
-        import pywintypes
130
-        try:
131
-            screenBuffer.SetConsoleTextAttribute(
132
-                win32console.FOREGROUND_RED |
133
-                win32console.FOREGROUND_GREEN |
134
-                win32console.FOREGROUND_BLUE)
135
-        except pywintypes.error:
136
-            return False
137
-        else:
138
-            return True
139
-
140
-    def write(self, text, color):
141
-        color = self._colors[color]
142
-        self.screenBuffer.SetConsoleTextAttribute(color)
143
-        self.stream.write(text)
144
-        self.screenBuffer.SetConsoleTextAttribute(self._colors['normal'])
145
-
146
-
147
-class _NullColorizer(object):
148
-    """See _AnsiColorizer docstring."""
149
-    def __init__(self, stream):
150
-        self.stream = stream
151
-
152
-    @staticmethod
153
-    def supported(stream=sys.stdout):
154
-        return True
155
-
156
-    def write(self, text, color):
157
-        self.stream.write(text)
158
-
159
-
160
-def get_elapsed_time_color(elapsed_time):
161
-    if elapsed_time > 1.0:
162
-        return 'red'
163
-    elif elapsed_time > 0.25:
164
-        return 'yellow'
165
-    else:
166
-        return 'green'
167
-
168
-
169
-class SubunitTestResult(testtools.TestResult):
170
-    def __init__(self, stream, descriptions, verbosity):
171
-        super(SubunitTestResult, self).__init__()
172
-        self.stream = stream
173
-        self.showAll = verbosity > 1
174
-        self.num_slow_tests = 10
175
-        self.slow_tests = []  # this is a fixed-sized heap
176
-        self.colorizer = None
177
-        # NOTE(vish): reset stdout for the terminal check
178
-        stdout = sys.stdout
179
-        sys.stdout = sys.__stdout__
180
-        for colorizer in [_Win32Colorizer, _AnsiColorizer, _NullColorizer]:
181
-            if colorizer.supported():
182
-                self.colorizer = colorizer(self.stream)
183
-                break
184
-        sys.stdout = stdout
185
-        self.start_time = None
186
-        self.last_time = {}
187
-        self.results = {}
188
-        self.last_written = None
189
-
190
-    def _writeElapsedTime(self, elapsed):
191
-        color = get_elapsed_time_color(elapsed)
192
-        self.colorizer.write("  %.2f" % elapsed, color)
193
-
194
-    def _addResult(self, test, *args):
195
-        try:
196
-            name = test.id()
197
-        except AttributeError:
198
-            name = 'Unknown.unknown'
199
-        test_class, test_name = name.rsplit('.', 1)
200
-
201
-        elapsed = (self._now() - self.start_time).total_seconds()
202
-        item = (elapsed, test_class, test_name)
203
-        if len(self.slow_tests) >= self.num_slow_tests:
204
-            heapq.heappushpop(self.slow_tests, item)
205
-        else:
206
-            heapq.heappush(self.slow_tests, item)
207
-
208
-        self.results.setdefault(test_class, [])
209
-        self.results[test_class].append((test_name, elapsed) + args)
210
-        self.last_time[test_class] = self._now()
211
-        self.writeTests()
212
-
213
-    def _writeResult(self, test_name, elapsed, long_result, color,
214
-                     short_result, success):
215
-        if self.showAll:
216
-            self.stream.write('    %s' % str(test_name).ljust(66))
217
-            self.colorizer.write(long_result, color)
218
-            if success:
219
-                self._writeElapsedTime(elapsed)
220
-            self.stream.writeln()
221
-        else:
222
-            self.colorizer.write(short_result, color)
223
-
224
-    def addSuccess(self, test):
225
-        super(SubunitTestResult, self).addSuccess(test)
226
-        self._addResult(test, 'OK', 'green', '.', True)
227
-
228
-    def addFailure(self, test, err):
229
-        if test.id() == 'process-returncode':
230
-            return
231
-        super(SubunitTestResult, self).addFailure(test, err)
232
-        self._addResult(test, 'FAIL', 'red', 'F', False)
233
-
234
-    def addError(self, test, err):
235
-        super(SubunitTestResult, self).addFailure(test, err)
236
-        self._addResult(test, 'ERROR', 'red', 'E', False)
237
-
238
-    def addSkip(self, test, reason=None, details=None):
239
-        super(SubunitTestResult, self).addSkip(test, reason, details)
240
-        self._addResult(test, 'SKIP', 'blue', 'S', True)
241
-
242
-    def startTest(self, test):
243
-        self.start_time = self._now()
244
-        super(SubunitTestResult, self).startTest(test)
245
-
246
-    def writeTestCase(self, cls):
247
-        if not self.results.get(cls):
248
-            return
249
-        if cls != self.last_written:
250
-            self.colorizer.write(cls, 'white')
251
-            self.stream.writeln()
252
-        for result in self.results[cls]:
253
-            self._writeResult(*result)
254
-        del self.results[cls]
255
-        self.stream.flush()
256
-        self.last_written = cls
257
-
258
-    def writeTests(self):
259
-        time = self.last_time.get(self.last_written, self._now())
260
-        if not self.last_written or (self._now() - time).total_seconds() > 2.0:
261
-            diff = 3.0
262
-            while diff > 2.0:
263
-                classes = self.results.keys()
264
-                oldest = min(classes, key=lambda x: self.last_time[x])
265
-                diff = (self._now() - self.last_time[oldest]).total_seconds()
266
-                self.writeTestCase(oldest)
267
-        else:
268
-            self.writeTestCase(self.last_written)
269
-
270
-    def done(self):
271
-        self.stopTestRun()
272
-
273
-    def stopTestRun(self):
274
-        for cls in list(self.results.iterkeys()):
275
-            self.writeTestCase(cls)
276
-        self.stream.writeln()
277
-        self.writeSlowTests()
278
-
279
-    def writeSlowTests(self):
280
-        # Pare out 'fast' tests
281
-        slow_tests = [item for item in self.slow_tests
282
-                      if get_elapsed_time_color(item[0]) != 'green']
283
-        if slow_tests:
284
-            slow_total_time = sum(item[0] for item in slow_tests)
285
-            slow = ("Slowest %i tests took %.2f secs:"
286
-                    % (len(slow_tests), slow_total_time))
287
-            self.colorizer.write(slow, 'yellow')
288
-            self.stream.writeln()
289
-            last_cls = None
290
-            # sort by name
291
-            for elapsed, cls, name in sorted(slow_tests,
292
-                                             key=lambda x: x[1] + x[2]):
293
-                if cls != last_cls:
294
-                    self.colorizer.write(cls, 'white')
295
-                    self.stream.writeln()
296
-                last_cls = cls
297
-                self.stream.write('    %s' % str(name).ljust(68))
298
-                self._writeElapsedTime(elapsed)
299
-                self.stream.writeln()
300
-
301
-    def printErrors(self):
302
-        if self.showAll:
303
-            self.stream.writeln()
304
-        self.printErrorList('ERROR', self.errors)
305
-        self.printErrorList('FAIL', self.failures)
306
-
307
-    def printErrorList(self, flavor, errors):
308
-        for test, err in errors:
309
-            self.colorizer.write("=" * 70, 'red')
310
-            self.stream.writeln()
311
-            self.colorizer.write(flavor, 'red')
312
-            self.stream.writeln(": %s" % test.id())
313
-            self.colorizer.write("-" * 70, 'red')
314
-            self.stream.writeln()
315
-            self.stream.writeln("%s" % err)
316
-
317
-
318
-test = subunit.ProtocolTestCase(sys.stdin, passthrough=None)
319
-
320
-if sys.version_info[0:2] <= (2, 6):
321
-    runner = unittest.TextTestRunner(verbosity=2)
322
-else:
323
-    runner = unittest.TextTestRunner(
324
-        verbosity=2, resultclass=SubunitTestResult)
325
-
326
-if runner.run(test).wasSuccessful():
327
-    exit_code = 0
328
-else:
329
-    exit_code = 1
330
-sys.exit(exit_code)

+ 0
- 73
tools/install_venv.py View File

@@ -1,73 +0,0 @@
1
-# Copyright 2010 United States Government as represented by the
2
-# Administrator of the National Aeronautics and Space Administration.
3
-# All Rights Reserved.
4
-#
5
-# Copyright 2010 OpenStack Foundation
6
-# Copyright 2013 IBM Corp.
7
-#
8
-#    Licensed under the Apache License, Version 2.0 (the "License"); you may
9
-#    not use this file except in compliance with the License. You may obtain
10
-#    a copy of the License at
11
-#
12
-#         http://www.apache.org/licenses/LICENSE-2.0
13
-#
14
-#    Unless required by applicable law or agreed to in writing, software
15
-#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
-#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
-#    License for the specific language governing permissions and limitations
18
-#    under the License.
19
-
20
-"""
21
-Installation script for Glance's development virtualenv
22
-"""
23
-
24
-from __future__ import print_function
25
-
26
-import os
27
-import sys
28
-
29
-import install_venv_common as install_venv  # noqa
30
-
31
-
32
-def print_help():
33
-    help = """
34
- Glance development environment setup is complete.
35
-
36
- Glance development uses virtualenv to track and manage Python dependencies
37
- while in development and testing.
38
-
39
- To activate the Glance virtualenv for the extent of your current shell session
40
- you can run:
41
-
42
- $ source .venv/bin/activate
43
-
44
- Or, if you prefer, you can run commands in the virtualenv on a case by case
45
- basis by running:
46
-
47
- $ tools/with_venv.sh <your command>
48
-
49
- Also, make test will automatically use the virtualenv.
50
-    """
51
-    print(help)
52
-
53
-
54
-def main(argv):
55
-    root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
56
-    venv = os.path.join(root, '.venv')
57
-    pip_requires = os.path.join(root, 'requirements.txt')
58
-    test_requires = os.path.join(root, 'test-requirements.txt')
59
-    py_version = "python%s.%s" % (sys.version_info[0], sys.version_info[1])
60
-    project = 'Kiloeyes'
61
-    install = install_venv.InstallVenv(root, venv, pip_requires, test_requires,
62
-                                       py_version, project)
63
-    options = install.parse_args(argv)
64
-    install.check_python_version()
65
-    install.check_dependencies()
66
-    install.create_virtualenv(no_site_packages=options.no_site_packages)
67
-    install.install_dependencies()
68
-    install.run_command([os.path.join(venv, 'bin/python'),
69
-                        'setup.py', 'develop'])
70
-    print_help()
71
-
72
-if __name__ == '__main__':
73
-    main(sys.argv)

+ 0
- 172
tools/install_venv_common.py View File

@@ -1,172 +0,0 @@
1
-# Copyright 2013 OpenStack Foundation
2
-# Copyright 2013 IBM Corp.
3
-#
4
-#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
-#    not use this file except in compliance with the License. You may obtain
6
-#    a copy of the License at
7
-#
8
-#         http://www.apache.org/licenses/LICENSE-2.0
9
-#
10
-#    Unless required by applicable law or agreed to in writing, software
11
-#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
-#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
-#    License for the specific language governing permissions and limitations
14
-#    under the License.
15
-
16
-"""Provides methods needed by installation script for OpenStack development
17
-virtual environments.
18
-
19
-Since this script is used to bootstrap a virtualenv from the system's Python
20
-environment, it should be kept strictly compatible with Python 2.6.
21
-
22
-Synced in from openstack-common
23
-"""
24
-
25
-from __future__ import print_function
26
-
27
-import optparse
28
-import os
29
-import subprocess
30
-import sys
31
-
32
-
33
-class InstallVenv(object):
34
-
35
-    def __init__(self, root, venv, requirements,
36
-                 test_requirements, py_version,
37
-                 project):
38
-        self.root = root
39
-        self.venv = venv
40
-        self.requirements = requirements
41
-        self.test_requirements = test_requirements
42
-        self.py_version = py_version
43
-        self.project = project
44
-
45
-    def die(self, message, *args):
46
-        print(message % args, file=sys.stderr)
47
-        sys.exit(1)
48
-
49
-    def check_python_version(self):
50
-        if sys.version_info < (2, 6):
51
-            self.die("Need Python Version >= 2.6")
52
-
53
-    def run_command_with_code(self, cmd, redirect_output=True,
54
-                              check_exit_code=True):
55
-        """Runs a command in an out-of-process shell.
56
-
57
-        Returns the output of that command. Working directory is self.root.
58
-        """
59
-        if redirect_output:
60
-            stdout = subprocess.PIPE
61
-        else:
62
-            stdout = None
63
-
64
-        proc = subprocess.Popen(cmd, cwd=self.root, stdout=stdout)
65
-        output = proc.communicate()[0]
66
-        if check_exit_code and proc.returncode != 0:
67
-            self.die('Command "%s" failed.\n%s', ' '.join(cmd), output)
68
-        return (output, proc.returncode)
69
-
70
-    def run_command(self, cmd, redirect_output=True, check_exit_code=True):
71
-        return self.run_command_with_code(cmd, redirect_output,
72
-                                          check_exit_code)[0]
73
-
74
-    def get_distro(self):
75
-        if (os.path.exists('/etc/fedora-release') or
76
-                os.path.exists('/etc/redhat-release')):
77
-            return Fedora(
78
-                self.root, self.venv, self.requirements,
79
-                self.test_requirements, self.py_version, self.project)
80
-        else:
81
-            return Distro(
82
-                self.root, self.venv, self.requirements,
83
-                self.test_requirements, self.py_version, self.project)
84
-
85
-    def check_dependencies(self):
86
-        self.get_distro().install_virtualenv()
87
-
88
-    def create_virtualenv(self, no_site_packages=True):
89
-        """Creates the virtual environment and installs PIP.
90
-
91
-        Creates the virtual environment and installs PIP only into the
92
-        virtual environment.
93
-        """
94
-        if not os.path.isdir(self.venv):
95
-            print('Creating venv...', end=' ')
96
-            if no_site_packages:
97
-                self.run_command(['virtualenv', '-q', '--no-site-packages',
98
-                                 self.venv])
99
-            else:
100
-                self.run_command(['virtualenv', '-q', self.venv])
101
-            print('done.')
102
-        else:
103
-            print("venv already exists...")
104
-            pass
105
-
106
-    def pip_install(self, *args):
107
-        self.run_command(['tools/with_venv.sh',
108
-                         'pip', 'install', '--upgrade'] + list(args),
109
-                         redirect_output=False)
110
-
111
-    def install_dependencies(self):
112
-        print('Installing dependencies with pip (this can take a while)...')
113
-
114
-        # First things first, make sure our venv has the latest pip and
115
-        # setuptools and pbr
116
-        self.pip_install('pip>=1.4')
117
-        self.pip_install('setuptools')
118
-        self.pip_install('pbr')
119
-
120
-        self.pip_install('-r', self.requirements, '-r', self.test_requirements)
121
-
122
-    def parse_args(self, argv):
123
-        """Parses command-line arguments."""
124
-        parser = optparse.OptionParser()
125
-        parser.add_option('-n', '--no-site-packages',
126
-                          action='store_true',
127
-                          help="Do not inherit packages from global Python "
128
-                               "install.")
129
-        return parser.parse_args(argv[1:])[0]
130
-
131
-
132
-class Distro(InstallVenv):
133
-
134
-    def check_cmd(self, cmd):
135
-        return bool(self.run_command(['which', cmd],
136
-                    check_exit_code=False).strip())
137
-
138
-    def install_virtualenv(self):
139
-        if self.check_cmd('virtualenv'):
140
-            return
141
-
142
-        if self.check_cmd('easy_install'):
143
-            print('Installing virtualenv via easy_install...', end=' ')
144
-            if self.run_command(['easy_install', 'virtualenv']):
145
-                print('Succeeded')
146
-                return
147
-            else:
148
-                print('Failed')
149
-
150
-        self.die('ERROR: virtualenv not found.\n\n%s development'
151
-                 ' requires virtualenv, please install it using your'
152
-                 ' favorite package management tool' % self.project)
153
-
154
-
155
-class Fedora(Distro):
156
-    """This covers all Fedora-based distributions.
157
-
158
-    Includes: Fedora, RHEL, CentOS, Scientific Linux
159
-    """
160
-
161
-    def check_pkg(self, pkg):
162
-        return self.run_command_with_code(['rpm', '-q', pkg],
163
-                                          check_exit_code=False)[1] == 0
164
-
165
-    def install_virtualenv(self):
166
-        if self.check_cmd('virtualenv'):
167
-            return
168
-
169
-        if not self.check_pkg('python-virtualenv'):
170
-            self.die("Please install 'python-virtualenv'.")
171
-
172
-        super(Fedora, self).install_virtualenv()

+ 7
- 0
tools/vagrant/rebootvm.sh View File

@@ -0,0 +1,7 @@
1
+VBoxManage snapshot h2-compute01 restore "Snapshot 3"
2
+VBoxManage snapshot h2-nova restore "Snapshot 3"
3
+VBoxManage snapshot h2-controller restore "Snapshot 3"
4
+
5
+vboxmanage startvm h2-compute01 --type headless
6
+vboxmanage startvm h2-nova --type headless
7
+vboxmanage startvm h2-controller --type headless

+ 3
- 0
tools/vagrant/stvm.sh View File

@@ -0,0 +1,3 @@
1
+vboxmanage controlvm h2-compute01 acpipowerbutton
2
+vboxmanage controlvm h2-nova acpipowerbutton
3
+vboxmanage controlvm h2-controller acpipowerbutton

+ 55
- 45
tools/vagrant/ubuntu/Vagrantfile View File

@@ -2,49 +2,59 @@
2 2
 # vi: set ft=ruby :
3 3
 require 'yaml'
4 4
 
5
-config_file=File.expand_path(File.join(File.dirname(__FILE__), 'ubuntu-virtualbox.yml'))
6
-settings=YAML.load_file(config_file)
7
-
8
-VM_MEM = settings['vm_memory']
9
-KAFKA_URL = settings['kafka_url']
10
-# ElasticSearch URL
11
-ES_URL = settings['elasticsearch_url']
12
-
13
-# All Vagrant configuration is done below. The "2" in Vagrant.configure
14
-# configures the configuration version (we support older styles for
15
-# backwards compatibility). Please don't change it unless you know what
16
-# you're doing.
17
-Vagrant.configure(2) do |config|
18
-  # The most common configuration options are documented and commented below.
19
-  # For a complete reference, please see the online documentation at
20
-  # https://docs.vagrantup.com.
21
-
22
-  # Every Vagrant development environment requires a box. You can search for
23
-  # boxes at https://atlas.hashicorp.com/search.
24
-  config.vm.box = "ubuntu/trusty64"
25
-
26
-  config.vm.provider "virtualbox" do |vb|
27
-  #   # Display the VirtualBox GUI when booting the machine
28
-  #   vb.gui = true
29
-  #
30
-  #   # Customize the amount of memory on the VM:
31
-     vb.memory = VM_MEM
32
-     config.vm.network "private_network", ip: "192.168.0.10"
33
-   end
34
-  
35
-   config.vm.provision "shell", inline: <<-SHELL
36
-     echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
37
-     echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list
38
-     sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
39
-     sudo apt-get update
40
-     sudo apt-get install -y git build-essential python-pip python-dev vim 
41
-     sudo apt-get install -y virtualenvwrapper
42
-     cd /vagrant && sudo git clone https://github.com/openstack/kiloeyes.git
43
-     echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
44
-     echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
45
-     sudo apt-get install -y oracle-java8-installer
46
-     cd /vagrant && wget #{KAFKA_URL} -O - | tar -zxvf - -C /vagrant 
47
-     wget #{ES_URL} -O /tmp/es.deb && sudo dpkg -i /tmp/es.deb
48
-     echo source /usr/share/virtualenvwrapper/virtualenvwrapper_lazy.sh | tee -a ~/.profile
49
-   SHELL
5
+nodes = YAML.load_file("onvm/conf/nodes.conf.yml")
6
+ids = YAML.load_file("onvm/conf/ids.conf.yml")
7
+
8
+Vagrant.configure("2") do |config|
9
+  config.vm.box = "tknerr/managed-server-dummy"
10
+  config.ssh.username = ids['username']
11
+  config.ssh.password = ids['password']
12
+
13
+  config.vm.synced_folder ".", "/vagrant", disabled: true
14
+  config.vm.synced_folder "onvm", "/onvm", disabled: false, create: true
15
+
16
+
17
+  sync_cfg = nodes['synchfolders']
18
+
19
+  lnodes = nodes['ctlnodes']
20
+  if lnodes
21
+    lnodes.each do |key|
22
+      config.vm.define "#{key}" do |node|
23
+        nodekey = nodes['logical2physical'][key]
24
+
25
+        if sync_cfg[key]
26
+          node.vm.synced_folder sync_cfg[key]['source'],
27
+            sync_cfg[key]['target'], disabled: false, create: true
28
+        end
29
+
30
+        node.vm.provider :managed do |managed|
31
+          managed.server = nodes[nodekey]['eth0']
32
+        end
33
+
34
+        node.vm.provision "#{key}-install", type: "shell" do |s|
35
+          s.path = "onvm/scripts/install-" + key + ".sh"
36
+          s.args = ids['sys_password'] + ' ' + nodes[nodekey]['eth0']
37
+        end
38
+      end
39
+    end
40
+  end
41
+
42
+  # agent node setup
43
+  lnodes = nodes['agentes']
44
+  if lnodes
45
+    lnodes.each do |key|
46
+      config.vm.define "#{key}" do |node|
47
+        node.vm.provider :managed do |managed|
48
+          managed.server = nodes[key]['eth0']
49
+        end
50
+
51
+        node.vm.provision "#{key}-install", type: "shell" do |s|
52
+          s.path = "onvm/scripts/install-agent.sh"
53
+          s.args = ids['sys_password'] + " " + nodes[key]['eth0']
54
+        end
55
+
56
+      end
57
+    end
58
+  end
59
+
50 60
 end

+ 7
- 0
tools/vagrant/ubuntu/onvm/conf/ids.conf.yml View File

@@ -0,0 +1,7 @@
1
+---
2
+username: "root"
3
+
4
+password: "time4fun"
5
+
6
+sys_password: "secret"
7
+

+ 49
- 0
tools/vagrant/ubuntu/onvm/conf/nodes.conf.yml View File

@@ -0,0 +1,49 @@
1
+---
2
+repo:
3
+  host_name: repo.leap.dev
4
+  eth0: 192.168.1.88
5
+  eth1: 192.168.1.88
6
+
7
+controller:
8
+  host_name: controller.leap.dev
9
+  eth0: 192.168.1.90
10
+
11
+devstack:
12
+  host_name: devstack.leap.dev
13
+  eth0: 192.168.1.93
14
+
15
+agent01:
16
+  host_name: agent01.leap.dev
17
+  eth0: 192.168.1.88
18
+
19
+logical2physical:
20
+  kiloeyes: controller
21
+  elastic: controller
22
+  kafka: controller
23
+  devstack: devstack
24
+
25
+
26
+# Define how many logical nodes and the sequence of the installation
27
+ctlnodes:
28
+  - devstack
29
+  - elastic
30
+  - kafka
31
+  - kiloeyes
32
+
33
+agentes:
34
+  - agent01
35
+
36
+uselocalrepo: yes
37
+
38
+aptopt: --force-yes
39
+
40
+
41
+# The nodes should be a list of logical name
42
+# The folder should be a local directory start from the project root
43
+synchfolders:
44
+  elastic:
45
+    source: leapbin
46
+    target: /leapbin
47
+  kiloeyes:
48
+    source: ./../../../../kiloeyes
49
+    target: /opt/kiloeyes

+ 330
- 0
tools/vagrant/ubuntu/onvm/scripts/ini-config View File

@@ -0,0 +1,330 @@
1
+#!/bin/bash
2
+#
3
+# **inc/ini-config** - Configuration/INI functions
4
+#
5
+# Support for manipulating INI-style configuration files
6
+#
7
+# These functions have no external dependencies and no side-effects
8
+
9
+# Save trace setting
10
+INC_CONF_TRACE=$(set +o | grep xtrace)
11
+set +o xtrace
12
+
13
+
14
+# Config Functions
15
+# ================
16
+
17
+# Append a new option in an ini file without replacing the old value
18
+# iniadd [-sudo] config-file section option value1 value2 value3 ...
19
+function iniadd {
20
+    local xtrace
21
+    xtrace=$(set +o | grep xtrace)
22
+    set +o xtrace
23
+    local sudo=""
24
+    if [ $1 == "-sudo" ]; then
25
+        sudo="-sudo "
26
+        shift
27
+    fi
28
+    local file=$1
29
+    local section=$2
30
+    local option=$3
31
+    shift 3
32
+
33
+    local values="$(iniget_multiline $file $section $option) $@"
34
+    iniset_multiline $sudo $file $section $option $values
35
+    $xtrace
36
+}
37
+
38
+# Comment an option in an INI file
39
+# inicomment [-sudo] config-file section option
40
+function inicomment {
41
+    local xtrace
42
+    xtrace=$(set +o | grep xtrace)
43
+    set +o xtrace
44
+    local sudo=""
45
+    if [ $1 == "-sudo" ]; then
46
+        sudo="sudo "
47
+        shift
48
+    fi
49
+    local file=$1
50
+    local section=$2
51
+    local option=$3
52
+
53
+    $sudo sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=.*$\)|#\1|" "$file"
54
+    $xtrace
55
+}
56
+
57
+# Get an option from an INI file
58
+# iniget config-file section option
59
+function iniget {
60
+    local xtrace
61
+    xtrace=$(set +o | grep xtrace)
62
+    set +o xtrace
63
+    local file=$1
64
+    local section=$2
65
+    local option=$3
66
+    local line
67
+
68
+    line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" "$file")
69
+    echo ${line#*=}
70
+    $xtrace
71
+}
72
+
73
+# Get a multiple line option from an INI file
74
+# iniget_multiline config-file section option
75
+function iniget_multiline {
76
+    local xtrace
77
+    xtrace=$(set +o | grep xtrace)
78
+    set +o xtrace
79
+    local file=$1
80
+    local section=$2
81
+    local option=$3
82
+    local values
83
+
84
+    values=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { s/^$option[ \t]*=[ \t]*//gp; }" "$file")
85
+    echo ${values}
86
+    $xtrace
87
+}
88
+
89
+# Determinate is the given option present in the INI file
90
+# ini_has_option config-file section option
91
+function ini_has_option {
92
+    local xtrace
93
+    xtrace=$(set +o | grep xtrace)
94
+    set +o xtrace
95
+    local file=$1
96
+    local section=$2
97
+    local option=$3
98
+    local line
99
+
100
+    line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" "$file")
101
+    $xtrace
102
+    [ -n "$line" ]
103
+}
104
+
105
+# Add another config line for a multi-line option.
106
+# It's normally called after iniset of the same option and assumes
107
+# that the section already exists.
108
+#
109
+# Note that iniset_multiline requires all the 'lines' to be supplied
110
+# in the argument list. Doing that will cause incorrect configuration
111
+# if spaces are used in the config values.
112
+#
113
+# iniadd_literal [-sudo] config-file section option value
114
+function iniadd_literal {
115
+    local xtrace
116
+    xtrace=$(set +o | grep xtrace)
117
+    set +o xtrace
118
+    local sudo=""
119
+    if [ $1 == "-sudo" ]; then
120
+        sudo="sudo "
121
+        shift
122
+    fi
123
+    local file=$1
124
+    local section=$2
125
+    local option=$3
126
+    local value=$4
127
+
128
+    if [[ -z $section || -z $option ]]; then
129
+        $xtrace
130
+        return
131
+    fi
132
+
133
+    # Add it
134
+    $sudo sed -i -e "/^\[$section\]/ a\\
135
+$option = $value
136
+" "$file"
137
+
138
+    $xtrace
139
+}
140
+
141
+# Remove an option from an INI file
142
+# inidelete [-sudo] config-file section option
143
+function inidelete {
144
+    local xtrace
145
+    xtrace=$(set +o | grep xtrace)
146
+    set +o xtrace
147
+    local sudo=""
148
+    if [ $1 == "-sudo" ]; then
149
+        sudo="sudo "
150
+        shift
151
+    fi
152
+    local file=$1
153
+    local section=$2
154
+    local option=$3
155
+
156
+    if [[ -z $section || -z $option ]]; then
157
+        $xtrace
158
+        return
159
+    fi
160
+
161
+    # Remove old values
162
+    $sudo sed -i -e "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ d; }" "$file"
163
+
164
+    $xtrace
165
+}
166
+
167
+# Set an option in an INI file
168
+# iniset [-sudo] config-file section option value
169
+#  - if the file does not exist, it is created
170
+function iniset {
171
+    local xtrace
172
+    xtrace=$(set +o | grep xtrace)
173
+    set +o xtrace
174
+    local sudo=""
175
+    if [ $1 == "-sudo" ]; then
176
+        sudo="sudo "
177
+        shift
178
+    fi
179
+    local file=$1
180
+    local section=$2
181
+    local option=$3
182
+    local value=$4
183
+
184
+    if [[ -z $section || -z $option ]]; then
185
+        $xtrace
186
+        return
187
+    fi
188
+
189
+    if ! grep -q "^\[$section\]" "$file" 2>/dev/null; then
190
+        # Add section at the end
191
+        echo -e "\n[$section]" | $sudo tee --append "$file" > /dev/null
192
+    fi
193
+    if ! ini_has_option "$file" "$section" "$option"; then
194
+        # Add it
195
+        $sudo sed -i -e "/^\[$section\]/ a\\
196
+$option = $value
197
+" "$file"
198
+    else
199
+        local sep
200
+        sep=$(echo -ne "\x01")
201
+        # Replace it
202
+        $sudo sed -i -e '/^\['${section}'\]/,/^\[.*\]/ s'${sep}'^\('${option}'[ \t]*=[ \t]*\).*$'${sep}'\1'"${value}"${sep} "$file"
203
+    fi
204
+    $xtrace
205
+}
206
+
207
+# Set an option in a conf file
208
+# confset [-sudo] config-file option value
209
+#  - if the file does not exist, it is created
210
+function confset {
211
+    local xtrace
212
+    xtrace=$(set +o | grep xtrace)
213
+    set +o xtrace
214
+    local sudo=""
215
+    if [ $1 == "-sudo" ]; then
216
+        sudo="sudo "
217
+        shift
218
+    fi
219
+    local file=$1
220
+    local option=$2
221
+    local value=$3
222
+
223
+    if ! grep -q "^$option" "$file" 2>/dev/null; then
224
+      echo -e "\n$option = $value\n" | $sudo tee --append "$file" > /dev/null
225
+    else
226
+      $sudo sed -i -e 's/^'$option'.*$/'$option' = '$value'/g' $file
227
+    fi
228
+
229
+    $xtrace
230
+}
231
+
232
+# Set a multiple line option in an INI file
233
+# iniset_multiline [-sudo] config-file section option value1 value2 value3 ...
234
+function iniset_multiline {
235
+    local xtrace
236
+    xtrace=$(set +o | grep xtrace)
237
+    set +o xtrace
238
+    local sudo=""
239
+    if [ $1 == "-sudo" ]; then
240
+        sudo="sudo "
241
+        shift
242
+    fi
243
+    local file=$1
244
+    local section=$2
245
+    local option=$3
246
+
247
+    shift 3
248
+    local values
249
+    for v in $@; do
250
+        # The later sed command inserts each new value in the line next to
251
+        # the section identifier, which causes the values to be inserted in
252
+        # the reverse order. Do a reverse here to keep the original order.
253
+        values="$v ${values}"
254
+    done
255
+    if ! grep -q "^\[$section\]" "$file"; then
256
+        # Add section at the end
257
+        echo -e "\n[$section]" | $sudo tee --append "$file" > /dev/null
258
+    else
259
+        # Remove old values
260
+        $sudo sed -i -e "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ d; }" "$file"
261
+    fi
262
+    # Add new ones
263
+    for v in $values; do
264
+        $sudo sed -i -e "/^\[$section\]/ a\\
265
+$option = $v
266
+" "$file"
267
+    done
268
+    $xtrace
269
+}
270
+
271
+# Uncomment an option in an INI file
272
+# iniuncomment config-file section option
273
+function iniuncomment {
274
+    local xtrace
275
+    xtrace=$(set +o | grep xtrace)
276
+    set +o xtrace
277
+    local sudo=""
278
+    if [ $1 == "-sudo" ]; then
279
+        sudo="sudo "
280
+        shift
281
+    fi
282
+    local file=$1
283
+    local section=$2
284
+    local option=$3
285
+    $sudo sed -i -e "/^\[$section\]/,/^\[.*\]/ s|[^ \t]*#[ \t]*\($option[ \t]*=.*$\)|\1|" "$file"
286
+    $xtrace
287
+}
288
+
289
+## Remove all comments in a file
290
+function iniremcomment {
291
+    local xtrace
292
+    xtrace=$(set +o | grep xtrace)
293
+    set +o xtrace
294
+    local sudo=""
295
+    if [ $1 == "-sudo" ]; then
296
+        sudo="sudo "
297
+        shift
298
+    fi
299
+    local file=$1
300
+    local tpfile="$(mktemp)"
301
+    $sudo grep -v "^\#" $1 | sed '/^$/N;/^\n$/D' > $tpfile
302
+    $sudo cp $tpfile $1
303
+    $sudo rm -rf $tmpfile
304
+    $xtrace
305
+}
306
+
307
+function parse_yaml {
308
+   local prefix=$2
309
+   local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
310
+   sed -ne "s|^\($s\):|\1|" \
311
+        -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
312
+        -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p"  $1 |
313
+   awk -F$fs '{
314
+      indent = length($1)/2;
315
+      vname[indent] = $2;
316
+      for (i in vname) {if (i > indent) {delete vname[i]}}
317
+      if (length($3) > 0) {
318
+         vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
319
+         printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
320
+      }
321
+   }'
322
+}
323
+
324
+
325
+# Restore xtrace
326
+$INC_CONF_TRACE
327
+
328
+# Local variables:
329
+# mode: shell-script
330
+# End:

+ 12
- 0
tools/vagrant/ubuntu/onvm/scripts/install-agent.sh View File

@@ -0,0 +1,12 @@
1
+#!/usr/bin/env bash
2
+# $1 sys_password
3
+# $2 public ip eth0
4
+
5
+source /onvm/scripts/ini-config
6
+eval $(parse_yaml '/onvm/conf/nodes.conf.yml' 'leap_')
7
+
8
+#apt-get update
9
+
10
+
11
+echo 'Agent install is now complete!'
12
+

+ 12
- 0
tools/vagrant/ubuntu/onvm/scripts/install-devstack.sh View File

@@ -0,0 +1,12 @@
1
+#!/usr/bin/env bash
2
+# $1 sys_password
3
+# $2 public ip eth0
4
+
5
+source /onvm/scripts/ini-config
6
+eval $(parse_yaml '/onvm/conf/nodes.conf.yml' 'leap_')
7
+
8
+#apt-get update
9
+
10
+
11
+echo 'Devstack install is now complete!'
12
+

+ 20
- 0
tools/vagrant/ubuntu/onvm/scripts/install-elastic.sh View File

@@ -0,0 +1,20 @@
1
+#!/usr/bin/env bash
2
+# $1 sys_password
3
+# $2 public ip eth0
4
+
5
+source /onvm/scripts/ini-config
6
+eval $(parse_yaml '/onvm/conf/nodes.conf.yml' 'leap_')
7
+
8
+# Java is required, install java first
9
+source /onvm/scripts/install-java.sh
10
+
11
+if [ -f /leapbin/elasticsearch-2.*.deb ];then
12
+  dpkg -i /leapbin/elasticsearch-2.*.deb
13
+  echo -e "network.host: $2" >> /etc/elasticsearch/elasticsearch.yml
14
+  update-rc.d elasticsearch defaults
15
+  service elasticsearch restart
16
+  echo 'Elastic install is now complete!'
17
+else
18
+  echo 'Elasticsearch binary was not found!'
19
+  echo 'Download elasticsearch 2.2.x.deb and place it in tools/vagrant/ubuntu/leapbin directory.'
20
+fi

+ 16
- 0
tools/vagrant/ubuntu/onvm/scripts/install-java.sh View File

@@ -0,0 +1,16 @@
1
+#!/usr/bin/env bash
2
+# $1 sys_password
3
+# $2 public ip eth0
4
+
5
+java_installed=$(which java)
6
+if [ -z $java_installed ] && [ -f /leapbin/jdk-8*-linux-x64.tar.gz ]; then
7
+  mkdir -p /opt/jdk
8
+  tar -zxf /leapbin/jdk-*-linux-x64.tar.gz -C /opt/jdk
9
+  mv /opt/jdk/* /opt/jdk/jdk1.8
10
+  update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8/bin/java 100
11
+  update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8/bin/javac 100
12
+  echo 'Java install is now complete!'
13
+else
14
+  echo 'Java has been either installed or not binary package found!'
15
+  echo 'Download java and place it in tools/vagrant/ubuntu/leapbin directory.'
16
+fi

+ 21
- 0
tools/vagrant/ubuntu/onvm/scripts/install-kafka.sh View File

@@ -0,0 +1,21 @@
1
+#!/usr/bin/env bash
2
+# $1 sys_password
3
+# $2 public ip eth0
4
+
5
+source /onvm/scripts/ini-config
6
+eval $(parse_yaml '/onvm/conf/nodes.conf.yml' 'leap_')
7
+
8
+if [ -f /leapbin/kafka_*-0.9.0.0.tgz ]; then
9
+  tar -zxf /leapbin/kafka_*-0.9.0.0.tgz -C /opt
10
+  mv /opt/kafka_*-0.9.0.0 /opt/kafka_0.9.0.0
11
+
12
+  /opt/kafka_0.9.0.0/bin/zookeeper-server-start.sh -daemon /opt/kafka_0.9.0.0/config/zookeeper.properties
13
+  sleep 2
14
+
15
+  /opt/kafka_0.9.0.0/bin/kafka-server-start.sh -daemon /opt/kafka_0.9.0.0/config/server.properties 
16
+
17
+  echo 'Kafka install is now complete!'
18
+else
19
+  echo 'Kafka binary was not found!'
20
+fi
21
+

+ 19
- 0
tools/vagrant/ubuntu/onvm/scripts/install-kiloeyes.sh View File

@@ -0,0 +1,19 @@
1
+#!/usr/bin/env bash
2
+# $1 sys_password
3
+# $2 public ip eth0
4
+
5
+source /onvm/scripts/ini-config
6
+eval $(parse_yaml '/onvm/conf/nodes.conf.yml' 'leap_')
7
+
8
+wget https://bootstrap.pypa.io/ez_setup.py -O - | python
9
+apt-get update
10
+apt-get -qqy install git python-dev python-pip python-pastedeploy
11
+
12
+cd /opt/kiloeyes
13
+pip install -r requirements.txt
14
+python setup.py install
15
+
16
+# Config the kiloeyes
17
+
18
+echo 'Kiloeyes install is now complete!'
19
+

+ 0
- 6
tools/vagrant/ubuntu/ubuntu-virtualbox.yml.sample View File

@@ -1,6 +0,0 @@
1
----
2
-
3
-vm_memory: 8192
4
-kafka_url: http://apache.stu.edu.tw/kafka/0.9.0.0/kafka_2.11-0.9.0.0.tgz 
5
-elasticsearch_url: https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.1.0/elasticsearch-2.1.0.deb
6
-

+ 0
- 7
tools/with_venv.sh View File

@@ -1,7 +0,0 @@
1
-#!/bin/bash
2
-TOOLS_PATH=${TOOLS_PATH:-$(dirname $0)}
3
-VENV_PATH=${VENV_PATH:-${TOOLS_PATH}}
4
-VENV_DIR=${VENV_NAME:-/../.venv}
5
-TOOLS=${TOOLS_PATH}
6
-VENV=${VENV:-${VENV_PATH}/${VENV_DIR}}
7
-source ${VENV}/bin/activate && "$@"

Loading…
Cancel
Save