Browse Source

Cleanup oslo.config

- Remove config opts and orchestrator ctor document redundancy

- Make "atomic" an attribute of orchestrator

- A bit reordering of opts

- Cleanup and rename inception.conf.sample

- Some other minors: Authors, setup.py

Change-Id: I9c501acf4a11c2fc0056130bd163bbccd2ec9e24
Changbin Liu 5 years ago
parent
commit
d0f14b4b3b
5 changed files with 97 additions and 142 deletions
  1. 1
    0
      Authors
  2. 0
    48
      etc/inception/inception.conf
  3. 25
    0
      etc/inception/inception.conf.sample
  4. 69
    90
      inception/orchestrator.py
  5. 2
    4
      setup.py

+ 1
- 0
Authors View File

@@ -1,2 +1,3 @@
1
+Andrew Forrest <aj4est@gmail.com>
1 2
 Changbin Liu <changbin.liu@gmail.com>
2 3
 Yun Mao <yunmao@gmail.com>

+ 0
- 48
etc/inception/inception.conf View File

@@ -1,48 +0,0 @@
1
-# inception.conf
2
-#
3
-# To use this configuration, add one of the following options to your command
4
-# line:
5
-#
6
-#   --config-file <d>/inception.conf
7
-# or
8
-#   --config-dir <d>
9
-#
10
-# where <d> is the path to the directory containing this file
11
-
12
-[DEFAULT]
13
-
14
-# user - login id with sudo for image used for nodes in Inception Cloud
15
-user = ubuntu
16
-
17
-# image - id of image used to construct nodes in Inception Cloud
18
-image = f3d62d5b-a76b-4997-a579-ff946a606132
19
-
20
-# flavor - id of machine flavor used for  nodes in Inception Cloud (3 = med)
21
-flavor = 3
22
-
23
-# gateway_flavor - id of machine flavor used to construct GW in Inception Cloud
24
-gateway_flavor = 1
25
-
26
-# key_name - name of PK pair for node access
27
-key_name = <your_key_name_here>
28
-
29
-# security_groups - firewall rules
30
-security_groups = default, ssh
31
-
32
-# src_dir - source location of various chef-related setup scripts on client
33
-src_dir = ../bin/
34
-
35
-# dst_dir - absolute destination path for chef-related setup scripts on nodes
36
-dst_dir = /home/ubuntu/
37
-
38
-# userdata - bash script run by cloud-init in late boot stage (rc.local-like)
39
-userdata = userdata.sh.template
40
-
41
-# timeout - maximum time to wait for all servers to be reachable (seconds)
42
-timeout = 999999
43
-
44
-# poll_interval - interval between readiness [ssh+userdata] polls (seconds)
45
-poll_interval = 5
46
-
47
-# pool - name of pool for floating IP addresses
48
-pool = research

+ 25
- 0
etc/inception/inception.conf.sample View File

@@ -0,0 +1,25 @@
1
+[DEFAULT]
2
+
3
+user = ubuntu
4
+
5
+image = f3d62d5b-a76b-4997-a579-ff946a606132
6
+
7
+flavor = 3
8
+
9
+gateway_flavor = 1
10
+
11
+key_name = shared
12
+
13
+security_groups = default, ssh
14
+
15
+src_dir = ../bin/
16
+
17
+dst_dir = /home/ubuntu/
18
+
19
+userdata = userdata.sh.template
20
+
21
+timeout = 999999
22
+
23
+poll_interval = 5
24
+
25
+pool = research

+ 69
- 90
inception/orchestrator.py View File

@@ -27,7 +27,6 @@ developer/user
27 27
 
28 28
 from collections import OrderedDict
29 29
 import functools
30
-import getopt
31 30
 import os
32 31
 import Queue
33 32
 import subprocess
@@ -43,84 +42,86 @@ from oslo.config import cfg
43 42
 from inception import __version__
44 43
 from inception.utils import cmd
45 44
 
46
-CONF = cfg.CONF
47
-
48
-inception_opts = [
45
+orchestrator_opts = [
49 46
     cfg.StrOpt('prefix',
50 47
                default=None,
51
-               metavar='PREFIX',
52 48
                required=True,
53 49
                short='p',
54
-               help='(unique) prefix for node names (no hyphens allowed)'),
50
+               help='unique prefix for node names (no hyphens allowed)'),
55 51
     cfg.IntOpt('num_workers',
56 52
                default=2,
57
-               metavar='NUM',
58 53
                short='n',
59 54
                help='number of worker nodes to create'),
60
-    cfg.BoolOpt('shell',
61
-                default=False,
62
-                help='initialize, then drop to embedded IPython shell'),
63 55
     cfg.BoolOpt('atomic',
64 56
                 default=False,
65
-                help='on error, run as if --cleanup was specified'),
66
-    cfg.BoolOpt('cleanup',
67
-                default=False,
68
-                help='take down the inception cloud'),
57
+                help='on error, whether rollback, i.e., auto delete all'
58
+                     ' created virtual resources'),
69 59
     cfg.BoolOpt('parallel',
70 60
                 default=False,
71
-                help='execute chef-related setup tasks in parallel'),
61
+                help='execute Chef-related setup tasks in parallel'),
72 62
     cfg.StrOpt('chef_repo',
73 63
                default='git://github.com/maoy/inception-chef-repo.git',
74
-               metavar='URL',
75
-               help='URL of Chef repo'),
64
+               help='URL of Chef repository'),
76 65
     cfg.StrOpt('chef_repo_branch',
77 66
                default='master',
78
-               metavar='BRANCH',
79 67
                help='name of branch of Chef repo to use'),
80 68
     cfg.StrOpt('ssh_keyfile',
81 69
                default=None,
82
-               metavar='PATH',
83
-               help='path of additional keyfile for node access via ssh'),
70
+               help='path of extra public key(s) for node access via ssh'),
84 71
     cfg.StrOpt('pool',
85 72
                default='research',
86 73
                help='name of pool for floating IP addresses'),
87 74
     cfg.StrOpt('user',
88 75
                default='ubuntu',
89
-               help=''),
76
+               help='login id with sudo for all nodes'),
90 77
     cfg.StrOpt('image',
91 78
                default='f3d62d5b-a76b-4997-a579-ff946a606132',
92
-               help=''),
79
+               help='id of image used to construct nodes (=u1204-130531-gv)'),
93 80
     cfg.IntOpt('flavor',
94 81
                default=3,
95
-               help='id of machine flavor used for nodes'),
82
+               help='id of machine flavor used for nodes (3=medium)'),
96 83
     cfg.IntOpt('gateway_flavor',
97 84
                default=1,
98
-               help='id of machine flavor used for gateway'),
85
+               help='id of machine flavor used to construct GW (1=tiny)'),
99 86
     cfg.StrOpt('key_name',
100
-               default='<your_key_name_here>',
101
-               help='name of key for node access via ssh'),
87
+               default='shared',
88
+               help='name of public key for node access via ssh'),
102 89
     cfg.ListOpt('security_groups',
103 90
                 default=['default', 'ssh'],
104
-                help='list of security groups for nodes'),
91
+                help='list of security groups (firewall rules) for nodes'),
105 92
     cfg.StrOpt('src_dir',
106 93
                default='../bin/',
107
-               help='path of setup script source dir on client'),
94
+               help='relative source location (to __file__) of various'
95
+                    ' chef-related setup scripts on client'),
108 96
     cfg.StrOpt('dst_dir',
109 97
                default='/home/ubuntu/',
110
-               help='path of setup script destination dir on nodes'),
98
+               help='absolute destination path for chef-related setup scripts'
99
+                    ' on nodes'),
111 100
     cfg.StrOpt('userdata',
112 101
                default='userdata.sh.template',
113
-               help='template for user data script'),
102
+               help='bash script run by cloud-init in late boot stage'
103
+                    ' (rc.local-like)'),
114 104
     cfg.IntOpt('timeout',
115 105
                default=999999,
116
-               help='number of seconds for creation timeout'),
106
+               help='maximum time (in seconds) to wait for all nodes to be'
107
+                    ' ready [ssh-able + userdata]'),
117 108
     cfg.IntOpt('poll_interval',
118 109
                default=5,
119 110
                help='interval (in seconds) between readiness polls'),
120 111
 ]
121 112
 
122
-# Register options
123
-CONF.register_cli_opts(inception_opts)
113
+cmd_opts = [
114
+    cfg.BoolOpt('shell',
115
+                default=False,
116
+                help='initialize, then drop to embedded IPython shell'),
117
+    cfg.BoolOpt('cleanup',
118
+                default=False,
119
+                help='take down the inception cloud'),
120
+]
121
+
122
+CONF = cfg.CONF
123
+CONF.register_cli_opts(orchestrator_opts)
124
+CONF.register_cli_opts(cmd_opts)
124 125
 
125 126
 
126 127
 class Orchestrator(object):
@@ -131,46 +132,25 @@ class Orchestrator(object):
131 132
     def __init__(self,
132 133
                  prefix,
133 134
                  num_workers,
135
+                 atomic,
136
+                 parallel,
134 137
                  chef_repo,
135 138
                  chef_repo_branch,
136
-                 parallel,
137
-                 ssh_keyfile=None,
138
-                 pool='research',
139
-                 user='ubuntu',
140
-                 image='f3d62d5b-a76b-4997-a579-ff946a606132',
141
-                 flavor=3,
142
-                 gateway_flavor=1,
143
-                 key_name='<your_key_name_here>',
144
-                 security_groups=('default', 'ssh'),
145
-                 src_dir='../bin/',
146
-                 dst_dir='/home/ubuntu/',
147
-                 userdata='userdata.sh.template',
148
-                 timeout=999999,
149
-                 poll_interval=5):
150
-        """
151
-        @param prefix: unique name as prefix
152
-        @param num_workers: how many worker nodes you'd like
153
-        @param chef_repo: chef repository location
154
-        @param chef_repo_branch: which branch to use in repo
155
-        @param parallel: whether run functions in parallel (via threads, for
156
-            accelerating) or sequential
157
-        @param ssh_keyfile: extra ssh public key to login user account
158
-        @param pool: floating ip pool
159
-        @param user: username (with root permission) for all servers
160
-        @param image: default u1204-130531-gv
161
-        @param flavor: default medium
162
-        @param gateway_flavor: default tiny
163
-        @param key_name: ssh public key to be injected
164
-        @param security_groups: firewall rules
165
-        @param src_dir: location from where scripts are uploaded to servers.
166
-            Relative path to __file__
167
-        @param dst_dir: target location of scripts on servers. Must be absolte
168
-            path
169
-        @param userdata: a bash script to be executed by cloud-init (in late
170
-            booting stage, rc.local-like)
171
-        @param timeout: sleep time (s) for servers to be launched
172
-        @param poll_interval: every this time poll to check whether a server
173
-            has finished launching, i.e., ssh-able + userdata done
139
+                 ssh_keyfile,
140
+                 pool,
141
+                 user,
142
+                 image,
143
+                 flavor,
144
+                 gateway_flavor,
145
+                 key_name,
146
+                 security_groups,
147
+                 src_dir,
148
+                 dst_dir,
149
+                 userdata,
150
+                 timeout,
151
+                 poll_interval):
152
+        """
153
+        For doc on each param refer to orchestrator_opts
174 154
         """
175 155
         ## check args
176 156
         #TODO(changbl): remove the restriction of "num_workers <= 5"
@@ -183,9 +163,11 @@ class Orchestrator(object):
183 163
         ## args
184 164
         self.prefix = prefix
185 165
         self.num_workers = num_workers
166
+        self.atomic = atomic
167
+        self.parallel = parallel
186 168
         self.chef_repo = chef_repo
187 169
         self.chef_repo_branch = chef_repo_branch
188
-        self.parallel = parallel
170
+        self.ssh_keyfile = ssh_keyfile
189 171
         self.pool = pool
190 172
         self.user = user
191 173
         self.image = image
@@ -198,14 +180,14 @@ class Orchestrator(object):
198 180
         self.dst_dir = os.path.abspath(dst_dir)
199 181
         with open(os.path.join(self.src_dir, userdata), 'r') as fin:
200 182
             self.userdata = fin.read()
183
+        self.timeout = timeout
184
+        self.poll_interval = poll_interval
201 185
         # Inject the extra ssh public key if any
202 186
         ssh_keycontent = ''
203
-        if ssh_keyfile:
204
-            with open(ssh_keyfile, 'r') as fin:
187
+        if self.ssh_keyfile:
188
+            with open(self.ssh_keyfile, 'r') as fin:
205 189
                 ssh_keycontent = fin.read()
206 190
         self.userdata = self.userdata % (user, ssh_keycontent)
207
-        self.timeout = timeout
208
-        self.poll_interval = poll_interval
209 191
         # scripts to run on chefserver, execute one by one (sequence matters)
210 192
         self.chefserver_commands = []
211 193
         self.chefserver_files = OrderedDict()
@@ -243,12 +225,9 @@ class Orchestrator(object):
243 225
         self._worker_names = []
244 226
         self._gateway_floating_ip = None
245 227
 
246
-    def start(self, atomic):
228
+    def start(self):
247 229
         """
248 230
         run the whole process
249
-
250
-        @param atomic: upon exception, whether rollback, i.e., auto delete all
251
-            created servers
252 231
         """
253 232
         try:
254 233
             self._check_existence()
@@ -265,15 +244,16 @@ class Orchestrator(object):
265 244
             print "OpenStack dashboard is https://%s" % self._controller_ip
266 245
         except Exception:
267 246
             print traceback.format_exc()
268
-            if atomic:
247
+            if self.atomic:
269 248
                 self.cleanup()
270 249
 
271 250
     def _check_existence(self):
272 251
         """
273 252
         Check whether inception cloud existence based on given self.prefix
274 253
         """
254
+        full_prefix = self.prefix + '-'
275 255
         for server in self.client.servers.list():
276
-            if '-' in server.name and server.name.split('-')[0] == self.prefix:
256
+            if server.name.startswith(full_prefix):
277 257
                 raise ValueError('prefix=%s is already used' % self.prefix)
278 258
 
279 259
     def _create_servers(self):
@@ -589,19 +569,19 @@ def main():
589 569
     """
590 570
     program starting point
591 571
     """
592
-
593
-    # Processes both config file and cmd line opts
572
+    # processes args
594 573
     try:
595 574
         CONF(args=sys.argv[1:], version="Inception: version %s" % __version__)
596
-    except Exception, e:
575
+    except Exception as e:
597 576
         print e
598
-        sys.exit(-2)
599
-
577
+        sys.exit(1)
578
+    # start orchestator
600 579
     orchestrator = Orchestrator(CONF.prefix,
601 580
                                 CONF.num_workers,
581
+                                CONF.atomic,
582
+                                CONF.parallel,
602 583
                                 CONF.chef_repo,
603 584
                                 CONF.chef_repo_branch,
604
-                                CONF.parallel,
605 585
                                 CONF.ssh_keyfile,
606 586
                                 CONF.pool,
607 587
                                 CONF.user,
@@ -615,7 +595,6 @@ def main():
615 595
                                 CONF.userdata,
616 596
                                 CONF.timeout,
617 597
                                 CONF.poll_interval)
618
-
619 598
     if CONF.shell:
620 599
         # give me a ipython shell
621 600
         IPython.embed()
@@ -623,7 +602,7 @@ def main():
623 602
     if CONF.cleanup:
624 603
         orchestrator.cleanup()
625 604
     else:
626
-        orchestrator.start(CONF.atomic)
605
+        orchestrator.start()
627 606
 
628 607
 ##############################################
629 608
 if __name__ == "__main__":

+ 2
- 4
setup.py View File

@@ -1,13 +1,11 @@
1
-#!/usr/bin/python
1
+#!/usr/bin/env python
2 2
 # Copyright (c) 2012 AT&T. All right reserved.
3
-#
4 3
 
5 4
 try:
6 5
     from setuptools import setup
7 6
 except ImportError:
8 7
     from distutils.core import setup
9 8
 
10
-
11 9
 # move version string out of setup so it is readily available to others
12 10
 from inception import __version__
13 11
 
@@ -17,7 +15,7 @@ setup(
17 15
     description="Inception: Towards a Nested Cloud Architecture",
18 16
     license="Apache 2.0",
19 17
     classifiers=["Programming Language :: Python"],
20
-    url='https://github.com/maoy/inception',
18
+    url='https://github.com/stackforge/inception',
21 19
     packages=["inception"],
22 20
     install_requires=[
23 21
         "oslo.config>=1.1.1",

Loading…
Cancel
Save