Skip to content

Commit

Permalink
Added popup for remote connection (Not yet functional)
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanpoland committed Apr 11, 2023
1 parent 6869033 commit 25d5d1f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 23 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Shiphelm is a Python library for interacting with containers more easily. With S
- Search containers by name or ID
- Change the open ports of a container
- Run new containers
- Work with Docker, Kubernetes
- Work with Docker, Docker-Swarm, and Kubernetes
- Use Kubernetes clusters and Docker Swarm

## Installation
Expand All @@ -29,19 +29,19 @@ GitHub Releases [https://github.com/Gameplex-Software/ShipHelm/releases]()

## Docker usage

This code will allow you to manage the local docker daemon
This code will allow you to manage the local container engine

```
from shiphelm.helmdocker import helmdocker
from shiphelm.helm import helm
hd = helmdocker() # create an instance of helmdocker
hd = helm.helm() # create an instance of helm
```

This code will allow you to manage any remote docker daemon
This code will allow you to manage any compatible remote container engine
```
from shiphelm.helmdocker import helmdocker
from shiphelm.helm import helm
hd = helmdocker('tcp://remote-docker-host:2375') # create an instance of helmdocker for romote management
hd = helm.reomte_connect('tcp://remote-docker-host:2375') # create an instance of helmdocker for romote management
```

### Get a List of Running Containers
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[metadata]
version = 0.6.2
version = 0.7.1-Beta
license_files = LICENSE
56 changes: 41 additions & 15 deletions src/shiphelm/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
# limitations under the License.
# ----------------------------------------------------------------------------

try:
from . import helmdocker, helmkube
except:
print("Error: Shiphelm cannot be run from source!")
exit()
import helmdocker, helmkube
from kubernetes import client
from typing import TYPE_CHECKING
import docker
import tkinter as tk
from tkinter import ttk

#Fix name conflict between docker nad kubernetes client
kubeclient = client
Expand All @@ -35,30 +33,32 @@
from helmkube import *

class helm:
def __init__():
def __init__(self, engine=None):
helm.engine = helm.set_engine_auto()
helm.get_helm_client()

def set_engine_auto():
helm.engine = None
try:
v1 = kubeclient.CoreV1Api()
api = v1.CoreV1Api()
helm.engine = "kubernetes"
v1.list_pod_for_all_namespaces(watch = False)
namespaces = api.list_namespace().items
print("Found Kubernetes engine on local system using Kubernetes container engine")
except:
pass
if not helm.engine:
try:
docker.from_env()
print("Found Docker engine on local system using Kubernetes container engine")
print("Found Docker engine on local system using Docker container engine")
helm.engine = "docker"
except:
pass

if not helm.engine:
print("[Error] Could not locate kubernetes or docker locally, this could be due to the current user permissions or an incompatible engine.")
print("[Debug] No compatible engine found, prompting for remote connection")
helm.remote_popup()
print("Popup got engine data:", helm.engineAddress, helm.engineType)

return helm.engine

def set_engine_manual(engine_select):
helm.engine = None
if engine_select == "docker":
Expand All @@ -78,9 +78,35 @@ def set_engine_manual(engine_select):

return helm.engine

def remote_popup():
# Create a popup window
window = tk.Tk()
window.title("Remote Address")

# Create a label and text input field for the remote address
tk.Label(window, text="Remote Address:").grid(row=0, column=0)
remote_address = tk.Entry(window)
remote_address.grid(row=0, column=1)

# Create a label and dropdown menu for the options
tk.Label(window, text="Options:").grid(row=1, column=0)
options = ttk.Combobox(window, values=["Option 1", "Option 2", "Option 3"])
options.current(0)
options.grid(row=1, column=1)

# Add a button to submit the inputs
submit_button = tk.Button(window, text="Submit")
submit_button.grid(row=2, column=1)

# Return values
helm.engineAddress = remote_address
helm.engineType = options.get()

# Start the event loop
window.mainloop()

def add_methods(cls):
methods = [m for m in dir(cls) if not m.startswith("__") and callable(getattr(cls, m))]
print(methods)

for method in methods:
setattr(helm, method, getattr(cls, method))
Expand All @@ -92,4 +118,4 @@ def get_helm_client():
return helmdocker.helmdocker()
elif helm.engine == "kubernetes":
helm.add_methods(helmkube.helmkube)
return helmkube.helmkube()
return helmkube.helmkube()

0 comments on commit 25d5d1f

Please sign in to comment.