vm-tool 1.0.16__tar.gz → 1.0.19__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {vm_tool-1.0.16/vm_tool.egg-info → vm_tool-1.0.19}/PKG-INFO +61 -13
  2. {vm_tool-1.0.16 → vm_tool-1.0.19}/README.md +28 -12
  3. vm_tool-1.0.19/setup.py +68 -0
  4. {vm_tool-1.0.16 → vm_tool-1.0.19}/vm_tool/cli.py +1 -1
  5. vm_tool-1.0.19/vm_tool/runner.py +116 -0
  6. {vm_tool-1.0.16 → vm_tool-1.0.19}/vm_tool/vm_setup/docker/create_docker_service.yml +12 -2
  7. vm_tool-1.0.19/vm_tool/vm_setup/dynamic_inventory.yml +0 -0
  8. {vm_tool-1.0.16 → vm_tool-1.0.19}/vm_tool/vm_setup/setup.yml +11 -0
  9. {vm_tool-1.0.16 → vm_tool-1.0.19/vm_tool.egg-info}/PKG-INFO +61 -13
  10. {vm_tool-1.0.16 → vm_tool-1.0.19}/vm_tool.egg-info/SOURCES.txt +1 -1
  11. vm_tool-1.0.19/vm_tool.egg-info/requires.txt +10 -0
  12. vm_tool-1.0.16/setup.py +0 -37
  13. vm_tool-1.0.16/vm_tool/runner.py +0 -88
  14. vm_tool-1.0.16/vm_tool/vm_setup/cloud_inventory.yml +0 -8
  15. vm_tool-1.0.16/vm_tool.egg-info/requires.txt +0 -3
  16. {vm_tool-1.0.16 → vm_tool-1.0.19}/LICENSE +0 -0
  17. {vm_tool-1.0.16 → vm_tool-1.0.19}/MANIFEST.in +0 -0
  18. {vm_tool-1.0.16 → vm_tool-1.0.19}/setup.cfg +0 -0
  19. {vm_tool-1.0.16 → vm_tool-1.0.19}/vm_tool/__init__.py +0 -0
  20. {vm_tool-1.0.16 → vm_tool-1.0.19}/vm_tool/ssh.py +0 -0
  21. {vm_tool-1.0.16 → vm_tool-1.0.19}/vm_tool/vm_setup/docker/install_docker_and_compose.yml +0 -0
  22. {vm_tool-1.0.16 → vm_tool-1.0.19}/vm_tool/vm_setup/inventory.yml +0 -0
  23. {vm_tool-1.0.16 → vm_tool-1.0.19}/vm_tool.egg-info/dependency_links.txt +0 -0
  24. {vm_tool-1.0.16 → vm_tool-1.0.19}/vm_tool.egg-info/entry_points.txt +0 -0
  25. {vm_tool-1.0.16 → vm_tool-1.0.19}/vm_tool.egg-info/top_level.txt +0 -0
@@ -1,23 +1,55 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: vm_tool
3
- Version: 1.0.16
3
+ Version: 1.0.19
4
4
  Summary: A Comprehensive Tool for Setting Up Virtual Machines.
5
5
  Home-page: https://github.com/thesunnysinha/vm_tool
6
+ Author: Sunny Sinha
7
+ Author-email: thesunnysinha@gmail.com
6
8
  License: MIT
7
9
  Project-URL: Documentation, https://github.com/thesunnysinha/vm_tool/README.md
8
10
  Project-URL: Source, https://github.com/thesunnysinha/vm_tool
9
11
  Project-URL: Tracker, https://github.com/thesunnysinha/vm_tool/issues
12
+ Keywords: virtual machine setup ansible automation
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: System Administrators
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.6
20
+ Classifier: Programming Language :: Python :: 3.7
21
+ Classifier: Programming Language :: Python :: 3.8
22
+ Classifier: Programming Language :: Python :: 3.9
23
+ Classifier: Programming Language :: Python :: 3.10
24
+ Classifier: Programming Language :: Python :: 3.11
25
+ Classifier: Programming Language :: Python :: 3.12
26
+ Classifier: Programming Language :: Python :: 3.13
27
+ Classifier: Topic :: Software Development :: Build Tools
28
+ Classifier: Topic :: System :: Systems Administration
29
+ Requires-Python: >=3.6
10
30
  Description-Content-Type: text/markdown
11
31
  License-File: LICENSE
12
32
  Requires-Dist: ansible
13
33
  Requires-Dist: ansible-runner
14
34
  Requires-Dist: paramiko
35
+ Requires-Dist: pydantic
36
+ Requires-Dist: pyyaml
37
+ Provides-Extra: dev
38
+ Requires-Dist: pytest; extra == "dev"
39
+ Requires-Dist: flake8; extra == "dev"
40
+ Requires-Dist: bump2version; extra == "dev"
41
+ Dynamic: author
42
+ Dynamic: author-email
43
+ Dynamic: classifier
15
44
  Dynamic: description
16
45
  Dynamic: description-content-type
17
46
  Dynamic: home-page
47
+ Dynamic: keywords
18
48
  Dynamic: license
19
49
  Dynamic: project-url
50
+ Dynamic: provides-extra
20
51
  Dynamic: requires-dist
52
+ Dynamic: requires-python
21
53
  Dynamic: summary
22
54
 
23
55
  # **VM Setup Tool**
@@ -29,7 +61,7 @@ The **VM Setup Tool** is an efficient, user-friendly solution designed to simpli
29
61
  ---
30
62
 
31
63
  ## **Pre-requisites**
32
- This tool supports projects utilizing **Docker Compose**. Ensure that a `docker-compose.yml` file is present at the root of your project directory before proceeding.
64
+ This tool supports projects utilizing **Docker Compose**.
33
65
 
34
66
  ---
35
67
 
@@ -48,14 +80,17 @@ pip install vm-tool
48
80
  Use the following example to configure and run the VM setup:
49
81
 
50
82
  ```python
51
- from vm_tool.runner import SetupRunner
83
+ from vm_tool.runner import SetupRunner, SetupRunnerConfig
52
84
 
53
- runner = SetupRunner(
85
+ config = SetupRunnerConfig(
54
86
  github_username='your_github_username', # e.g., username
55
87
  github_token='your_github_token', # e.g., token
56
- github_project_url='your_github_project_url' # e.g., https://github.com/username/repo
88
+ github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
89
+ docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
57
90
  )
58
91
 
92
+ runner = SetupRunner(config)
93
+
59
94
  runner.run_setup()
60
95
  ```
61
96
 
@@ -75,19 +110,32 @@ By automating these tasks, the tool minimizes errors and saves time, allowing yo
75
110
  The **VM Setup Tool** also supports cloud setup for VMs. Use the following example to configure and run the cloud setup:
76
111
 
77
112
  ```python
78
- from vm_tool.runner import SetupRunner
113
+ from vm_tool.runner import SetupRunner, SetupRunnerConfig, SSHConfig
79
114
 
80
- runner = SetupRunner(
115
+ config = SetupRunnerConfig(
81
116
  github_username='your_github_username', # e.g., username
82
117
  github_token='your_github_token', # e.g., token
83
- github_project_url='your_github_project_url' # e.g., https://github.com/username/repo
118
+ github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
119
+ docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
84
120
  )
85
121
 
86
- runner.run_cloud_setup(
87
- ssh_username='your_ssh_username', # e.g., ssh_user
88
- ssh_password='your_ssh_password', # e.g., ssh_password
89
- ssh_hostname='your_ssh_hostname' # e.g., ssh.example.com
90
- )
122
+ runner = SetupRunner(config)
123
+
124
+ ssh_configs = [
125
+ SSHConfig(
126
+ ssh_username='your_ssh_username_1', # e.g., ssh_user_1
127
+ ssh_password='your_ssh_password_1', # e.g., ssh_password_1
128
+ ssh_hostname='your_ssh_hostname_1' # e.g., ssh1.example.com
129
+ ),
130
+ SSHConfig(
131
+ ssh_username='your_ssh_username_2', # e.g., ssh_user_2
132
+ ssh_password='your_ssh_password_2', # e.g., ssh_password_2
133
+ ssh_hostname='your_ssh_hostname_2' # e.g., ssh2.example.com
134
+ )
135
+ # Add more SSHConfig instances as needed
136
+ ]
137
+
138
+ runner.run_cloud_setup(ssh_configs)
91
139
  ```
92
140
 
93
141
  ### **What Happens During Cloud Setup**
@@ -7,7 +7,7 @@ The **VM Setup Tool** is an efficient, user-friendly solution designed to simpli
7
7
  ---
8
8
 
9
9
  ## **Pre-requisites**
10
- This tool supports projects utilizing **Docker Compose**. Ensure that a `docker-compose.yml` file is present at the root of your project directory before proceeding.
10
+ This tool supports projects utilizing **Docker Compose**.
11
11
 
12
12
  ---
13
13
 
@@ -26,14 +26,17 @@ pip install vm-tool
26
26
  Use the following example to configure and run the VM setup:
27
27
 
28
28
  ```python
29
- from vm_tool.runner import SetupRunner
29
+ from vm_tool.runner import SetupRunner, SetupRunnerConfig
30
30
 
31
- runner = SetupRunner(
31
+ config = SetupRunnerConfig(
32
32
  github_username='your_github_username', # e.g., username
33
33
  github_token='your_github_token', # e.g., token
34
- github_project_url='your_github_project_url' # e.g., https://github.com/username/repo
34
+ github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
35
+ docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
35
36
  )
36
37
 
38
+ runner = SetupRunner(config)
39
+
37
40
  runner.run_setup()
38
41
  ```
39
42
 
@@ -53,19 +56,32 @@ By automating these tasks, the tool minimizes errors and saves time, allowing yo
53
56
  The **VM Setup Tool** also supports cloud setup for VMs. Use the following example to configure and run the cloud setup:
54
57
 
55
58
  ```python
56
- from vm_tool.runner import SetupRunner
59
+ from vm_tool.runner import SetupRunner, SetupRunnerConfig, SSHConfig
57
60
 
58
- runner = SetupRunner(
61
+ config = SetupRunnerConfig(
59
62
  github_username='your_github_username', # e.g., username
60
63
  github_token='your_github_token', # e.g., token
61
- github_project_url='your_github_project_url' # e.g., https://github.com/username/repo
64
+ github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
65
+ docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
62
66
  )
63
67
 
64
- runner.run_cloud_setup(
65
- ssh_username='your_ssh_username', # e.g., ssh_user
66
- ssh_password='your_ssh_password', # e.g., ssh_password
67
- ssh_hostname='your_ssh_hostname' # e.g., ssh.example.com
68
- )
68
+ runner = SetupRunner(config)
69
+
70
+ ssh_configs = [
71
+ SSHConfig(
72
+ ssh_username='your_ssh_username_1', # e.g., ssh_user_1
73
+ ssh_password='your_ssh_password_1', # e.g., ssh_password_1
74
+ ssh_hostname='your_ssh_hostname_1' # e.g., ssh1.example.com
75
+ ),
76
+ SSHConfig(
77
+ ssh_username='your_ssh_username_2', # e.g., ssh_user_2
78
+ ssh_password='your_ssh_password_2', # e.g., ssh_password_2
79
+ ssh_hostname='your_ssh_hostname_2' # e.g., ssh2.example.com
80
+ )
81
+ # Add more SSHConfig instances as needed
82
+ ]
83
+
84
+ runner.run_cloud_setup(ssh_configs)
69
85
  ```
70
86
 
71
87
  ### **What Happens During Cloud Setup**
@@ -0,0 +1,68 @@
1
+ from setuptools import setup, find_packages
2
+ import os
3
+
4
+ # Read the contents of README.md
5
+ readme_path = os.path.join(os.path.dirname(__file__), 'README.md')
6
+ if os.path.exists(readme_path):
7
+ with open(readme_path, encoding='utf-8') as f:
8
+ long_description = f.read()
9
+ else:
10
+ long_description = ''
11
+
12
+ setup(
13
+ name='vm_tool',
14
+ version='1.0.19', # This will be updated by bump2version
15
+ packages=find_packages(),
16
+ description='A Comprehensive Tool for Setting Up Virtual Machines.',
17
+ long_description=long_description,
18
+ long_description_content_type='text/markdown',
19
+ install_requires=[
20
+ 'ansible',
21
+ 'ansible-runner',
22
+ 'paramiko',
23
+ 'pydantic',
24
+ 'pyyaml'
25
+ ],
26
+ extras_require={
27
+ 'dev': [
28
+ 'pytest',
29
+ 'flake8',
30
+ 'bump2version'
31
+ ]
32
+ },
33
+ entry_points={
34
+ 'console_scripts': [
35
+ 'vm_tool=vm_tool.cli:main',
36
+ ],
37
+ },
38
+ classifiers=[
39
+ 'Development Status :: 5 - Production/Stable',
40
+ 'Intended Audience :: Developers',
41
+ 'Intended Audience :: System Administrators',
42
+ 'License :: OSI Approved :: MIT License',
43
+ 'Programming Language :: Python',
44
+ 'Programming Language :: Python :: 3',
45
+ 'Programming Language :: Python :: 3.6',
46
+ 'Programming Language :: Python :: 3.7',
47
+ 'Programming Language :: Python :: 3.8',
48
+ 'Programming Language :: Python :: 3.9',
49
+ 'Programming Language :: Python :: 3.10',
50
+ 'Programming Language :: Python :: 3.11',
51
+ 'Programming Language :: Python :: 3.12',
52
+ 'Programming Language :: Python :: 3.13',
53
+ 'Topic :: Software Development :: Build Tools',
54
+ 'Topic :: System :: Systems Administration',
55
+ ],
56
+ python_requires='>=3.6',
57
+ keywords='virtual machine setup ansible automation',
58
+ license='MIT',
59
+ include_package_data=True,
60
+ url='https://github.com/thesunnysinha/vm_tool',
61
+ project_urls={
62
+ 'Documentation': 'https://github.com/thesunnysinha/vm_tool/README.md',
63
+ 'Source': 'https://github.com/thesunnysinha/vm_tool',
64
+ 'Tracker': 'https://github.com/thesunnysinha/vm_tool/issues',
65
+ },
66
+ author='Sunny Sinha',
67
+ author_email='thesunnysinha@gmail.com',
68
+ )
@@ -2,7 +2,7 @@ import argparse
2
2
 
3
3
  def main():
4
4
  parser = argparse.ArgumentParser(description='Setup VMs using Ansible.')
5
- parser.add_argument('--version', action='version', version='1.0.16')
5
+ parser.add_argument('--version', action='version', version='1.0.19')
6
6
 
7
7
  args = parser.parse_args()
8
8
 
@@ -0,0 +1,116 @@
1
+ import sys
2
+ import ansible_runner
3
+ import os
4
+ import yaml
5
+ from pydantic import BaseModel, HttpUrl, validator
6
+ from typing import List
7
+
8
+ class SetupRunnerConfig(BaseModel):
9
+ github_username: str
10
+ github_token: str
11
+ github_project_url: HttpUrl
12
+ docker_compose_file_path: str = 'docker-compose.yml'
13
+
14
+ @validator('docker_compose_file_path', pre=True, always=True)
15
+ def set_default_docker_compose_file_path(cls, v):
16
+ return v or 'docker-compose.yml'
17
+
18
+ class SSHConfig(BaseModel):
19
+ ssh_username: str
20
+ ssh_password: str
21
+ ssh_hostname: str
22
+
23
+ class SetupRunner:
24
+ def __init__(self, config: SetupRunnerConfig):
25
+ self.github_username = config.github_username
26
+ self.github_token = config.github_token
27
+ self.github_project_url = config.github_project_url
28
+ self.docker_compose_file_path = config.docker_compose_file_path
29
+
30
+ def _run_ansible_playbook(self, extravars, inventory_file):
31
+ # Get the current directory of this script
32
+ current_dir = os.path.dirname(os.path.abspath(__file__))
33
+
34
+ # Get the virtual environment directory
35
+ venv_dir = os.path.join(sys.prefix, 'ansible_runner_data')
36
+
37
+ # Ensure the directory exists
38
+ os.makedirs(venv_dir, exist_ok=True)
39
+
40
+ # Construct dynamic paths
41
+ playbook_path = os.path.join(current_dir, 'vm_setup', 'setup.yml')
42
+ inventory_path = os.path.join(current_dir, 'vm_setup', inventory_file)
43
+
44
+ try:
45
+ # Run the Ansible playbook using ansible-runner
46
+ r = ansible_runner.run(
47
+ private_data_dir=venv_dir,
48
+ playbook=playbook_path,
49
+ inventory=inventory_path,
50
+ extravars=extravars
51
+ )
52
+
53
+ if r.rc != 0:
54
+ raise RuntimeError(f"Ansible playbook execution failed with return code {r.rc}: {r.stdout}")
55
+
56
+ except Exception as e:
57
+ raise RuntimeError(f"An error occurred while running the Ansible playbook: {str(e)}")
58
+
59
+ def run_setup(self):
60
+ # Construct extravars dictionary
61
+ extravars = {
62
+ 'GITHUB_USERNAME': self.github_username,
63
+ 'GITHUB_TOKEN': self.github_token,
64
+ 'GITHUB_PROJECT_URL': self.github_project_url,
65
+ 'EXECUTION_TYPE': "normal"
66
+ }
67
+
68
+ if self.docker_compose_file_path:
69
+ extravars["DOCKER_COMPOSE_FILE_PATH"] = self.docker_compose_file_path
70
+
71
+ self._run_ansible_playbook(extravars, 'inventory.yml')
72
+
73
+ def run_cloud_setup(self, ssh_configs: List[SSHConfig]):
74
+ # Define the path for the dynamic inventory file
75
+ inventory_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'vm_setup', 'dynamic_inventory.yml')
76
+
77
+ # Check if the dynamic inventory file already exists
78
+ if os.path.exists(inventory_file_path):
79
+ # Read the existing inventory file
80
+ with open(inventory_file_path, 'r') as inventory_file:
81
+ inventory_content = yaml.safe_load(inventory_file)
82
+ else:
83
+ # Create dynamic inventory content
84
+ inventory_content = {
85
+ 'all': {
86
+ 'hosts': {},
87
+ 'vars': {
88
+ 'ansible_python_interpreter': '/usr/bin/python3'
89
+ }
90
+ }
91
+ }
92
+
93
+ for i, ssh_config in enumerate(ssh_configs):
94
+ host_key = f'cloud_host_{i}'
95
+ inventory_content['all']['hosts'][host_key] = {
96
+ 'ansible_host': ssh_config.ssh_hostname,
97
+ 'ansible_user': ssh_config.ssh_username,
98
+ 'ansible_ssh_pass': ssh_config.ssh_password
99
+ }
100
+
101
+ # Write dynamic inventory to a file
102
+ with open(inventory_file_path, 'w') as inventory_file:
103
+ yaml.dump(inventory_content, inventory_file)
104
+
105
+ # Construct extravars dictionary
106
+ extravars = {
107
+ 'GITHUB_USERNAME': self.github_username,
108
+ 'GITHUB_TOKEN': self.github_token,
109
+ 'GITHUB_PROJECT_URL': self.github_project_url,
110
+ 'EXECUTION_TYPE': "cloud"
111
+ }
112
+
113
+ if self.docker_compose_file_path:
114
+ extravars["DOCKER_COMPOSE_FILE_PATH"] = self.docker_compose_file_path
115
+
116
+ self._run_ansible_playbook(extravars, 'dynamic_inventory.yml')
@@ -28,6 +28,16 @@
28
28
  state: touch
29
29
  mode: '0644'
30
30
 
31
+ - name: Check if Docker Compose File Path is Valid
32
+ ansible.builtin.stat:
33
+ path: "{{ project_dest_dir }}/{{ DOCKER_COMPOSE_FILE_PATH | default('docker-compose.yml') }}"
34
+ register: compose_file_stat
35
+
36
+ - name: Fail if Docker Compose File Path is Invalid
37
+ ansible.builtin.fail:
38
+ msg: "The specified Docker Compose file path '{{ project_dest_dir }}/{{ DOCKER_COMPOSE_FILE_PATH | default('docker-compose.yml') }}' does not exist."
39
+ when: not compose_file_stat.stat.exists
40
+
31
41
  - name: Insert Docker Service Configuration
32
42
  ansible.builtin.blockinfile:
33
43
  path: "{{ service_file_path }}"
@@ -39,7 +49,7 @@
39
49
  [Service]
40
50
  Type=simple
41
51
  WorkingDirectory={{ project_dest_dir }}
42
- ExecStart=docker compose -f docker-compose.yml up -d
52
+ ExecStart=docker compose -f {{ DOCKER_COMPOSE_FILE_PATH | default('docker-compose.yml') }} up -d
43
53
  Restart=always
44
54
  RestartSec=10s
45
55
 
@@ -50,4 +60,4 @@
50
60
  ansible.builtin.systemd:
51
61
  daemon_reload: yes
52
62
 
53
- become: yes
63
+ become: yes
File without changes
@@ -6,6 +6,17 @@
6
6
  static_playbook_dir: "{{ playbook_dir }}"
7
7
 
8
8
  tasks:
9
+ - name: Gather package facts
10
+ package_facts:
11
+ manager: auto
12
+
13
+ - name: Install sshpass if execution type is cloud and not already installed
14
+ apt:
15
+ name: sshpass
16
+ state: present
17
+ when: EXECUTION_TYPE == "cloud" and "'sshpass' not in ansible_facts.packages"
18
+ become: yes
19
+
9
20
  - name: Set project_dest_dir variable
10
21
  set_fact:
11
22
  project_dest_dir: "{{ static_playbook_dir }}/project"
@@ -1,23 +1,55 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: vm_tool
3
- Version: 1.0.16
3
+ Version: 1.0.19
4
4
  Summary: A Comprehensive Tool for Setting Up Virtual Machines.
5
5
  Home-page: https://github.com/thesunnysinha/vm_tool
6
+ Author: Sunny Sinha
7
+ Author-email: thesunnysinha@gmail.com
6
8
  License: MIT
7
9
  Project-URL: Documentation, https://github.com/thesunnysinha/vm_tool/README.md
8
10
  Project-URL: Source, https://github.com/thesunnysinha/vm_tool
9
11
  Project-URL: Tracker, https://github.com/thesunnysinha/vm_tool/issues
12
+ Keywords: virtual machine setup ansible automation
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: System Administrators
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.6
20
+ Classifier: Programming Language :: Python :: 3.7
21
+ Classifier: Programming Language :: Python :: 3.8
22
+ Classifier: Programming Language :: Python :: 3.9
23
+ Classifier: Programming Language :: Python :: 3.10
24
+ Classifier: Programming Language :: Python :: 3.11
25
+ Classifier: Programming Language :: Python :: 3.12
26
+ Classifier: Programming Language :: Python :: 3.13
27
+ Classifier: Topic :: Software Development :: Build Tools
28
+ Classifier: Topic :: System :: Systems Administration
29
+ Requires-Python: >=3.6
10
30
  Description-Content-Type: text/markdown
11
31
  License-File: LICENSE
12
32
  Requires-Dist: ansible
13
33
  Requires-Dist: ansible-runner
14
34
  Requires-Dist: paramiko
35
+ Requires-Dist: pydantic
36
+ Requires-Dist: pyyaml
37
+ Provides-Extra: dev
38
+ Requires-Dist: pytest; extra == "dev"
39
+ Requires-Dist: flake8; extra == "dev"
40
+ Requires-Dist: bump2version; extra == "dev"
41
+ Dynamic: author
42
+ Dynamic: author-email
43
+ Dynamic: classifier
15
44
  Dynamic: description
16
45
  Dynamic: description-content-type
17
46
  Dynamic: home-page
47
+ Dynamic: keywords
18
48
  Dynamic: license
19
49
  Dynamic: project-url
50
+ Dynamic: provides-extra
20
51
  Dynamic: requires-dist
52
+ Dynamic: requires-python
21
53
  Dynamic: summary
22
54
 
23
55
  # **VM Setup Tool**
@@ -29,7 +61,7 @@ The **VM Setup Tool** is an efficient, user-friendly solution designed to simpli
29
61
  ---
30
62
 
31
63
  ## **Pre-requisites**
32
- This tool supports projects utilizing **Docker Compose**. Ensure that a `docker-compose.yml` file is present at the root of your project directory before proceeding.
64
+ This tool supports projects utilizing **Docker Compose**.
33
65
 
34
66
  ---
35
67
 
@@ -48,14 +80,17 @@ pip install vm-tool
48
80
  Use the following example to configure and run the VM setup:
49
81
 
50
82
  ```python
51
- from vm_tool.runner import SetupRunner
83
+ from vm_tool.runner import SetupRunner, SetupRunnerConfig
52
84
 
53
- runner = SetupRunner(
85
+ config = SetupRunnerConfig(
54
86
  github_username='your_github_username', # e.g., username
55
87
  github_token='your_github_token', # e.g., token
56
- github_project_url='your_github_project_url' # e.g., https://github.com/username/repo
88
+ github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
89
+ docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
57
90
  )
58
91
 
92
+ runner = SetupRunner(config)
93
+
59
94
  runner.run_setup()
60
95
  ```
61
96
 
@@ -75,19 +110,32 @@ By automating these tasks, the tool minimizes errors and saves time, allowing yo
75
110
  The **VM Setup Tool** also supports cloud setup for VMs. Use the following example to configure and run the cloud setup:
76
111
 
77
112
  ```python
78
- from vm_tool.runner import SetupRunner
113
+ from vm_tool.runner import SetupRunner, SetupRunnerConfig, SSHConfig
79
114
 
80
- runner = SetupRunner(
115
+ config = SetupRunnerConfig(
81
116
  github_username='your_github_username', # e.g., username
82
117
  github_token='your_github_token', # e.g., token
83
- github_project_url='your_github_project_url' # e.g., https://github.com/username/repo
118
+ github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
119
+ docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
84
120
  )
85
121
 
86
- runner.run_cloud_setup(
87
- ssh_username='your_ssh_username', # e.g., ssh_user
88
- ssh_password='your_ssh_password', # e.g., ssh_password
89
- ssh_hostname='your_ssh_hostname' # e.g., ssh.example.com
90
- )
122
+ runner = SetupRunner(config)
123
+
124
+ ssh_configs = [
125
+ SSHConfig(
126
+ ssh_username='your_ssh_username_1', # e.g., ssh_user_1
127
+ ssh_password='your_ssh_password_1', # e.g., ssh_password_1
128
+ ssh_hostname='your_ssh_hostname_1' # e.g., ssh1.example.com
129
+ ),
130
+ SSHConfig(
131
+ ssh_username='your_ssh_username_2', # e.g., ssh_user_2
132
+ ssh_password='your_ssh_password_2', # e.g., ssh_password_2
133
+ ssh_hostname='your_ssh_hostname_2' # e.g., ssh2.example.com
134
+ )
135
+ # Add more SSHConfig instances as needed
136
+ ]
137
+
138
+ runner.run_cloud_setup(ssh_configs)
91
139
  ```
92
140
 
93
141
  ### **What Happens During Cloud Setup**
@@ -12,7 +12,7 @@ vm_tool.egg-info/dependency_links.txt
12
12
  vm_tool.egg-info/entry_points.txt
13
13
  vm_tool.egg-info/requires.txt
14
14
  vm_tool.egg-info/top_level.txt
15
- vm_tool/vm_setup/cloud_inventory.yml
15
+ vm_tool/vm_setup/dynamic_inventory.yml
16
16
  vm_tool/vm_setup/inventory.yml
17
17
  vm_tool/vm_setup/setup.yml
18
18
  vm_tool/vm_setup/docker/create_docker_service.yml
@@ -0,0 +1,10 @@
1
+ ansible
2
+ ansible-runner
3
+ paramiko
4
+ pydantic
5
+ pyyaml
6
+
7
+ [dev]
8
+ pytest
9
+ flake8
10
+ bump2version
vm_tool-1.0.16/setup.py DELETED
@@ -1,37 +0,0 @@
1
- from setuptools import setup, find_packages
2
- import os
3
-
4
- # Read the contents of README.md
5
- readme_path = os.path.join(os.path.dirname(__file__), 'README.md')
6
- if os.path.exists(readme_path):
7
- with open(readme_path, encoding='utf-8') as f:
8
- long_description = f.read()
9
- else:
10
- long_description = ''
11
-
12
- setup(
13
- name='vm_tool',
14
- version='1.0.16', # This will be updated by bump2version
15
- packages=find_packages(),
16
- description='A Comprehensive Tool for Setting Up Virtual Machines.',
17
- long_description=long_description,
18
- long_description_content_type='text/markdown',
19
- install_requires=[
20
- 'ansible',
21
- 'ansible-runner',
22
- 'paramiko'
23
- ],
24
- entry_points={
25
- 'console_scripts': [
26
- 'vm_tool=vm_tool.cli:main',
27
- ],
28
- },
29
- license='MIT',
30
- include_package_data=True,
31
- url='https://github.com/thesunnysinha/vm_tool',
32
- project_urls={
33
- 'Documentation': 'https://github.com/thesunnysinha/vm_tool/README.md',
34
- 'Source': 'https://github.com/thesunnysinha/vm_tool',
35
- 'Tracker': 'https://github.com/thesunnysinha/vm_tool/issues',
36
- },
37
- )
@@ -1,88 +0,0 @@
1
- import sys
2
- import ansible_runner
3
- import os
4
-
5
- class SetupRunner:
6
- def __init__(self, github_username, github_token, github_project_url):
7
- self.github_username = github_username
8
- self.github_token = github_token
9
- self.github_project_url = github_project_url
10
-
11
- def run_setup(self):
12
- # Construct extravars dictionary
13
- extravars = {
14
- 'GITHUB_USERNAME': self.github_username,
15
- 'GITHUB_TOKEN': self.github_token,
16
- 'GITHUB_PROJECT_URL': self.github_project_url
17
- }
18
-
19
- # Get the current directory of this script
20
- current_dir = os.path.dirname(os.path.abspath(__file__))
21
-
22
- # Get the virtual environment directory
23
- venv_dir = os.path.join(sys.prefix, 'ansible_runner_data')
24
-
25
- # Ensure the directory exists
26
- os.makedirs(venv_dir, exist_ok=True)
27
-
28
-
29
- # Construct dynamic paths
30
- playbook_path = os.path.join(current_dir, 'vm_setup', 'setup.yml')
31
- inventory_path = os.path.join(current_dir, 'vm_setup', 'inventory.yml')
32
-
33
- try:
34
- # Run the Ansible playbook using ansible-runner
35
- r = ansible_runner.run(
36
- private_data_dir=venv_dir,
37
- playbook=playbook_path,
38
- inventory=inventory_path,
39
- extravars=extravars
40
- )
41
-
42
- if r.rc != 0:
43
- raise RuntimeError(f"Ansible playbook execution failed with return code {r.rc}: {r.stdout}")
44
-
45
- except Exception as e:
46
- raise RuntimeError(f"An error occurred while running the Ansible playbook: {str(e)}")
47
-
48
-
49
- def run_cloud_setup(self,ssh_username,ssh_password,ssh_hostname):
50
- # Construct extravars dictionary
51
- extravars = {
52
- 'SSH_USERNAME': ssh_username,
53
- 'SSH_PASSWORD': ssh_password,
54
- 'SSH_HOSTNAME': ssh_hostname,
55
- 'GITHUB_USERNAME': self.github_username,
56
- 'GITHUB_TOKEN': self.github_token,
57
- 'GITHUB_PROJECT_URL': self.github_project_url
58
-
59
- }
60
-
61
- # Get the current directory of this script
62
- current_dir = os.path.dirname(os.path.abspath(__file__))
63
-
64
- # Get the virtual environment directory
65
- venv_dir = os.path.join(sys.prefix, 'ansible_runner_data')
66
-
67
- # Ensure the directory exists
68
- os.makedirs(venv_dir, exist_ok=True)
69
-
70
-
71
- # Construct dynamic paths
72
- playbook_path = os.path.join(current_dir, 'vm_setup', 'setup.yml')
73
- inventory_path = os.path.join(current_dir, 'vm_setup', 'cloud_inventory.yml')
74
-
75
- try:
76
- # Run the Ansible playbook using ansible-runner
77
- r = ansible_runner.run(
78
- private_data_dir=venv_dir,
79
- playbook=playbook_path,
80
- inventory=inventory_path,
81
- extravars=extravars
82
- )
83
-
84
- if r.rc != 0:
85
- raise RuntimeError(f"Ansible playbook execution failed with return code {r.rc}: {r.stdout}")
86
-
87
- except Exception as e:
88
- raise RuntimeError(f"An error occurred while running the Ansible playbook: {str(e)}")
@@ -1,8 +0,0 @@
1
- all:
2
- hosts:
3
- cloud_host:
4
- ansible_host: "{{ SSH_HOSTNAME }}"
5
- ansible_user: "{{ SSH_USERNAME }}"
6
- ansible_ssh_pass: "{{ SSH_PASSWORD }}"
7
- vars:
8
- ansible_python_interpreter: /usr/bin/python3
@@ -1,3 +0,0 @@
1
- ansible
2
- ansible-runner
3
- paramiko
File without changes
File without changes
File without changes
File without changes
File without changes