Browse Source

Incoporate oslo.config facilities in Inception

Convert Inception code to use a configuration file and command line options as
processed by oslo.config.

+ orchestrator modified to use oslo.config for options
+ sample config file introduced
+ dependency on oslo.config added to setup.py
+ version string moved from setup.py to module init for ready access
  for --version and others

Implements: blueprint Inception Configuration Blueprint
Change-Id: I984700867d8ddf5ee1602cc4ed6608f36a38a6be
Andrew Forrest 5 years ago
parent
commit
03ed5b7e9f
4 changed files with 165 additions and 54 deletions
  1. 48
    0
      etc/inception/inception.conf
  2. 1
    0
      inception/__init__.py
  3. 111
    52
      inception/orchestrator.py
  4. 5
    2
      setup.py

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

@@ -0,0 +1,48 @@
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

+ 1
- 0
inception/__init__.py View File

@@ -0,0 +1 @@
1
+__version__ = '0.0.1'

+ 111
- 52
inception/orchestrator.py View File

@@ -38,9 +38,90 @@ import traceback
38 38
 
39 39
 import IPython
40 40
 from novaclient.v1_1.client import Client
41
+from oslo.config import cfg
41 42
 
43
+from inception import __version__
42 44
 from inception.utils import cmd
43 45
 
46
+CONF = cfg.CONF
47
+
48
+inception_opts = [
49
+    cfg.StrOpt('prefix',
50
+               default=None,
51
+               metavar='PREFIX',
52
+               required=True,
53
+               short='p',
54
+               help='(unique) prefix for node names (no hyphens allowed)'),
55
+    cfg.IntOpt('num_workers',
56
+               default=2,
57
+               metavar='NUM',
58
+               short='n',
59
+               help='number of worker nodes to create'),
60
+    cfg.BoolOpt('shell',
61
+                default=False,
62
+                help='initialize, then drop to embedded IPython shell'),
63
+    cfg.BoolOpt('atomic',
64
+                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'),
69
+    cfg.BoolOpt('parallel',
70
+                default=False,
71
+                help='execute chef-related setup tasks in parallel'),
72
+    cfg.StrOpt('chef_repo',
73
+               default='git://github.com/maoy/inception-chef-repo.git',
74
+               metavar='URL',
75
+               help='URL of Chef repo'),
76
+    cfg.StrOpt('chef_repo_branch',
77
+               default='master',
78
+               metavar='BRANCH',
79
+               help='name of branch of Chef repo to use'),
80
+    cfg.StrOpt('ssh_keyfile',
81
+               default=None,
82
+               metavar='PATH',
83
+               help='path of additional keyfile for node access via ssh'),
84
+    cfg.StrOpt('pool',
85
+               default='research',
86
+               help='name of pool for floating IP addresses'),
87
+    cfg.StrOpt('user',
88
+               default='ubuntu',
89
+               help=''),
90
+    cfg.StrOpt('image',
91
+               default='f3d62d5b-a76b-4997-a579-ff946a606132',
92
+               help=''),
93
+    cfg.IntOpt('flavor',
94
+               default=3,
95
+               help='id of machine flavor used for nodes'),
96
+    cfg.IntOpt('gateway_flavor',
97
+               default=1,
98
+               help='id of machine flavor used for gateway'),
99
+    cfg.StrOpt('key_name',
100
+               default='<your_key_name_here>',
101
+               help='name of key for node access via ssh'),
102
+    cfg.ListOpt('security_groups',
103
+                default=['default', 'ssh'],
104
+                help='list of security groups for nodes'),
105
+    cfg.StrOpt('src_dir',
106
+               default='../bin/',
107
+               help='path of setup script source dir on client'),
108
+    cfg.StrOpt('dst_dir',
109
+               default='/home/ubuntu/',
110
+               help='path of setup script destination dir on nodes'),
111
+    cfg.StrOpt('userdata',
112
+               default='userdata.sh.template',
113
+               help='template for user data script'),
114
+    cfg.IntOpt('timeout',
115
+               default=999999,
116
+               help='number of seconds for creation timeout'),
117
+    cfg.IntOpt('poll_interval',
118
+               default=5,
119
+               help='interval (in seconds) between readiness polls'),
120
+]
121
+
122
+# Register options
123
+CONF.register_cli_opts(inception_opts)
124
+
44 125
 
45 126
 class Orchestrator(object):
46 127
     """
@@ -59,7 +140,7 @@ class Orchestrator(object):
59 140
                  image='f3d62d5b-a76b-4997-a579-ff946a606132',
60 141
                  flavor=3,
61 142
                  gateway_flavor=1,
62
-                 key_name='shared',
143
+                 key_name='<your_key_name_here>',
63 144
                  security_groups=('default', 'ssh'),
64 145
                  src_dir='../bin/',
65 146
                  dst_dir='/home/ubuntu/',
@@ -508,63 +589,41 @@ def main():
508 589
     """
509 590
     program starting point
510 591
     """
511
-    # default argument values
512
-    shell = False
513
-    atomic = False
514
-    cleanup = False
515
-    chef_repo = "git://github.com/maoy/inception-chef-repo.git"
516
-    chef_repo_branch = "master"
517
-    parallel = False
518
-    ssh_keyfile = None
519
-    pool = 'research'
592
+
593
+    # Processes both config file and cmd line opts
520 594
     try:
521
-        optlist, _ = getopt.getopt(sys.argv[1:], 'p:n:',
522
-                                   ["shell", "atomic", "cleanup", "parallel",
523
-                                    "chef-repo=", "chef-repo-branch=",
524
-                                    "ssh-keyfile=", 'pool='])
525
-        optdict = dict(optlist)
526
-        prefix = optdict['-p']
527
-        num_workers = int(optdict['-n'])
528
-        if "--shell" in optdict:
529
-            shell = True
530
-        if "--atomic" in optdict:
531
-            atomic = True
532
-        if "--cleanup" in optdict:
533
-            cleanup = True
534
-        if "--chef-repo" in optdict:
535
-            chef_repo = optdict["--chef-repo"]
536
-        if "--chef-repo-branch" in optdict:
537
-            chef_repo_branch = optdict["--chef-repo-branch"]
538
-        if "--parallel" in optdict:
539
-            parallel = True
540
-        if "--ssh-keyfile" in optdict:
541
-            ssh_keyfile = optdict["--ssh-keyfile"]
542
-        if "--pool" in optdict:
543
-            pool = optdict["--pool"]
544
-    except Exception:
545
-        print traceback.format_exc()
546
-        usage()
547
-        sys.exit(1)
548
-    orchestrator = Orchestrator(prefix, num_workers, chef_repo,
549
-                                chef_repo_branch, parallel, ssh_keyfile, pool)
550
-    if shell:
595
+        CONF(args=sys.argv[1:], version="Inception: version %s" % __version__)
596
+    except Exception, e:
597
+        print e
598
+        sys.exit(-2)
599
+
600
+    orchestrator = Orchestrator(CONF.prefix,
601
+                                CONF.num_workers,
602
+                                CONF.chef_repo,
603
+                                CONF.chef_repo_branch,
604
+                                CONF.parallel,
605
+                                CONF.ssh_keyfile,
606
+                                CONF.pool,
607
+                                CONF.user,
608
+                                CONF.image,
609
+                                CONF.flavor,
610
+                                CONF.gateway_flavor,
611
+                                CONF.key_name,
612
+                                CONF.security_groups,
613
+                                CONF.src_dir,
614
+                                CONF.dst_dir,
615
+                                CONF.userdata,
616
+                                CONF.timeout,
617
+                                CONF.poll_interval)
618
+
619
+    if CONF.shell:
551 620
         # give me a ipython shell
552 621
         IPython.embed()
553 622
         return
554
-    if cleanup:
623
+    if CONF.cleanup:
555 624
         orchestrator.cleanup()
556 625
     else:
557
-        orchestrator.start(atomic)
558
-
559
-
560
-def usage():
561
-    print """
562
-python %s -p <prefix> -n <num_workers> [--shell] [--atomic] [--cleanup]
563
-  [--parallel] [--chef-repo=git://github.com/maoy/inception-chef-repo.git]
564
-  [--chef-repo-branch=master] [--ssh-keyfile=/path/to/key] [--pool=nova]
565
-
566
-Note: make sure OpenStack-related environment variables are defined.
567
-""" % (__file__,)
626
+        orchestrator.start(CONF.atomic)
568 627
 
569 628
 ##############################################
570 629
 if __name__ == "__main__":

+ 5
- 2
setup.py View File

@@ -7,17 +7,20 @@ try:
7 7
 except ImportError:
8 8
     from distutils.core import setup
9 9
 
10
-version = '0.0.1'
10
+
11
+# move version string out of setup so it is readily available to others
12
+from inception import __version__
11 13
 
12 14
 setup(
13 15
     name='inception',
14
-    version=version,
16
+    version=__version__,
15 17
     description="Inception: Towards a Nested Cloud Architecture",
16 18
     license="Apache 2.0",
17 19
     classifiers=["Programming Language :: Python"],
18 20
     url='https://github.com/maoy/inception',
19 21
     packages=["inception"],
20 22
     install_requires=[
23
+        "oslo.config>=1.1.1",
21 24
         "python-novaclient>=2.13.0",
22 25
         "IPython>=0.13.2",
23 26
     ],

Loading…
Cancel
Save