Apply suggested f-string changes

This commit is contained in:
Bernhard Gally 2023-07-01 00:05:08 +02:00 committed by Megan Wilhite
parent 30354137b0
commit 725a5bdc3a

View file

@ -145,7 +145,7 @@ def _authenticate():
)
connect_data = {"username": username, "password": passwd}
full_url = "https://{}:{}/api2/json/access/ticket".format(url, port)
full_url = f"https://{url}:{port}/api2/json/access/ticket"
response = requests.post(full_url, verify=verify_ssl, data=connect_data)
response.raise_for_status()
@ -163,7 +163,7 @@ def query(conn_type, option, post_data=None):
log.debug("Not authenticated yet, doing that now..")
_authenticate()
full_url = "https://{}:{}/api2/json/{}".format(url, port, option)
full_url = f"https://{url}:{port}/api2/json/{option}"
log.debug("%s: %s (%s)", conn_type, full_url, post_data)
@ -453,9 +453,7 @@ def avail_images(call=None, location="local"):
ret = {}
for host_name, host_details in avail_locations().items():
for item in query(
"get", "nodes/{}/storage/{}/content".format(host_name, location)
):
for item in query("get", f"nodes/{host_name}/storage/{location}/content"):
ret[item["volid"]] = item
return ret
@ -562,7 +560,7 @@ def _dictionary_to_stringlist(input_dict):
setting1=value1,setting2=value2
"""
return ",".join("{}={}".format(k, input_dict[k]) for k in sorted(input_dict.keys()))
return ",".join(f"{k}={input_dict[k]}" for k in sorted(input_dict.keys()))
def _reconfigure_clone(vm_, vmid):
@ -718,7 +716,7 @@ def create(vm_):
# wait until the vm has been created so we can start it
if not wait_for_created(data["upid"], timeout=300):
return {"Error": "Unable to create {}, command timed out".format(name)}
return {"Error": f"Unable to create {name}, command timed out"}
if vm_.get("clone") is True:
_reconfigure_clone(vm_, vmid)
@ -731,7 +729,7 @@ def create(vm_):
# Wait until the VM has fully started
log.debug('Waiting for state "running" for vm %s on %s', vmid, host)
if not wait_for_state(vmid, "running"):
return {"Error": "Unable to start {}, command timed out".format(name)}
return {"Error": f"Unable to start {name}, command timed out"}
if agent_get_ip is True:
try:
@ -871,7 +869,7 @@ def _import_api():
Load this json content into global variable "api"
"""
global api
full_url = "https://{}:{}/pve-docs/api-viewer/apidoc.js".format(url, port)
full_url = f"https://{url}:{port}/pve-docs/api-viewer/apidoc.js"
returned_data = requests.get(full_url, verify=verify_ssl)
re_filter = re.compile(" (?:pveapi|apiSchema) = (.*)^;", re.DOTALL | re.MULTILINE)
@ -1105,12 +1103,12 @@ def get_vmconfig(vmid, node=None, node_type="openvz"):
if node is None:
# We need to figure out which node this VM is on.
for host_name, host_details in avail_locations().items():
for item in query("get", "nodes/{}/{}".format(host_name, node_type)):
for item in query("get", f"nodes/{host_name}/{node_type}"):
if item["vmid"] == vmid:
node = host_name
# If we reached this point, we have all the information we need
data = query("get", "nodes/{}/{}/{}/config".format(node, node_type, vmid))
data = query("get", f"nodes/{node}/{node_type}/{vmid}/config")
return data
@ -1182,7 +1180,7 @@ def destroy(name, call=None):
__utils__["cloud.fire_event"](
"event",
"destroying instance",
"salt/cloud/{}/destroying".format(name),
f"salt/cloud/{name}/destroying",
args={"name": name},
sock_dir=__opts__["sock_dir"],
transport=__opts__["transport"],
@ -1196,7 +1194,7 @@ def destroy(name, call=None):
# wait until stopped
if not wait_for_state(vmobj["vmid"], "stopped"):
return {"Error": "Unable to stop {}, command timed out".format(name)}
return {"Error": f"Unable to stop {name}, command timed out"}
# required to wait a bit here, otherwise the VM is sometimes
# still locked and destroy fails.
@ -1206,7 +1204,7 @@ def destroy(name, call=None):
__utils__["cloud.fire_event"](
"event",
"destroyed instance",
"salt/cloud/{}/destroyed".format(name),
f"salt/cloud/{name}/destroyed",
args={"name": name},
sock_dir=__opts__["sock_dir"],
transport=__opts__["transport"],
@ -1216,7 +1214,7 @@ def destroy(name, call=None):
name, _get_active_provider_name().split(":")[0], __opts__
)
return {"Destroyed": "{} was destroyed.".format(name)}
return {"Destroyed": f"{name} was destroyed."}
def set_vm_status(status, name=None, vmid=None):
@ -1305,7 +1303,7 @@ def start(name, vmid=None, call=None):
# xxx: TBD: Check here whether the status was actually changed to 'started'
return {"Started": "{} was started.".format(name)}
return {"Started": f"{name} was started."}
def stop(name, vmid=None, call=None):
@ -1327,7 +1325,7 @@ def stop(name, vmid=None, call=None):
# xxx: TBD: Check here whether the status was actually changed to 'stopped'
return {"Stopped": "{} was stopped.".format(name)}
return {"Stopped": f"{name} was stopped."}
def shutdown(name=None, vmid=None, call=None):
@ -1351,4 +1349,4 @@ def shutdown(name=None, vmid=None, call=None):
# xxx: TBD: Check here whether the status was actually changed to 'stopped'
return {"Shutdown": "{} was shutdown.".format(name)}
return {"Shutdown": f"{name} was shutdown."}