vm-tool 1.0.2__tar.gz → 1.0.6__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.
vm_tool-1.0.6/PKG-INFO ADDED
@@ -0,0 +1,97 @@
1
+ Metadata-Version: 2.2
2
+ Name: vm_tool
3
+ Version: 1.0.6
4
+ Summary: A Comprehensive Tool for Setting Up Virtual Machines Using Ansible.
5
+ License: MIT
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: ansible
9
+ Requires-Dist: ansible-runner
10
+ Requires-Dist: paramiko
11
+ Dynamic: description
12
+ Dynamic: description-content-type
13
+ Dynamic: license
14
+ Dynamic: requires-dist
15
+ Dynamic: summary
16
+
17
+ # **VM Setup Tool**
18
+ ### **A Comprehensive Solution for Streamlining Virtual Machine Configuration with Ansible**
19
+
20
+ ## **Overview**
21
+ The **VM Setup Tool** is an efficient, user-friendly solution designed to simplify the process of setting up and managing virtual machines (VMs) using Ansible. Ideal for automating VM deployment and configuration, this tool ensures consistency and enhances operational efficiency across your infrastructure.
22
+
23
+ ---
24
+
25
+ ## **Pre-requisites**
26
+ 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.
27
+
28
+ ---
29
+
30
+ ## **Installation**
31
+ Install the VM Setup Tool using **pip**, the Python package manager:
32
+
33
+ ```bash
34
+ pip install vm-tool
35
+ ```
36
+
37
+ ---
38
+
39
+ ## **Example Usage**
40
+
41
+ ### **Automated VM Setup**
42
+ Use the following example to configure and run the VM setup:
43
+
44
+ ```python
45
+ from vm_tool.runner import SetupRunner
46
+
47
+ runner = SetupRunner(
48
+ github_username='your_github_username', # e.g., username
49
+ github_token='your_github_token', # e.g., token
50
+ github_project_url='your_github_project_url' # e.g., https://github.com/username/repo
51
+ )
52
+
53
+ runner.run_setup()
54
+ ```
55
+
56
+ ### **What Happens During Setup**
57
+ The VM Setup Tool will:
58
+ 1. Clone the specified GitHub repository to your local machine.
59
+ 2. Install **Docker** if it’s not already available on the target machine.
60
+ 3. Install **Docker Compose** for managing multi-container applications.
61
+ 4. Create, enable, and start the Docker service.
62
+ 5. Ensure the Docker container remains active, providing a robust environment for your applications.
63
+
64
+ By automating these tasks, the tool minimizes errors and saves time, allowing you to focus on development and deployment.
65
+
66
+ ---
67
+
68
+ ## **SSH Client Feature**
69
+ The **VM Setup Tool** also includes a dedicated **SSH client** feature to simplify the configuration of SSH access for VMs, including automated SSH key generation and management.
70
+
71
+ ### **Example Usage**
72
+
73
+ ```python
74
+ from vm_tool.ssh import SSHSetup
75
+
76
+ ssh_setup = SSHSetup(
77
+ hostname='your_vm_hostname', # e.g., vm.example.com
78
+ username='your_vm_username', # e.g., user
79
+ password='your_vm_password', # e.g., password
80
+ email='your_email_for_ssh_key' # e.g., user@example.com
81
+ )
82
+
83
+ ssh_setup.setup()
84
+ ```
85
+
86
+ ### **What Happens During SSH Setup**
87
+ When you run the SSH setup, the tool will:
88
+ 1. Generate an SSH key pair if none exists.
89
+ 2. Read the public SSH key or create a new one if necessary.
90
+ 3. Configure the VM by adding the public key to the VM's **authorized_keys** file.
91
+ 4. Update the local SSH configuration file with the VM's details.
92
+ 5. Establish an SSH connection to verify the setup.
93
+ 6. Close the connection once setup is complete.
94
+
95
+ ---
96
+
97
+ With its comprehensive features, the **VM Setup Tool** eliminates the hassle of manual configurations and enables seamless integration of VMs into your workflows. Start using the tool today to automate and optimize your virtual machine setup process.
@@ -7,7 +7,7 @@ with open(os.path.join(os.path.dirname(__file__), 'Readme.md'), encoding='utf-8'
7
7
 
8
8
  setup(
9
9
  name='vm_tool',
10
- version='1.0.2', # This will be updated by bump2version
10
+ version='1.0.6', # This will be updated by bump2version
11
11
  packages=find_packages(),
12
12
  description='A Comprehensive Tool for Setting Up Virtual Machines Using Ansible.',
13
13
  long_description=long_description,
@@ -15,6 +15,7 @@ setup(
15
15
  install_requires=[
16
16
  'ansible',
17
17
  'ansible-runner',
18
+ 'paramiko'
18
19
  ],
19
20
  entry_points={
20
21
  'console_scripts': [
@@ -0,0 +1,117 @@
1
+ import os
2
+ import paramiko
3
+
4
+ class SSHSetup:
5
+ """
6
+ A class to set up SSH configuration and keys for a VM.
7
+
8
+ Attributes:
9
+ hostname (str): The hostname of the VM.
10
+ username (str): The username for SSH login.
11
+ password (str): The password for SSH login.
12
+ email (str): The email for SSH key generation.
13
+ private_key_path (str): The path to the private SSH key.
14
+ client (paramiko.SSHClient): The SSH client.
15
+ """
16
+
17
+ def __init__(self, hostname, username, password, email):
18
+ """
19
+ The constructor for SSHSetup class.
20
+
21
+ Parameters:
22
+ hostname (str): The hostname of the VM.
23
+ username (str): The username for SSH login.
24
+ password (str): The password for SSH login.
25
+ email (str): The email for SSH key generation.
26
+ """
27
+ self.hostname = hostname
28
+ self.username = username
29
+ self.password = password
30
+ self.email = email
31
+ self.private_key_path = os.path.expanduser('~/.ssh/id_rsa')
32
+ self.client = paramiko.SSHClient()
33
+ self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
34
+
35
+ def generate_ssh_key(self, email):
36
+ """
37
+ Generates an SSH key pair.
38
+
39
+ Parameters:
40
+ email (str): The email for SSH key generation.
41
+ """
42
+ print(f"Generating SSH key for email: {email}")
43
+ os.system(f'ssh-keygen -t rsa -b 4096 -C "{email}"')
44
+
45
+ def read_or_generate_public_key(self, email):
46
+ """
47
+ Reads the public SSH key or generates a new one if it doesn't exist.
48
+
49
+ Parameters:
50
+ email (str): The email for SSH key generation.
51
+
52
+ Returns:
53
+ str: The public SSH key.
54
+ """
55
+ public_key_path = f'{self.private_key_path}.pub'
56
+ if not os.path.exists(public_key_path):
57
+ self.generate_ssh_key(email)
58
+ with open(public_key_path, 'r') as file:
59
+ print(f"Reading public key from {public_key_path}")
60
+ return file.read()
61
+
62
+ def configure_vm(self, vm_ip, vm_password, public_key):
63
+ """
64
+ Configures the VM by adding the public SSH key to the authorized keys.
65
+
66
+ Parameters:
67
+ vm_ip (str): The IP address of the VM.
68
+ vm_password (str): The password for the VM.
69
+ public_key (str): The public SSH key.
70
+ """
71
+ print(f"Configuring VM at {vm_ip} with provided public key.")
72
+ self.client.connect(vm_ip, username=self.username, password=vm_password)
73
+ self.client.exec_command(f'echo "{public_key}" >> ~/.ssh/authorized_keys')
74
+ self.client.close()
75
+
76
+ def update_ssh_config(self):
77
+ """
78
+ Updates the local SSH config file with the VM details.
79
+ """
80
+ config = f"""
81
+ Host {self.hostname}
82
+ HostName {self.hostname}
83
+ User {self.username}
84
+ StrictHostKeyChecking no
85
+ IdentityFile {self.private_key_path}
86
+ ForwardAgent yes
87
+ """
88
+ print(f"Updating SSH config for host {self.hostname}.")
89
+ with open(f'{os.path.expanduser("~")}/.ssh/config', 'a') as file:
90
+ file.write(config)
91
+
92
+ def establish_connection(self):
93
+ """
94
+ Establishes an SSH connection to the VM.
95
+ """
96
+ print(f"Establishing SSH connection to {self.hostname}.")
97
+ self.client.connect(self.hostname, username=self.username, key_filename=self.private_key_path)
98
+
99
+ def close_connection(self):
100
+ """
101
+ Closes the SSH connection.
102
+ """
103
+ if self.client:
104
+ print("Closing SSH connection.")
105
+ self.client.close()
106
+
107
+ def setup(self):
108
+ """
109
+ Sets up the SSH configuration and keys for the VM.
110
+ """
111
+ print("Starting SSH setup.")
112
+ public_key = self.read_or_generate_public_key(self.email)
113
+ self.configure_vm(self.hostname, self.password, public_key)
114
+ self.update_ssh_config()
115
+ self.establish_connection()
116
+ self.close_connection()
117
+ print("SSH setup completed.")
@@ -0,0 +1,97 @@
1
+ Metadata-Version: 2.2
2
+ Name: vm_tool
3
+ Version: 1.0.6
4
+ Summary: A Comprehensive Tool for Setting Up Virtual Machines Using Ansible.
5
+ License: MIT
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: ansible
9
+ Requires-Dist: ansible-runner
10
+ Requires-Dist: paramiko
11
+ Dynamic: description
12
+ Dynamic: description-content-type
13
+ Dynamic: license
14
+ Dynamic: requires-dist
15
+ Dynamic: summary
16
+
17
+ # **VM Setup Tool**
18
+ ### **A Comprehensive Solution for Streamlining Virtual Machine Configuration with Ansible**
19
+
20
+ ## **Overview**
21
+ The **VM Setup Tool** is an efficient, user-friendly solution designed to simplify the process of setting up and managing virtual machines (VMs) using Ansible. Ideal for automating VM deployment and configuration, this tool ensures consistency and enhances operational efficiency across your infrastructure.
22
+
23
+ ---
24
+
25
+ ## **Pre-requisites**
26
+ 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.
27
+
28
+ ---
29
+
30
+ ## **Installation**
31
+ Install the VM Setup Tool using **pip**, the Python package manager:
32
+
33
+ ```bash
34
+ pip install vm-tool
35
+ ```
36
+
37
+ ---
38
+
39
+ ## **Example Usage**
40
+
41
+ ### **Automated VM Setup**
42
+ Use the following example to configure and run the VM setup:
43
+
44
+ ```python
45
+ from vm_tool.runner import SetupRunner
46
+
47
+ runner = SetupRunner(
48
+ github_username='your_github_username', # e.g., username
49
+ github_token='your_github_token', # e.g., token
50
+ github_project_url='your_github_project_url' # e.g., https://github.com/username/repo
51
+ )
52
+
53
+ runner.run_setup()
54
+ ```
55
+
56
+ ### **What Happens During Setup**
57
+ The VM Setup Tool will:
58
+ 1. Clone the specified GitHub repository to your local machine.
59
+ 2. Install **Docker** if it’s not already available on the target machine.
60
+ 3. Install **Docker Compose** for managing multi-container applications.
61
+ 4. Create, enable, and start the Docker service.
62
+ 5. Ensure the Docker container remains active, providing a robust environment for your applications.
63
+
64
+ By automating these tasks, the tool minimizes errors and saves time, allowing you to focus on development and deployment.
65
+
66
+ ---
67
+
68
+ ## **SSH Client Feature**
69
+ The **VM Setup Tool** also includes a dedicated **SSH client** feature to simplify the configuration of SSH access for VMs, including automated SSH key generation and management.
70
+
71
+ ### **Example Usage**
72
+
73
+ ```python
74
+ from vm_tool.ssh import SSHSetup
75
+
76
+ ssh_setup = SSHSetup(
77
+ hostname='your_vm_hostname', # e.g., vm.example.com
78
+ username='your_vm_username', # e.g., user
79
+ password='your_vm_password', # e.g., password
80
+ email='your_email_for_ssh_key' # e.g., user@example.com
81
+ )
82
+
83
+ ssh_setup.setup()
84
+ ```
85
+
86
+ ### **What Happens During SSH Setup**
87
+ When you run the SSH setup, the tool will:
88
+ 1. Generate an SSH key pair if none exists.
89
+ 2. Read the public SSH key or create a new one if necessary.
90
+ 3. Configure the VM by adding the public key to the VM's **authorized_keys** file.
91
+ 4. Update the local SSH configuration file with the VM's details.
92
+ 5. Establish an SSH connection to verify the setup.
93
+ 6. Close the connection once setup is complete.
94
+
95
+ ---
96
+
97
+ With its comprehensive features, the **VM Setup Tool** eliminates the hassle of manual configurations and enables seamless integration of VMs into your workflows. Start using the tool today to automate and optimize your virtual machine setup process.
@@ -3,6 +3,7 @@ setup.py
3
3
  vm_tool/__init__.py
4
4
  vm_tool/cli.py
5
5
  vm_tool/runner.py
6
+ vm_tool/ssh.py
6
7
  vm_tool.egg-info/PKG-INFO
7
8
  vm_tool.egg-info/SOURCES.txt
8
9
  vm_tool.egg-info/dependency_links.txt
@@ -1,2 +1,3 @@
1
1
  ansible
2
2
  ansible-runner
3
+ paramiko
vm_tool-1.0.2/PKG-INFO DELETED
@@ -1,60 +0,0 @@
1
- Metadata-Version: 2.2
2
- Name: vm_tool
3
- Version: 1.0.2
4
- Summary: A Comprehensive Tool for Setting Up Virtual Machines Using Ansible.
5
- License: MIT
6
- Description-Content-Type: text/markdown
7
- License-File: LICENSE
8
- Requires-Dist: ansible
9
- Requires-Dist: ansible-runner
10
- Dynamic: description
11
- Dynamic: description-content-type
12
- Dynamic: license
13
- Dynamic: requires-dist
14
- Dynamic: summary
15
-
16
- # VM Setup Tool
17
-
18
- ### A Comprehensive Tool for Setting Up Virtual Machines Using Ansible
19
-
20
- ## Overview
21
-
22
- The VM Setup Tool is designed to simplify the process of setting up virtual machines (VMs) using Ansible. This tool is particularly useful for automating the deployment and configuration of VMs, ensuring consistency and efficiency across your infrastructure.
23
-
24
- ## Pre-requisites
25
-
26
- Currently, the tool supports projects that use Docker Compose. Ensure you have a `docker-compose.yml` file at the root level of your project.
27
-
28
- ## Installation
29
-
30
- To install the VM Setup Tool, you can use pip, the Python package installer. Run the following command in your terminal:
31
-
32
- ```bash
33
- pip install vm-tool
34
- ```
35
-
36
- ## Example Usage
37
-
38
- ```python
39
- from vm_tool import SetupRunner
40
-
41
- runner = SetupRunner(
42
- github_username='your_github_username', # e.g. username
43
- github_token='your_github_token', # e.g. token
44
- github_project_url='your_github_project_url' # e.g. https://github.com/username/repo
45
- )
46
-
47
- runner.run_setup()
48
- ```
49
-
50
- ## What This Will Do
51
-
52
- ### When you run the setup, the VM Setup Tool will perform the following actions:
53
-
54
- - Clone the specified GitHub repository to your local machine.
55
- - Install Docker on the target machine if it is not already installed.
56
- - Install Docker Compose to manage multi-container Docker applications.
57
- - Create, enable, and start a Docker service on the machine.
58
- - Ensure that the Docker container remains up and running, providing a stable environment for your applications.
59
-
60
- By automating these steps, the VM Setup Tool helps you save time and reduce the potential for errors, allowing you to focus on developing and deploying your applications.
@@ -1,60 +0,0 @@
1
- Metadata-Version: 2.2
2
- Name: vm_tool
3
- Version: 1.0.2
4
- Summary: A Comprehensive Tool for Setting Up Virtual Machines Using Ansible.
5
- License: MIT
6
- Description-Content-Type: text/markdown
7
- License-File: LICENSE
8
- Requires-Dist: ansible
9
- Requires-Dist: ansible-runner
10
- Dynamic: description
11
- Dynamic: description-content-type
12
- Dynamic: license
13
- Dynamic: requires-dist
14
- Dynamic: summary
15
-
16
- # VM Setup Tool
17
-
18
- ### A Comprehensive Tool for Setting Up Virtual Machines Using Ansible
19
-
20
- ## Overview
21
-
22
- The VM Setup Tool is designed to simplify the process of setting up virtual machines (VMs) using Ansible. This tool is particularly useful for automating the deployment and configuration of VMs, ensuring consistency and efficiency across your infrastructure.
23
-
24
- ## Pre-requisites
25
-
26
- Currently, the tool supports projects that use Docker Compose. Ensure you have a `docker-compose.yml` file at the root level of your project.
27
-
28
- ## Installation
29
-
30
- To install the VM Setup Tool, you can use pip, the Python package installer. Run the following command in your terminal:
31
-
32
- ```bash
33
- pip install vm-tool
34
- ```
35
-
36
- ## Example Usage
37
-
38
- ```python
39
- from vm_tool import SetupRunner
40
-
41
- runner = SetupRunner(
42
- github_username='your_github_username', # e.g. username
43
- github_token='your_github_token', # e.g. token
44
- github_project_url='your_github_project_url' # e.g. https://github.com/username/repo
45
- )
46
-
47
- runner.run_setup()
48
- ```
49
-
50
- ## What This Will Do
51
-
52
- ### When you run the setup, the VM Setup Tool will perform the following actions:
53
-
54
- - Clone the specified GitHub repository to your local machine.
55
- - Install Docker on the target machine if it is not already installed.
56
- - Install Docker Compose to manage multi-container Docker applications.
57
- - Create, enable, and start a Docker service on the machine.
58
- - Ensure that the Docker container remains up and running, providing a stable environment for your applications.
59
-
60
- By automating these steps, the VM Setup Tool helps you save time and reduce the potential for errors, allowing you to focus on developing and deploying your applications.
File without changes
File without changes
File without changes
File without changes
File without changes