test read-only
This commit is contained in:
commit
8364a50f4a
78
main.py
Normal file
78
main.py
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import random
|
||||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
|
||||
def write_numbers_to_file(a, b, c):
|
||||
with open(os.path.join(output_dir, "numbers.txt"), "w+") as f:
|
||||
srv_list = random.sample(range(a, b), c)
|
||||
for count, value in enumerate(srv_list):
|
||||
f.write(str(value) + '\n')
|
||||
|
||||
|
||||
def starting_osd():
|
||||
with open(os.path.join(output_dir, "numbers.txt"), "r") as f:
|
||||
for line in f:
|
||||
# print(f'systemctl start ceph-{ceph_fsid}@osd.{line.strip()}.service')
|
||||
p = subprocess.run(f'systemctl start ceph-{args.fsid}@osd.{line}', shell=True, capture_output=True)
|
||||
if p.stderr.decode():
|
||||
print(p.stderr.decode().strip())
|
||||
else:
|
||||
print(f'systemctl start ceph-{args.fsid}@osd.{line.rstrip()}.service started')
|
||||
|
||||
|
||||
def stopping_osd():
|
||||
with open(os.path.join(output_dir, "numbers.txt"), "r") as f:
|
||||
for line in f:
|
||||
# print(f'systemctl stop ceph-{ceph_fsid}@osd.{line.strip()}.service')
|
||||
p = subprocess.run(f'systemctl stop ceph-{args.fsid}@osd.{line}', shell=True, capture_output=True)
|
||||
if p.stderr.decode():
|
||||
print(p.stderr.decode().strip())
|
||||
else:
|
||||
print(f'systemctl stop ceph-{args.fsid}@osd.{line.rstrip()}.service stopped')
|
||||
|
||||
|
||||
def show_file():
|
||||
with open(os.path.join(output_dir, "numbers.txt"), "r") as f:
|
||||
for line in f:
|
||||
print(f'systemctl stop|start ceph-{args.fsid}@osd.{line.strip()}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# ceph_fsid = "7461bfe8-dc87-11ee-898a-7b25c28deba6"
|
||||
output_dir = os.getcwd()
|
||||
|
||||
parser = argparse.ArgumentParser(description="Randomly start|stop OSDs")
|
||||
parser.add_argument('--show', action='store_true', help="Just show the commands the program prepared to run up")
|
||||
parser.add_argument('--fsid', type=str, default='kek', help='FSID of a cluster', required=True)
|
||||
args = parser.parse_args()
|
||||
if args.show:
|
||||
show_file()
|
||||
sys.exit()
|
||||
|
||||
|
||||
inp = input("Create random numbers of OSD?: y\\n: ")
|
||||
if inp == "y":
|
||||
try:
|
||||
frst_inp = int(input("Enter the first border of range: "))
|
||||
scnd_inp = int(input(f" The first number of range is {frst_inp} and the second?: "))
|
||||
thrd_inp = int(input(" The numbers of samples, please: "))
|
||||
write_numbers_to_file(frst_inp, scnd_inp, thrd_inp)
|
||||
except ValueError:
|
||||
print(" Not an int!")
|
||||
sys.exit()
|
||||
elif inp == "n":
|
||||
print("Be sure that file already exists. ")
|
||||
else:
|
||||
print(" do not fuck with me. Exiting")
|
||||
sys.exit()
|
||||
|
||||
inp = input("What we gonna do? start|stop ?: ")
|
||||
if inp == "start":
|
||||
starting_osd()
|
||||
elif inp == "stop":
|
||||
stopping_osd()
|
||||
else:
|
||||
print(" Вы ввели хуйню")
|
||||
25
numbers.txt
Normal file
25
numbers.txt
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
64
|
||||
84
|
||||
105
|
||||
70
|
||||
16
|
||||
91
|
||||
38
|
||||
103
|
||||
47
|
||||
18
|
||||
56
|
||||
93
|
||||
80
|
||||
39
|
||||
36
|
||||
108
|
||||
106
|
||||
44
|
||||
14
|
||||
27
|
||||
85
|
||||
32
|
||||
8
|
||||
102
|
||||
87
|
||||
Loading…
Reference in New Issue
Block a user