github.com/annchain/OG@v0.0.9/scripts/persistent/pvreset.py (about) 1 import io 2 import os 3 import yaml 4 5 # hosts = { 6 # 'izuf63aqm171s25itl5egkz': {'v1': 200, 'v2': 100, 'v3': 100, 'v4': 100}, 7 # 'izuf63aqm171s25itl5egjz': {'v1': 40, 'v2': 20, 'v3': 20}, 8 # 'izuf6a8si7x4swoav7odv5z': {'v1': 40, 'v2': 20, 'v3': 20}, 9 # 'izuf6a8si7x4swoav7odv6z': {'v1': 40, 'v2': 20, 'v3': 20}, 10 # 'izuf6a8si7x4swoav7odv7z': {'v1': 40, 'v2': 20, 'v3': 20}, 11 # 'izuf6a8si7x4swoav7odv8z': {'v1': 40, 'v2': 20, 'v3': 20}, 12 # } 13 # 14 # host_ip = { 15 # 'izuf63aqm171s25itl5egkz': '172.28.152.101', 16 # 'izuf63aqm171s25itl5egjz': '172.28.152.102', 17 # 'izuf6a8si7x4swoav7odv5z': '172.28.152.104',# 103 18 # 'izuf6a8si7x4swoav7odv6z': '172.28.152.105',# 104 19 # 'izuf6a8si7x4swoav7odv7z': '172.28.152.103',# 105 20 # 'izuf6a8si7x4swoav7odv8z': '172.28.152.106', 21 # } 22 23 storage_class = 'huge' 24 # storage_class = 'local-storage' 25 prefix = 'huge' 26 27 hosts = { 28 'izuf63aqm171s25itl5egkz': {prefix + '1': 50, prefix + '2': 50}, 29 # 'izuf63aqm171s25itl5egjz': {prefix + '1': 5, prefix + '2': 5}, 30 # 'izuf6a8si7x4swoav7odv5z': {prefix + '1': 5, prefix + '2': 5}, 31 # 'izuf6a8si7x4swoav7odv6z': {prefix + '1': 5, prefix + '2': 5}, 32 # 'izuf6a8si7x4swoav7odv7z': {prefix + '1': 5, prefix + '2': 5}, 33 # 'izuf6a8si7x4swoav7odv8z': {prefix + '1': 5, prefix + '2': 5}, 34 } 35 36 host_ip = { 37 'izuf63aqm171s25itl5egkz': '172.28.152.101', 38 'izuf63aqm171s25itl5egjz': '172.28.152.102', 39 'izuf6a8si7x4swoav7odv5z': '172.28.152.104', # 103 40 'izuf6a8si7x4swoav7odv6z': '172.28.152.105', # 104 41 'izuf6a8si7x4swoav7odv7z': '172.28.152.103', # 105 42 'izuf6a8si7x4swoav7odv8z': '172.28.152.106', 43 } 44 45 46 def reg(host, folder, size, storage_class): 47 with open("sample.yaml", 'r') as stream: 48 try: 49 d = yaml.safe_load(stream) 50 d['metadata']['name'] = host_ip[host][-3:] + '-' + folder 51 d['spec']['capacity']['storage'] = '%dGi' % size 52 d['spec']['local']['path'] = '/alidata1/nfs/' + folder 53 d['spec']['nodeAffinity']['required']['nodeSelectorTerms'][0]['matchExpressions'][0]['values'][0] = host 54 55 if storage_class is None: 56 del d['spec']['storageClassName'] 57 else: 58 d['spec']['storageClassName'] = storage_class 59 60 with io.open('output.yaml', 'w', encoding='utf8') as outfile: 61 yaml.dump(d, outfile, default_flow_style=False, allow_unicode=True) 62 os.system('kubectl create -f output.yaml') 63 except yaml.YAMLError as exc: 64 print(exc) 65 66 67 if __name__ == '__main__': 68 # remove all volumes 69 # os.system('kubectl delete pv --all') 70 71 for host, value in hosts.items(): 72 for folder, size in value.items(): 73 reg(host, folder, size, storage_class)