mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 02:05:41 +01:00
Enable cfg migration from v1.8.0 (#7751)
Signed-off-by: Daniel Jiang <jiangd@vmware.com>
This commit is contained in:
parent
bae6f17ad3
commit
64b16c8915
@ -21,7 +21,7 @@ def main():
|
||||
args = parser.parse_args()
|
||||
if args.target_version is not None:
|
||||
target_version = args.target_version
|
||||
input_version = utils.get_conf_version(args.input_path)
|
||||
input_version = utils.get_conf_version(args.input_path)
|
||||
curr_dir = os.path.dirname(__file__)
|
||||
if input_version == target_version:
|
||||
print ("Version of input harbor.cfg is identical to target %s, no need to upgrade" % input_version)
|
||||
|
@ -2,7 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import yaml
|
||||
from string import Template
|
||||
|
||||
if sys.version_info[:3][0] == 2:
|
||||
@ -14,16 +14,24 @@ if sys.version_info[:3][0] == 3:
|
||||
import io as StringIO
|
||||
|
||||
def read_conf(path):
|
||||
temp_section = "configuration"
|
||||
conf = StringIO.StringIO()
|
||||
conf.write("[%s]\n" % temp_section)
|
||||
conf.write(open(path).read())
|
||||
conf.seek(0, os.SEEK_SET)
|
||||
rcp = ConfigParser.RawConfigParser()
|
||||
rcp.readfp(conf)
|
||||
d = {}
|
||||
for op in rcp.options(temp_section):
|
||||
d[op] = rcp.get(temp_section, op)
|
||||
with open(path) as f:
|
||||
try:
|
||||
d = yaml.safe_load(f)
|
||||
except yaml.error.YAMLError:
|
||||
f.seek(0)
|
||||
temp_section = "configuration"
|
||||
conf = StringIO.StringIO()
|
||||
conf.write("[%s]\n" % temp_section)
|
||||
conf.write(f.read())
|
||||
conf.seek(0, os.SEEK_SET)
|
||||
rcp = ConfigParser.RawConfigParser()
|
||||
rcp.readfp(conf)
|
||||
d = {}
|
||||
for op in rcp.options(temp_section):
|
||||
d[op] = rcp.get(temp_section, op)
|
||||
else:
|
||||
if "_version" not in d:
|
||||
raise Exception("Bad format configuration file: %s" % path)
|
||||
return d
|
||||
|
||||
def get_conf_version(path):
|
||||
|
@ -16,28 +16,14 @@ RC_UP = 102
|
||||
RC_DOWN = 103
|
||||
RC_BACKUP = 104
|
||||
RC_RESTORE = 105
|
||||
RC_UNNKNOW_TYPE = 106
|
||||
RC_UNKNOWN_TYPE = 106
|
||||
RC_GEN = 110
|
||||
|
||||
class DBMigrator():
|
||||
|
||||
def __init__(self, target):
|
||||
path = "/harbor-migration/harbor-cfg/harbor.cfg"
|
||||
env = ""
|
||||
if os.path.exists(path):
|
||||
temp_section = "configuration"
|
||||
conf = StringIO.StringIO()
|
||||
conf.write("[%s]\n" % temp_section)
|
||||
conf.write(open(path).read())
|
||||
conf.seek(0, os.SEEK_SET)
|
||||
rcp = ConfigParser.RawConfigParser()
|
||||
rcp.readfp(conf)
|
||||
if rcp.get(temp_section, "admiral_url") != "NA":
|
||||
env = "WITH_ADMIRAL=true"
|
||||
else:
|
||||
print("harbor.cfg not found, WITH_ADMIRAL will not be set to true")
|
||||
self.target = target
|
||||
self.script = env + " ./db/run.sh"
|
||||
self.script = "./db/run.sh"
|
||||
|
||||
def backup(self):
|
||||
return run_cmd(self.script + " backup") == 0
|
||||
@ -246,7 +232,7 @@ def main():
|
||||
|
||||
else:
|
||||
print ("Unknow action type: " + str(commandline_input.action))
|
||||
sys.exit(RC_UNNKNOW_TYPE)
|
||||
sys.exit(RC_UNKNOWN_TYPE)
|
||||
except Exception as ex:
|
||||
print ("Migrator fail to execute, err: " + ex.message)
|
||||
sys.exit(RC_GEN)
|
||||
|
Loading…
Reference in New Issue
Block a user