Skip to content

Commit a94ba86

Browse files
committed
added network_cli option
1 parent 6afe2f0 commit a94ba86

7 files changed

Lines changed: 37 additions & 14 deletions

File tree

2G-Service/ansible-config-2g/shell-definition.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ node_types:
4242
type: string
4343
tags: [ user_input ]
4444
Connection Method:
45-
description: For Linux / Windows connections
45+
description: Specifies the "ansible_connection" host variable
4646
type: string
4747
tags: [user_input]
48-
default: SSH
48+
default: ssh
4949
constraints:
50-
- valid_values: [ SSH, WinRM ]
50+
- valid_values: [ ssh, winrm, network_cli ]
5151
Script Parameters:
5252
description: (Optional) key pair values passed playbook VARS file to be accesible in script. Pass in following format - key1,val1;key2,val2.
5353
type: string

2G-Service/ansible-config-2g/src/driver.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from helper_code.resource_helpers import get_resource_attribute_gen_agostic
1212
from helper_code.parse_script_params import get_params_list_from_semicolon_sep_str
1313
from helper_code.gitlab_api_url_validator import is_base_path_gitlab_api
14+
from helper_code.validate_protocols import is_path_supported_protocol
1415
from cloudshell.core.logger.qs_logger import get_qs_logger
1516
from ansible_configuration import AnsibleConfiguration, HostConfiguration
1617

@@ -59,7 +60,7 @@ def execute_playbook(self, context, cancellation_context, playbook_path):
5960
return completed_msg
6061

6162
def _is_path_supported_protocol(self, path):
62-
return any(path.startswith(protocol) for protocol in self.supported_protocols)
63+
return is_path_supported_protocol(path, self.supported_protocols)
6364

6465
@staticmethod
6566
def _append_gitlab_url_suffix(url, branch):
@@ -256,7 +257,7 @@ def _get_ansible_config_json(self, context, api, reporter, playbook_path):
256257
if curr_password:
257258
new_obj["repositoryDetails"]["password"] = "*******"
258259
json_copy = json.dumps(new_obj, indent=4)
259-
reporter.debug_out("=== Ansible Configuration JSON ===\n{}".format(json_copy), log_only=True)
260+
reporter.info_out("=== Ansible Configuration JSON ===\n{}".format(json_copy), log_only=True)
260261

261262
return ansi_conf_json
262263

2G-Service/ansible-config-2g/src/drivermetadata.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Parameters>
77
<Parameter Name="playbook_path" Type="String"
88
DisplayName="Playbook Path"
9-
Description="Can pass the Full URL OR a shortened path that will be combined with base path attribute"
9+
Description="Can pass the Full URL OR a shortened path that will be combined with base path attribute. Will Fallback to value defined on service."
1010
Mandatory="False"/>
1111
</Parameters>
1212
</Command>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def is_path_supported_protocol(path, supported_protocols):
2+
"""
3+
:param str path:
4+
:param list [str] protocols:
5+
:return:
6+
"""
7+
path = path.lower()
8+
return any(path.startswith(protocol) for protocol in supported_protocols)
9+
10+
11+
if __name__ == "__main__":
12+
protocols = ["http", "https"]
13+
path = "httpS://www.lol.com"
14+
print(is_path_supported_protocol(path, protocols))

2G-Service/ansible-config-2g/test_requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ unittest2
44
mock
55
teamcity-messages
66
jsonpickle
7-
nose-exclude
7+
nose-exclude
8+
pytest

2G-Service/ansible-config-2g/tests/test_ansible-config-2g.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"""
55
Tests for `AnsibleConfig2GDriver`
66
"""
7+
from driver import AnsibleConfig2GDriver
78

89
import unittest
910

10-
from driver import AnsibleConfig2GDriver
11+
1112

1213

1314
class TestAnsibleConfig2GDriver(unittest.TestCase):
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
class AnsibleConnectionHelper(object):
2+
CONNECTION_METHOD_WIN_RM = 'winrm'
23
WIN_RM_SECURED_PORT = '5986'
34
WIN_RM_PORT = '5985'
4-
CONNECTION_METHOD_WIN_RM = 'winrm'
55
CONNECTION_METHOD_SSH = 'ssh'
6+
CONNECTION_METHOD_NETWORK_CLI = "network_cli"
67
SSH_PORT = '22'
8+
CONNECTION_METHOD_VM_WARE = "vmware_tools"
9+
VM_WARE_PORT = '443'
710

811
def __init__(self):
912
pass
1013

1114
def get_ansible_port(self, host):
12-
ansible_port = None
1315
if host.connection_method == self.CONNECTION_METHOD_WIN_RM:
1416
if host.connection_secured:
15-
ansible_port = self.WIN_RM_SECURED_PORT
17+
return self.WIN_RM_SECURED_PORT
1618
else:
17-
ansible_port = self.WIN_RM_PORT
19+
return self.WIN_RM_PORT
1820
if host.connection_method == self.CONNECTION_METHOD_SSH:
19-
ansible_port = self.SSH_PORT
20-
return ansible_port
21+
return self.SSH_PORT
22+
if host.connection_method == self.CONNECTION_METHOD_VM_WARE:
23+
return self.VM_WARE_PORT
24+
if host.connection_method == self.CONNECTION_METHOD_NETWORK_CLI:
25+
return self.SSH_PORT
26+

0 commit comments

Comments
 (0)