Skip to content

Commit

Permalink
Merge pull request #22 from nutanix/task/cicd-pipeline-using-github-a…
Browse files Browse the repository at this point in the history
…ctions

Cicd pipeline using GitHub actions
  • Loading branch information
saratkumar-yb authored Jan 24, 2022
2 parents 0765ecc + c72792b commit 0a5d999
Show file tree
Hide file tree
Showing 14 changed files with 478 additions and 220 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/ok-to-test-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ jobs:
ref
});
const check = checks.check_runs.filter(c => c.name === process.env.job);
console.log(check);
console.log(checks);
console.log(check.length)
if (check.length == 0) {
return "Check is not present, ignoring this step."
}
Expand All @@ -86,4 +83,4 @@ jobs:
status: 'completed',
conclusion: process.env.conclusion
});
return result;
return result;
35 changes: 19 additions & 16 deletions generate_spec.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
import json


def generate_spec(data, variable_name='', default={}):
def generate_spec(data, variable_name="", default={}):
is_list = False
if 'additionalProperties' in data.keys():
data = data['additionalProperties']
if 'items' in data.keys():
data = data['items']
if "additionalProperties" in data.keys():
data = data["additionalProperties"]
if "items" in data.keys():
data = data["items"]
is_list = True
if 'properties' in data.keys():
data = data['properties']
elif 'type' in data.keys() and data['type'] in ['string', 'integer', 'boolean']:
return '{{' + variable_name + '}}'
if "properties" in data.keys():
data = data["properties"]
elif "type" in data.keys() and data["type"] in ["string", "integer", "boolean"]:
return "{{" + variable_name + "}}"
for k, v in data.items():
data[k] = generate_spec(v, variable_name + '__' + str(k) if variable_name else str(k))
data[k] = generate_spec(
v, variable_name + "__" + str(k) if variable_name else str(k)
)
if is_list:
data.update({'list_key': variable_name})
data.update({"list_key": variable_name})
return [data]
return data


def parse_json_to_spec(json_files_dir='', spec_files_dir=''):
def parse_json_to_spec(json_files_dir="", spec_files_dir=""):
import glob
import os
print(glob.glob(json_files_dir + '*json.json'))
files = glob.glob(json_files_dir + '*json.json')

print(glob.glob(json_files_dir + "*json.json"))
files = glob.glob(json_files_dir + "*json.json")
for file in files:
file_name = spec_files_dir + os.path.splitext(file)[0]

with open(file) as f:
data = json.loads(f.read())
print('--------------------------------')
print("--------------------------------")
spec = generate_spec(data)
with open(file_name + "_spec.json", 'w') as spec_file:
with open(file_name + "_spec.json", "w") as spec_file:
spec_file.write(json.dumps(spec))
print(json.dumps(spec, indent=4))
return spec
2 changes: 1 addition & 1 deletion nutanix/ncp/plugins/module_utils/base_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BaseModule(AnsibleModule):
action=dict(type="str", required=True, aliases=["state"]),
auth=dict(type="dict", required=True),
data=dict(type="dict", required=False),
operations=dict(type="list", required=False),
operations=dict(type="list", elements="str", required=False),
wait=dict(type="bool", required=False, default=True),
wait_timeout=dict(type="int", required=False, default=300),
validate_certs=dict(type="bool", required=False, default=False),
Expand Down
16 changes: 7 additions & 9 deletions nutanix/ncp/plugins/module_utils/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +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: %s"
% (
"Status: "
+ str(info["msg"])
+ ", Message: "
+ 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 @@ -203,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 += "/{0}/{1}".format(key, val)
path += f"/{key}/{val}"
url += path
return self.validate_url(url, netloc, path)

Expand Down Expand Up @@ -241,7 +239,7 @@ def get_spec(self):
)

file_path = join(ncp_dir, self.spec_file)
with open(file_path) 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
13 changes: 8 additions & 5 deletions nutanix/ncp/plugins/module_utils/prism/vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _get_api_spec(self, 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": "name==%s" % name, "length": 1}
data = {"filter": f"name=={name}", "length": 1}
resp = self.send_request(
self.module,
self.methods_of_actions["list"],
Expand All @@ -41,24 +41,27 @@ def get_entity_by_name(self, name="", kind=""):
self.credentials["username"],
self.credentials["password"],
)

try:
return resp["entities"][0]["metadata"]

except IndexError:
self.result["message"] = 'Entity with name "%s" does not exist.' % name

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

self.module.exit_json(**self.result)


class VMSpec:
def get_default_spec(self):
raise NotImplementedError(
"Get Default Spec helper not implemented for {0}".format(self.entity_type)
f"Get Default Spec helper not implemented for {self.entity_type}"
)

def _get_api_spec(self, param_spec, **kwargs):
raise NotImplementedError(
"Get Api Spec helper not implemented for {0}".format(self.entity_type)
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 @@ -246,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") 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
40 changes: 24 additions & 16 deletions nutanix/ncp/plugins/modules/nutanix_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function

from ..module_utils.base_module import BaseModule
from ..module_utils.prism.images import Image

__metaclass__ = type


Expand All @@ -21,30 +18,39 @@
description: This module allows to perform the following tasks on /images
options:
action:
state:
description: This is the action used to indicate the type of request
aliases: ['action']
required: true
type: str
credentials:
auth:
description: Credentials needed for authenticating to the subnet
required: true
type: dict (Variable from file)
type: dict #(Variable from file)
data:
description: This acts as either the params or the body payload depending on the HTTP action
required: false
type: dict
operation:
operations:
description: This acts as the sub_url in the requested url
required: false
type: str
ip_address:
description: This acts as the ip_address of the subnet. It can be passed as a list in ansible using with_items
required: True
type: str (Variable from file)
port:
description: This acts as the port of the subnet. It can be passed as a list in ansible using with_items
required: True
type: str (Variable from file)
type: list
elements: str
wait_timeout: ###
description: This is the wait_timeout description
required: False
type: int
default: 300
wait: ###
description: This is the wait description
required: False
type: bool
default: true
validate_certs: ###
description: This is the validate_certs description
required: False
type: bool
default: False
author:
- Gevorg Khachatryan (@gevorg_khachatryan)
Expand Down Expand Up @@ -149,6 +155,8 @@
- 404 Invalid UUID provided
- 202 Request Accepted
"""
from ..module_utils.base_module import BaseModule # noqa: E402
from ..module_utils.prism.images import Image # noqa: E402


def run_module():
Expand Down
42 changes: 25 additions & 17 deletions nutanix/ncp/plugins/modules/nutanix_subnets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function

from ..module_utils.base_module import BaseModule
from ..module_utils.prism.subnets import Subnet

__metaclass__ = type


Expand All @@ -21,30 +18,39 @@
description: This module allows to perform the following tasks on /subnets
options:
action:
description: This is the HTTP action used to indicate the type of request
state:
description: This is the action used to indicate the type of request
aliases: ['action']
required: true
type: str
credentials:
auth:
description: Credentials needed for authenticating to the subnet
required: true
type: dict (Variable from file)
type: dict #(Variable from file)
data:
description: This acts as either the params or the body payload depending on the HTTP action
required: false
type: dict
operation:
operations:
description: This acts as the sub_url in the requested url
required: false
type: str
ip_address:
description: This acts as the ip_address of the subnet. It can be passed as a list in ansible using with_items
required: True
type: str (Variable from file)
port:
description: This acts as the port of the subnet. It can be passed as a list in ansible using with_items
required: True
type: str (Variable from file)
type: list
elements: str
wait_timeout: ###
description: This is the wait_timeout description
required: False
type: int
default: 300
wait: ###
description: This is the wait description
required: False
type: bool
default: true
validate_certs: ###
description: This is the validate_certs description
required: False
type: bool
default: False
author:
- Gevorg Khachatryan (@gevorg_khachatryan-97)
Expand Down Expand Up @@ -133,6 +139,8 @@
- 404 Invalid UUID provided
- 202 Request Accepted
"""
from ..module_utils.base_module import BaseModule # noqa: E402
from ..module_utils.prism.subnets import Subnet # noqa: E402


def run_module():
Expand Down
Loading

0 comments on commit 0a5d999

Please sign in to comment.