Total Complexity | 13 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import pipes |
||
5 | class Omnibus(object): |
||
6 | OMNITRUCK = 'https://www.chef.io/chef/install.sh' |
||
7 | |||
8 | def __init__(self, options): |
||
9 | supports = ('pre_release', 'version', 'download_path') |
||
10 | self.options = {k: options[k] for k in supports} |
||
11 | |||
12 | def build_command(self, version=None, pre_release=False, |
||
13 | download_path=None): |
||
14 | command = "curl -sL %s | sudo bash" % (pipes.quote(self.OMNITRUCK)) |
||
15 | |||
16 | command_args = [] |
||
17 | |||
18 | if pre_release or version or download_path: |
||
19 | command_args += ['-s', '--'] |
||
20 | |||
21 | if pre_release: |
||
22 | command_args += ['-p'] |
||
23 | |||
24 | if version: |
||
25 | command_args += ['-v', version] |
||
26 | |||
27 | if download_path: |
||
28 | command_args += ['-v', download_path] |
||
29 | |||
30 | command_args = [pipes.quote(arg) for arg in command_args] |
||
31 | command_args = ' '.join(command_args) |
||
32 | command = command + ' ' + command_args |
||
33 | |||
34 | return command |
||
35 | |||
36 | def chef_installed(self): |
||
37 | knife = "/opt/chef/bin/knife" |
||
38 | command = "test -x %s" % (pipes.quote(knife)) |
||
39 | version = self.options['version'] |
||
40 | |||
41 | if version: |
||
42 | command += (" && %s --version | grep %s" % |
||
43 | (pipes.quote(knife), |
||
44 | pipes.quote('Chef: %s' % (version)))) |
||
45 | |||
46 | exit_code = shell.shell_out(command) |
||
47 | return exit_code == 0 |
||
48 | |||
49 | def install(self): |
||
50 | return shell.shell_out(self.build_command(**self.options)) |
||
51 |