This commit is contained in:
Nico Schottelius 2019-12-08 14:15:36 +01:00
parent 26aeb78f61
commit 5b44034602
4 changed files with 14 additions and 22 deletions

0
bin/ucloud-run-reinstall Normal file → Executable file
View file

View file

@ -18,21 +18,16 @@ if __name__ == "__main__":
arg_parser.add_argument('component_args', nargs='*') arg_parser.add_argument('component_args', nargs='*')
args = arg_parser.parse_args() args = arg_parser.parse_args()
if args.conf_dir:
os.environ['UCLOUD_CONF_DIR'] = args.conf_dir
try: try:
name = args.component name = args.component
mod = importlib.import_module("ucloud.{}.main".format(name)) mod = importlib.import_module("ucloud.{}.main".format(name))
main = getattr(mod, "main") main = getattr(mod, "main")
if args.conf_dir:
print("setting conf")
os.environ['UCLOUD_CONF_DIR'] = args.conf_dir
main() main()
# except decouple.UndefinedValueError as e:
# print(e)
# sys.exit(1)
except Exception as e: except Exception as e:
logging.exception(e) logging.exception(e)
print(e) print(e)

View file

@ -28,7 +28,7 @@ class CreateVM(Resource):
validator = schemas.CreateVMSchema(data) validator = schemas.CreateVMSchema(data)
if validator.is_valid(): if validator.is_valid():
vm_uuid = uuid4().hex vm_uuid = uuid4().hex
vm_key = join_path(config['api']["VM_PREFIX"), vm_uuid) vm_key = join_path(config['etcd']["VM_PREFIX"], vm_uuid)
specs = { specs = {
"cpu": validator.specs["cpu"], "cpu": validator.specs["cpu"],
"ram": validator.specs["ram"], "ram": validator.specs["ram"],
@ -56,7 +56,7 @@ class CreateVM(Resource):
# Create ScheduleVM Request # Create ScheduleVM Request
r = RequestEntry.from_scratch( r = RequestEntry.from_scratch(
type=RequestType.ScheduleVM, uuid=vm_uuid, type=RequestType.ScheduleVM, uuid=vm_uuid,
request_prefix=config['api']["REQUEST_PREFIX") request_prefix=config['etcd']["REQUEST_PREFIX"]
) )
request_pool.put(r) request_pool.put(r)
@ -71,7 +71,7 @@ class VmStatus(Resource):
validator = schemas.VMStatusSchema(data) validator = schemas.VMStatusSchema(data)
if validator.is_valid(): if validator.is_valid():
vm = vm_pool.get( vm = vm_pool.get(
join_path(config['api']["VM_PREFIX"), data["uuid"]) join_path(config['etcd']["VM_PREFIX"], data["uuid"])
) )
vm_value = vm.value.copy() vm_value = vm.value.copy()
vm_value["ip"] = [] vm_value["ip"] = []
@ -79,7 +79,7 @@ class VmStatus(Resource):
network_name, mac, tap = network_mac_and_tap network_name, mac, tap = network_mac_and_tap
network = etcd_client.get( network = etcd_client.get(
join_path( join_path(
config['api']["NETWORK_PREFIX"), config['etcd']["NETWORK_PREFIX"],
data["name"], data["name"],
network_name, network_name,
), ),
@ -100,7 +100,7 @@ class CreateImage(Resource):
validator = schemas.CreateImageSchema(data) validator = schemas.CreateImageSchema(data)
if validator.is_valid(): if validator.is_valid():
file_entry = etcd_client.get( file_entry = etcd_client.get(
join_path(config['api']["FILE_PREFIX"), data["uuid"]) join_path(config['etcd']["FILE_PREFIX"], data["uuid"])
) )
file_entry_value = json.loads(file_entry.value) file_entry_value = json.loads(file_entry.value)
@ -113,7 +113,7 @@ class CreateImage(Resource):
"visibility": "public", "visibility": "public",
} }
etcd_client.put( etcd_client.put(
join_path(config['etcd']["IMAGE_PREFIX"), data["uuid"]), join_path(config['etcd']["IMAGE_PREFIX"], data["uuid"]),
json.dumps(image_entry_json), json.dumps(image_entry_json),
) )
@ -125,7 +125,7 @@ class ListPublicImages(Resource):
@staticmethod @staticmethod
def get(): def get():
images = etcd_client.get_prefix( images = etcd_client.get_prefix(
config['etcd']["IMAGE_PREFIX"), value_in_json=True config['etcd']["IMAGE_PREFIX"], value_in_json=True
) )
r = { r = {
"images": [] "images": []
@ -148,7 +148,7 @@ class VMAction(Resource):
if validator.is_valid(): if validator.is_valid():
vm_entry = vm_pool.get( vm_entry = vm_pool.get(
join_path(config['etcd']["VM_PREFIX"), data["uuid"]) join_path(config['etcd']["VM_PREFIX"], data["uuid"])
) )
action = data["action"] action = data["action"]
@ -326,7 +326,7 @@ class GetSSHKeys(Resource):
# {user_prefix}/{realm}/{name}/key/{key_name} # {user_prefix}/{realm}/{name}/key/{key_name}
etcd_key = join_path( etcd_key = join_path(
config['etcd']['USER_PREFIX'), config['etcd']['USER_PREFIX'],
data["realm"], data["realm"],
data["name"], data["name"],
"key", "key",
@ -430,9 +430,7 @@ class CreateNetwork(Resource):
prefix = nb_prefix.available_prefixes.create( prefix = nb_prefix.available_prefixes.create(
data={ data={
"prefix_length": config['network'][ "prefix_length": config['network']["PREFIX_LENGTH"],
"PREFIX_LENGTH"]
),
"description": '{}\'s network "{}"'.format( "description": '{}\'s network "{}"'.format(
data["name"], data["network_name"] data["name"], data["network_name"]
), ),

View file

@ -25,8 +25,7 @@ config_file = os.path.join(conf_dir, conf_name)
config = configparser.ConfigParser() config = configparser.ConfigParser()
try: try:
with open(config_file, "r") as conf_fd: config.read(config_file)
conf.read(conf_fd)
except FileNotFoundError: except FileNotFoundError:
log.warn("Configuration file not found - using defaults") log.warn("Configuration file not found - using defaults")