Skip to content

Commit

Permalink
Run pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ogajduse committed Oct 11, 2023
1 parent 12cd73a commit 82bd26f
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 29 deletions.
1 change: 0 additions & 1 deletion tests/test_vm_and_template_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def test_vm(provider_crud, test_template):


def test_sanity(provider_crud, test_template, test_vm):

template = test_template
vm = test_vm
mgmt = provider_crud.mgmt
Expand Down
1 change: 0 additions & 1 deletion wrapanapi/systems/container/rhopenshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def drop_item(struct, key):

@reconnect(unauthenticated_error_handler)
class Openshift(System):

_stats_available = {
"num_container": lambda self: len(self.list_container()),
"num_pod": lambda self: len(self.list_pods()),
Expand Down
2 changes: 1 addition & 1 deletion wrapanapi/systems/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ def delete_images(self, image_list=None):
image_list (list): ["imageID_1", "imageID_2"]
"""
for image in image_list:
img = EC2Image(system=self, raw=self.ec2_resource.Image(image)).delete()
EC2Image(system=self, raw=self.ec2_resource.Image(image)).delete()

def find_templates(
self,
Expand Down
2 changes: 1 addition & 1 deletion wrapanapi/systems/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ def _list_templates(
projects.extend(IMAGE_PROJECTS)
for project in projects:
results.extend(
GoogleCloudImage(system=self, raw=image, project=project, name=image['name'])
GoogleCloudImage(system=self, raw=image, project=project, name=image["name"])
for image in images.list(
project=project,
filter=filter_expr,
Expand Down
4 changes: 2 additions & 2 deletions wrapanapi/systems/hawkular.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ def _get_inventory(self, hostname, port, protocol):
return cls(**kwargs)

def _metrics_older(self, metrics_version):
metrics_version = metrics_version.rstrip('.Final')
status_version = self.metric._get("status")['Implementation-Version'].rstrip('.Final')
metrics_version = metrics_version.rstrip(".Final")
status_version = self.metric._get("status")["Implementation-Version"].rstrip(".Final")
return version.parse(status_version) > version.parse(metrics_version)

def info(self):
Expand Down
80 changes: 60 additions & 20 deletions wrapanapi/systems/msazure.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def refresh(self):
"""
try:
vm = self._api.get(
resource_group_name=self._resource_group, vm_name=self._name, expand="instanceView"
resource_group_name=self._resource_group,
vm_name=self._name,
expand="instanceView",
)
except CloudError as e:
if e.response.status_code == 404:
Expand Down Expand Up @@ -164,7 +166,10 @@ def ip(self):
pub_ip_id = ip_config_obj.public_ip_address.id
except AttributeError:
self.logger.error(
"VM '%s' doesn't have public IP on %s:%s", self.name, if_name, ip_config_name
"VM '%s' doesn't have public IP on %s:%s",
self.name,
if_name,
ip_config_name,
)
return None

Expand Down Expand Up @@ -278,7 +283,9 @@ def capture(self, container, image_name, overwrite_vhds=True):
self._wait_on_operation(operation)
self.logger.info("Capturing VM '%s'", self.name)
operation = self._api.capture(
resource_group_name=self._resource_group, vm_name=self.name, parameters=params
resource_group_name=self._resource_group,
vm_name=self.name,
parameters=params,
)
return self._wait_on_operation(operation)

Expand Down Expand Up @@ -364,14 +371,19 @@ def deploy(self, vm_name, **vm_settings):
vm_size = vm_settings["vm_size"]
if vm_size not in vm_sizes:
raise ValueError(
"wrong vm size %s passed. possible size: %s", vm_size, ",".join(vm_sizes)
"wrong vm size %s passed. possible size: %s",
vm_size,
",".join(vm_sizes),
)

storage_container = vm_settings["storage_container"]
# nsg_name = vm_settings['network_nsg'] # todo: check whether nsg is necessary at all

# allocating public ip address for new vm
public_ip_params = {"location": location, "public_ip_allocation_method": "Dynamic"}
public_ip_params = {
"location": location,
"public_ip_allocation_method": "Dynamic",
}
public_ip = self.system.network_client.public_ip_addresses.create_or_update(
resource_group_name=resource_group,
public_ip_address_name=vm_name,
Expand Down Expand Up @@ -412,7 +424,11 @@ def deploy(self, vm_name, **vm_settings):
nic_params = {
"location": location,
"ip_configurations": [
{"name": vm_name, "public_ip_address": public_ip, "subnet": {"id": vsubnet.id}}
{
"name": vm_name,
"public_ip_address": public_ip,
"subnet": {"id": vsubnet.id},
}
],
}

Expand All @@ -432,7 +448,11 @@ def _create_or_update_nic():
# preparing os disk
# todo: replace with copy disk operation
self.system.copy_blob_image(
self.name, vm_name, vm_settings["storage_account"], self._container, storage_container
self.name,
vm_name,
vm_settings["storage_account"],
self._container,
storage_container,
)
image_uri = self.system.container_client.make_blob_url(
container_name=storage_container, blob_name=vm_name
Expand All @@ -452,10 +472,15 @@ def _create_or_update_nic():
"network_profile": {"network_interfaces": [{"id": nic.id}]},
}
vm = self.system.compute_client.virtual_machines.create_or_update(
resource_group_name=resource_group, vm_name=vm_name, parameters=vm_parameters
resource_group_name=resource_group,
vm_name=vm_name,
parameters=vm_parameters,
).result()
vm = AzureInstance(
system=self.system, name=vm.name, resource_group=vm_settings["resource_group"], raw=vm
system=self.system,
name=vm.name,
resource_group=vm_settings["resource_group"],
raw=vm,
)
vm.wait_for_state(VmState.RUNNING)
return vm
Expand Down Expand Up @@ -908,7 +933,8 @@ def remove_discs_by_search(self, disc_name=None, resource_group=None):
discs = self.list_free_discs(resource_group=self.resource_group)
for disc_name in discs:
operation = self.compute_client.disks.delete(
resource_group_name=resource_group or self.resource_group, disk_name=disc_name
resource_group_name=resource_group or self.resource_group,
disk_name=disc_name,
)
operation.wait()
self.logger.info('"%s" disc removed', disc_name)
Expand Down Expand Up @@ -1015,7 +1041,9 @@ def copy_blob_image(
container_name=template_container, blob_name=template
)
operation = container_client.copy_blob(
container_name=storage_container, blob_name=vm_name + ".vhd", copy_source=src_uri
container_name=storage_container,
blob_name=vm_name + ".vhd",
copy_source=src_uri,
)
wait_for(lambda: operation.status != "pending", timeout="10m", delay=15)
# copy operation obj.status->str
Expand All @@ -1030,7 +1058,9 @@ def _remove_container_blob(self, container_client, container, blob, remove_snaps
if "SnapshotsPresent" in str(e) and remove_snapshots:
self.logger.warn("Blob '%s' has snapshots present, removing them", blob.name)
container_client.delete_blob(
container_name=container.name, blob_name=blob.name, delete_snapshots="include"
container_name=container.name,
blob_name=blob.name,
delete_snapshots="include",
)
else:
raise
Expand Down Expand Up @@ -1111,7 +1141,10 @@ def find_templates(self, name=None, container=None, prefix=None, only_vhd=True):
continue
matches.append(
AzureBlobImage(
system=self, name=img_name, container=found_container_name, raw=image
system=self,
name=img_name,
container=found_container_name,
raw=image,
)
)
return matches
Expand All @@ -1131,12 +1164,16 @@ def list_compute_images_by_resource_group(self, resource_group=None, free_images
"""
Args:
resource_group (str): Name of the resource group
free_images (bool): Whether to collect image which do not have any resource(VM) linked to it
free_images (bool): Whether to collect image which do not have
any resource(VM) linked to it
"""
resource_group = resource_group or self.resource_group
image_list = list(
self.resource_client.resources.list(
filter=f"resourceType eq 'Microsoft.Compute/images' and resourceGroup eq '{resource_group}'"
filter=(
"resourceType eq 'Microsoft.Compute/images' "
f"and resourceGroup eq '{resource_group}'"
)
)
)

Expand All @@ -1151,8 +1188,7 @@ def list_compute_images_by_resource_group(self, resource_group=None, free_images
for vm_name in vm_list:
images_used_by_vm.append(
self.compute_client.virtual_machines.get(
resource_group_name=resource_group,
vm_name=vm_name
resource_group_name=resource_group, vm_name=vm_name
).storage_profile.image_reference.id
)

Expand Down Expand Up @@ -1195,7 +1231,8 @@ def delete_stack(self, stack_name, resource_group=None):
self.logger.info("Removes a Deployment Stack resource created with Orchestration")
deps = self.resource_client.deployments
operation = deps.delete(
resource_group_name=resource_group or self.resource_group, deployment_name=stack_name
resource_group_name=resource_group or self.resource_group,
deployment_name=stack_name,
)
operation.wait()
self.logger.info(
Expand Down Expand Up @@ -1230,7 +1267,9 @@ def delete_compute_image_by_resource_group(self, resource_group=None, image_list
resource_group = resource_group or self.resource_group
for image in image_list:
self.logger.info("Deleting '%s' from '%s'", image, resource_group)
response = self.compute_client.images.delete(resource_group_name=resource_group, image_name=image)
response = self.compute_client.images.delete(
resource_group_name=resource_group, image_name=image
)
result.append((image, response))
return result

Expand All @@ -1243,7 +1282,8 @@ def list_stack_resources(self, stack_name, resource_group=None):
"pips": [],
}
dep_op_list = self.resource_client.deployment_operations.list(
resource_group_name=resource_group or self.resource_group, deployment_name=stack_name
resource_group_name=resource_group or self.resource_group,
deployment_name=stack_name,
)
for dep in dep_op_list:
if dep.properties.target_resource:
Expand Down
3 changes: 1 addition & 2 deletions wrapanapi/systems/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,6 @@ def info(self):
return f"{self.api.client.service_type} {self.api.client.version}"

def _get_tenants(self):

if self.keystone_version == 3:
return self.tenant_api.list()
real_tenants = []
Expand Down Expand Up @@ -820,7 +819,7 @@ def _generic_paginator(self, f):
return lists

def list_vms(self, filter_tenants=True, all_tenants=True):
call = partial(self.api.servers.list, True, {'all_tenants': all_tenants})
call = partial(self.api.servers.list, True, {"all_tenants": all_tenants})
instances = self._generic_paginator(call)
if filter_tenants and all_tenants:
# Filter instances based on their tenant ID
Expand Down
1 change: 1 addition & 0 deletions wrapanapi/systems/openstack_infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# Note: This same mechanism may be required for keystone and cinder
# clients, but hopefully won't be.


# monkeypatch method to add retry support to openstack
def _request_timeout_handler(self, url, method, retry_count=0, **kwargs):
try:
Expand Down
1 change: 0 additions & 1 deletion wrapanapi/systems/scvmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ def _log_str(self):


class SCVirtualMachine(Vm, _LogStrMixin):

state_map = {
"Running": VmState.RUNNING,
"PowerOff": VmState.STOPPED,
Expand Down

0 comments on commit 82bd26f

Please sign in to comment.