Skip to content

Commit

Permalink
Black Test Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alaa-bish committed Jan 23, 2022
1 parent 6ea993b commit 7059afd
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 46 deletions.
Empty file modified nutanix/ncp/plugins/README.md
100644 → 100755
Empty file.
Empty file modified nutanix/ncp/plugins/module_utils/base_module.py
100644 → 100755
Empty file.
20 changes: 9 additions & 11 deletions nutanix/ncp/plugins/module_utils/entity.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ def check_response(self):
self.result["task_information"] = task

self.result["changed"] = True
status = self.response.get(
"state") or self.response.get("status").get("state")
status = self.response.get("state") or self.response.get("status").get("state")
if status and status.lower() != "succeeded" or self.action == "list":
self.result["changed"] = False
if status.lower() != "complete":
Expand Down Expand Up @@ -157,10 +156,11 @@ def send_request(module, method, req_url, req_data, username, password, timeout=
)
if not 300 > info["status"] > 199:
module.fail_json(
msg="Fail: " + "Status: " +
f'{str(info["msg"])}' + ", Message: " +
f'{str(info.get("body"))}'

msg="Fail: "
+ "Status: "
+ f'{str(info["msg"])}'
+ ", Message: "
+ f'{str(info.get("body"))}'
)

body = resp.read() if resp else info.get("body")
Expand Down Expand Up @@ -220,8 +220,7 @@ def validate_url(url, netloc, path=""):

def get_action(self):
if self.action == "present":
self.action = "update" if self.data["metadata"].get(
"uuid") else "create"
self.action = "update" if self.data["metadata"].get("uuid") else "create"
elif self.action == "absent":
self.action = self.methods_of_actions[self.action]
elif self.action not in self.methods_of_actions.keys():
Expand All @@ -240,7 +239,7 @@ def get_spec(self):
)

file_path = join(ncp_dir, self.spec_file)
with open(file_path, encoding='utf_8') as f:
with open(file_path, encoding="utf_8") as f:
# spec = json.loads(str(f.read()))
spec = yaml.safe_load(f.read())
return spec
Expand Down Expand Up @@ -325,8 +324,7 @@ def run_module(self, module):

if not self.url:
self.url = (
str(self.auth.get("ip_address")) +
":" + str(self.auth.get("port"))
str(self.auth.get("ip_address")) + ":" + str(self.auth.get("port"))
)

self.netloc = self.url
Expand Down
Empty file modified nutanix/ncp/plugins/module_utils/prism/images.py
100644 → 100755
Empty file.
Empty file modified nutanix/ncp/plugins/module_utils/prism/prism.py
100644 → 100755
Empty file.
Empty file modified nutanix/ncp/plugins/module_utils/prism/subnets.py
100644 → 100755
Empty file.
18 changes: 5 additions & 13 deletions nutanix/ncp/plugins/module_utils/prism/vms.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def _get_api_spec(self, param_spec, **kwargs):
pass

def get_entity_by_name(self, name="", kind=""):
url = self.generate_url_from_operations(
kind, netloc=self.url, ops=["list"])
url = self.generate_url_from_operations(kind, netloc=self.url, ops=["list"])
data = {"filter": f"name=={name}", "length": 1}
resp = self.send_request(
self.module,
Expand All @@ -48,7 +47,7 @@ def get_entity_by_name(self, name="", kind=""):

except IndexError:

self.result["message"] = f'Entity with name {name} does not exist.'
self.result["message"] = f"Entity with name {name} does not exist."
self.result["failed"] = True

self.module.exit_json(**self.result)
Expand All @@ -57,17 +56,12 @@ def get_entity_by_name(self, name="", kind=""):
class VMSpec:
def get_default_spec(self):
raise NotImplementedError(

f"Get Default Spec helper not implemented for {self.entity_type}"


)

def _get_api_spec(self, param_spec, **kwargs):
raise NotImplementedError(

f"Get Api Spec helper not implemented for {self.entity_type}"

)

def remove_null_references(self, spec, parent_spec=None, spec_key=None):
Expand Down Expand Up @@ -216,11 +210,9 @@ def _get_api_spec(self, param_spec, **kwargs):
# nic_final['subnet_reference'][k.split('_')[-1]] = v

elif k == "subnet_uuid" and v:
nic_final["subnet_reference"] = {
"kind": "subnet", "uuid": v}
nic_final["subnet_reference"] = {"kind": "subnet", "uuid": v}
elif k == "subnet_name" and not nic_param.get("subnet_uuid"):
nic_final["subnet_reference"] = self.__get_subnet_ref(
v, **kwargs)
nic_final["subnet_reference"] = self.__get_subnet_ref(v, **kwargs)

elif k == "ip_endpoint_list" and bool(v):
nic_final[k] = [{"ip": v[0]}]
Expand Down Expand Up @@ -257,7 +249,7 @@ def _get_api_spec(self, param_spec, **kwargs):

gc_spec = self.get_default_spec()
script_file_path = param_spec["script_path"]
with open(script_file_path, "r", encoding='utf_8') as f:
with open(script_file_path, "r", encoding="utf_8") as f:
content = f.read()
content = b64encode(content)
type = param_spec["type"]
Expand Down
14 changes: 7 additions & 7 deletions nutanix/ncp/plugins/modules/nutanix_images.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__metaclass__ = type


DOCUMENTATION = r'''
DOCUMENTATION = r"""
---
module: nutanix_images
Expand Down Expand Up @@ -54,9 +54,9 @@
author:
- Gevorg Khachatryan (@gevorg_khachatryan)
'''
"""

EXAMPLES = r'''
EXAMPLES = r"""
#CREATE action, request to /images
- hosts: [hosts_group]
Expand Down Expand Up @@ -121,9 +121,9 @@
data:
metadata:
uuid: string
'''
"""

RETURN = r'''
RETURN = r"""
CREATE:
description: CREATE /images Response for nutanix imagese
returned: (for CREATE /images operation)
Expand Down Expand Up @@ -154,7 +154,7 @@
- default Internal Error
- 404 Invalid UUID provided
- 202 Request Accepted
'''
"""
from ..module_utils.base_module import BaseModule
from ..module_utils.prism.images import Image

Expand All @@ -168,5 +168,5 @@ def main():
run_module()


if __name__ == '__main__':
if __name__ == "__main__":
main()
15 changes: 8 additions & 7 deletions nutanix/ncp/plugins/modules/nutanix_subnets.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__metaclass__ = type


DOCUMENTATION = r'''
DOCUMENTATION = r"""
---
module: nutanix_subnets
Expand Down Expand Up @@ -54,9 +54,9 @@
author:
- Gevorg Khachatryan (@gevorg_khachatryan-97)
'''
"""

EXAMPLES = r'''
EXAMPLES = r"""
#CREATE action, request to /subnets
- hosts: [hosts_group]
Expand Down Expand Up @@ -105,9 +105,9 @@
metadata:
uuid: string
'''
"""

RETURN = r'''
RETURN = r"""
CREATE:
description: CREATE /subnets Response for nutanix subnets
returned: (for CREATE /subnets operation)
Expand Down Expand Up @@ -138,10 +138,11 @@
- default Internal Error
- 404 Invalid UUID provided
- 202 Request Accepted
'''
"""
from ..module_utils.base_module import BaseModule
from ..module_utils.prism.subnets import Subnet


def run_module():
module = BaseModule()
Subnet(module)
Expand All @@ -151,5 +152,5 @@ def main():
run_module()


if __name__ == '__main__':
if __name__ == "__main__":
main()
11 changes: 3 additions & 8 deletions nutanix/ncp/plugins/modules/nutanix_vms.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,7 @@ def run_module():
type="str", required=False, aliases=["desc", "description"]
),
metadata__uuid=dict(type="str", aliases=["uuid"], required=False),
spec__resources__num_sockets=dict(
type="int", default=1, aliases=["vcpus"]
),

spec__resources__num_sockets=dict(type="int", default=1, aliases=["vcpus"]),
spec__resources__num_vcpus_per_socket=dict(
type="int",
default=1,
Expand Down Expand Up @@ -346,8 +343,7 @@ def run_module():
aliases=["storage_container"],
options=dict(
storage_container_name=dict(type="str"),
storage_container_uuid=dict(
type="str", aliases=["uuid"]),
storage_container_uuid=dict(type="str", aliases=["uuid"]),
),
),
),
Expand All @@ -371,8 +367,7 @@ def run_module():
spec__resources__memory_size_mib=dict(
type="int", default=1, aliases=["memory_size_mib", "memory_gb"]
),
metadata__categories_mapping=dict(
type="dict", aliases=["categories"]),
metadata__categories_mapping=dict(type="dict", aliases=["categories"]),
metadata__use_categories_mapping=dict(
type="bool", aliases=["use_categories_mapping"], default=False
),
Expand Down

0 comments on commit 7059afd

Please sign in to comment.