Skip to content

Commit

Permalink
Merge pull request #41 from nutanix/fix-python-version
Browse files Browse the repository at this point in the history
solve python 2.7 issues
  • Loading branch information
alaa-bish authored Jan 26, 2022
2 parents a628478 + 875aae4 commit 2eba51f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions plugins/module_utils/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ def send_request(module, method, req_url, req_data, username, password, timeout=
module.fail_json(
msg="Fail: "
+ "Status: "
+ f'{str(info["msg"])}'
+ "{0}".format(str(info["msg"]))
+ ", Message: "
+ f'{str(info.get("body"))}'
+ "{0}".format(str(info.get("body")))
)

body = resp.read() if resp else info.get("body")
Expand Down Expand Up @@ -201,7 +201,7 @@ def generate_url_from_operations(self, name, netloc=None, ops=None):
elif type(each) is dict:
key = list(each.keys())[0]
val = each[key]
path += f"/{key}/{val}"
path += "/{0}/{1}".format(key, val)
url += path
return self.validate_url(url, netloc, path)

Expand Down Expand Up @@ -239,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, "rb") as f:
# spec = json.loads(str(f.read()))
spec = yaml.safe_load(f.read())
return spec
Expand Down
10 changes: 5 additions & 5 deletions plugins/module_utils/prism/vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_attr_spec(self, param, param_spec, **kwargs):

def get_entity_by_name(self, name="", kind=""):
url = self.generate_url_from_operations(kind, netloc=self.url, ops=["list"])
data = {"filter": f"name=={name}", "length": 1}
data = {"filter": "name=={0}".format(name), "length": 1}
resp = self.send_request(
self.module,
self.methods_of_actions["list"],
Expand All @@ -44,7 +44,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"] = "Entity with name {0} does not exist.".format(name)
self.result["failed"] = True

self.module.exit_json(**self.result)
Expand All @@ -53,12 +53,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}"
"Get Default Spec helper not implemented for {0}".format(self.entity_type)
)

def _get_api_spec(self, param_spec, **kwargs):
raise NotImplementedError(
f"Get Api Spec helper not implemented for {self.entity_type}"
"Get Api Spec helper not implemented for {0}".format(self.entity_type)
)

def remove_null_references(self, spec, parent_spec=None, spec_key=None):
Expand Down Expand Up @@ -246,7 +246,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, "rb", encoding="utf_8") as f:
with open(script_file_path, "rb") as f:
content = f.read()
content = b64encode(content)
type = param_spec["type"]
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/plugins/module_utils/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def test_generate_url(self):
elif isinstance(each, dict):
key = list(each.keys())[0]
val = each[key]
path += f"/{key}/{val}"
path += "/{0}/{1}".format(key, val)
self.assertTrue("http" in actual.scheme)
self.assertEqual(netloc, actual.netloc)
self.assertEqual(path, actual.path)
Expand Down

0 comments on commit 2eba51f

Please sign in to comment.