-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.py
109 lines (91 loc) · 2.58 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import os
import pathlib
import subprocess
from setuptools import setup
from shutil import which
POOLNAME = 'jumbo-storage'
POOLDIR = '/var/lib/libvirt/images/%s' % POOLNAME
def list_package_data(package_dir, data_dirs):
"""Return the list of all the data subdirectories for a package
:param package_dir: The directory of the package
:type package_dir: str
:param data_dirs: The list of the top level data directories of the package
:type data_dirs: list<str>
:rtype: list<str>
"""
data = []
for d in data_dirs:
for dir_name, _, _ in os.walk(package_dir + '/' + d):
data.append('%s/*' % dir_name.split(package_dir + '/')[1])
return data
def create_storage_pool():
"""Create a storage pool jumbo-storage to provision clusters using libvirt
"""
if which('virsh'):
if not os.path.isdir(POOLDIR):
pathlib.Path(POOLDIR).mkdir()
pool_test = subprocess.Popen([
'sudo',
'virsh',
'pool-info',
POOLNAME
])
# If the storage pool doesn't exist
if not pool_test.poll():
res = subprocess.Popen([
'sudo',
'virsh',
'pool-define-as',
'--target', POOLDIR,
'--name', POOLNAME,
'--type', 'dir'
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
for line in res.stdout:
print(line.decode('utf-8').rstrip())
res = subprocess.Popen([
'sudo',
'virsh',
'pool-autostart',
POOLNAME
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
res = subprocess.Popen([
'sudo',
'virsh',
'pool-start',
POOLNAME
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
setup(
name='Jumbo',
version='0.4.3',
install_requires=[
'Click',
'click-shell',
'jinja2',
'prettytable',
'pyyaml',
'ipaddress'
],
packages=[
'jumbo.cli',
'jumbo.core',
'jumbo.utils'
],
package_data={
'jumbo.core': list_package_data('jumbo/core', ['data', 'config']),
'jumbo.utils': list_package_data('jumbo/utils', ['templates'])
},
entry_points='''
[console_scripts]
jumbo=jumbo.cli.main:jumbo
'''
)
create_storage_pool()