forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_packer.py
More file actions
69 lines (46 loc) · 2.19 KB
/
create_packer.py
File metadata and controls
69 lines (46 loc) · 2.19 KB
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
import os
import argparse
# Adds dev-tools/packer directory with the necessary files to a beat
def generate_packer(es_beats, abs_path, beat, beat_path, version):
# create dev-tools/packer
packer_path = abs_path + "/dev-tools/packer"
print(packer_path)
if os.path.isdir(packer_path):
print("Dev tools already exists. Stopping...")
return
# create all directories needed
os.makedirs(packer_path + "/beats")
templates = es_beats + "/libbeat/scripts/dev-tools/packer"
content = load_file(templates + "/version.yml", beat, beat_path, version)
with open(packer_path + "/version.yml", "w") as f:
f.write(content)
content = load_file(templates + "/Makefile", beat, beat_path, version)
with open(packer_path + "/Makefile", "w") as f:
f.write(content)
content = load_file(templates + "/config.yml", beat, beat_path, version)
with open(packer_path + "/beats/" + beat + ".yml", "w") as f:
f.write(content)
print("Packer directories created")
def load_file(file, beat, beat_path, version):
content = ""
with open(file) as f:
content = f.read()
return content.replace("{beat}", beat).replace("{beat_path}", beat_path).replace("{version}", version)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Creates the beats packer structure")
parser.add_argument("--beat", help="Beat name", default="test")
parser.add_argument("--beat_path", help="Beat path", default="./")
parser.add_argument("--es_beats", help="Beat path", default="../")
parser.add_argument("--version", help="Beat version", default="0.1.0")
args = parser.parse_args()
# Fetches GOPATH and current execution directory. It is expected to run this script from the Makefile.
gopath = os.environ['GOPATH'].split(os.pathsep)[0]
# Normalise go path
gopath = os.path.abspath(gopath)
abs_path = os.path.abspath("./")
# Removes the gopath + /src/ from the directory name to fetch the path
beat_path = abs_path[len(gopath) + 5:]
print(beat_path)
print(abs_path)
es_beats = os.path.abspath(args.es_beats)
generate_packer(es_beats, abs_path, args.beat, beat_path, args.version)