~bcsaller/charms/trusty/cloudfoundry/progressbar

« back to all changes in this revision

Viewing changes to cfdeploy

  • Committer: Benjamin Saller
  • Date: 2014-11-10 22:57:55 UTC
  • Revision ID: benjamin.saller@canonical.com-20141110225755-0ay7awde2om3m1by
installer with progress bar, installs cf cli if missing

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
         dict(__file__='.tox/py27/bin/activate_this.py'))
5
5
import argparse
6
6
import logging
7
 
import webbrowser
 
7
import sys
 
8
from contextlib import contextmanager
8
9
from functools import partial
9
10
 
10
11
from cloudfoundry.releases import RELEASES
17
18
                                login,
18
19
                                reconciler_endpoint,
19
20
                                webadmin_endpoint,
 
21
                                sh,
20
22
                                socket_open,
21
23
                                until,
22
24
                                which
40
42
    return options
41
43
 
42
44
 
 
45
# This is done because the default webbrowser invocation will output
 
46
# on stderr and muck with the progress bar. By hiding the output
 
47
# with devnull it proceeds as expected.
 
48
show = sh.check('xdg-open')
 
49
 
 
50
 
 
51
@contextmanager
 
52
def devnull():
 
53
    _save = sys.stderr
 
54
    fp = open('/dev/null', 'w')
 
55
    sys.stderr = fp
 
56
    yield
 
57
    sys.stderr = _save
 
58
 
 
59
 
43
60
def show_reconciler():
44
 
    uri = "http://%s:8888/" % reconciler_endpoint()
45
 
    webbrowser.open_new_tab(uri)
 
61
    with devnull():
 
62
        uri = "http://%s:8888/" % reconciler_endpoint()
 
63
        show(uri)
 
64
 
 
65
 
 
66
def show_webadmin():
 
67
    with devnull():
 
68
        uri = "http://%s:8070/" % webadmin_endpoint()
 
69
        show(uri)
46
70
 
47
71
 
48
72
class ProgressBar(Bar):
56
80
        super(ProgressBar, self).next()
57
81
 
58
82
 
59
 
def show_webadmin():
60
 
    uri = "http://%s:8070/" % webadmin_endpoint()
61
 
    webbrowser.open_new_tab(uri)
62
 
 
63
83
def install_deps():
64
84
    if not which('cf'):
65
85
        from platform import machine
66
86
        if machine() is not "x86_64":
67
 
            print "Unable to install CF CLI for your architecture. Deploy will not work as expected."
 
87
            print "Unable to install CF CLI for your architecture. "
 
88
            "Deploy will not work as expected."
68
89
            return
69
 
        sh.wget('http://go-cli.s3-website-us-east-1.amazonaws.com/releases/latest/cf-cli_amd64.deb')
 
90
        sh.wget('http://go-cli.s3-website-us-east-1.amazonaws.com/'
 
91
                'releases/latest/cf-cli_amd64.deb')
70
92
        print "Installing CF CLI (this requires sudo access)"
71
93
        sh.sudo('dpkg', '-i', 'cf-cli_amd64.deb')
72
94
 
76
98
    logging.basicConfig(level=options.log_level)
77
99
    install_deps()
78
100
 
79
 
    bar = ProgressBar('Deploying CloudFoundry', max=8)
 
101
    bar = ProgressBar('Deploying CloudFoundry', max=10)
80
102
    bar.next(message='Bootstrapping')
81
103
    bootstrap()
82
104
    until(juju_state_server, bar=bar, message="Waiting for State Server")
93
115
    until(endpoint, bar=bar, message='Waiting for CloudFoundry API endpoint')
94
116
    until(partial(login, options.admin_password),
95
117
          bar=bar, message='Waiting to login to CloudFoundry (long)')
96
 
    until(lambda: socket_open(webadmin_endpoint(), 8070))
 
118
    until(lambda: socket_open(webadmin_endpoint(), 8070),
 
119
          bar=bar, message="Waiting on webadmin. ")
97
120
    bar.next(message="Opening Admin Console")
98
121
    show_webadmin()
99
122
    bar.finish()
100
 
    print "You should now be logged into a running CF deployment"
 
123
 
 
124
    print "You should now be logged into a running CF deployment."
 
125
    if which('cf'):
 
126
        print "The 'cf' command line client is installed and available."
 
127
 
101
128
 
102
129
if __name__ == "__main__":
103
130
    main()