aap-utils 0.1__tar.gz → 0.1.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aap_utils
3
- Version: 0.1
3
+ Version: 0.1.3
4
4
  Summary: A Python library for registering an IP address for AAP
5
5
  Author: Minh Dang
6
6
  Author-email: danghoangminh86@gmail.com
@@ -4,13 +4,13 @@ A Python library for registering an IP address on a specific server.
4
4
 
5
5
  ## Installation
6
6
 
7
- To install AAP lib from PyPI, run: pip install pmcd_aap
7
+ To install AAP lib from PyPI, run: pip install aap_utils
8
8
 
9
9
 
10
10
  ## Usage
11
11
 
12
12
  ```python
13
- from aap import register_demo
13
+ from aap_utils import register_demo
14
14
 
15
15
  register_demo(debug=True)
16
16
 
@@ -0,0 +1,80 @@
1
+ import socket
2
+ import requests
3
+ import time
4
+ import os
5
+ from hydra import initialize, compose
6
+ from omegaconf import OmegaConf, DictConfig
7
+
8
+ def register_demo(debug=False):
9
+ for attempt in range(10):
10
+ try:
11
+ local_ip = socket.gethostbyname(socket.gethostname())
12
+ response = requests.post(
13
+ "http://hocmay-svc/aiplatform-api/demo/register/",
14
+ json={"demo_ip": local_ip},
15
+ headers={"Content-Type": "application/json"}
16
+ )
17
+ if response.ok:
18
+ response_json = response.json()
19
+ argo_host = response_json.get('ARGOWORKFLOW_HOST', 'http://argowf.aiplatform.vcntt.tech')
20
+ domain_name = argo_host.split("argowf.")[-1]
21
+ url, namespace = create_url(domain_name=domain_name)
22
+
23
+ # print(f"The demo service is at {namespace}.your_custorm_domain/demo/. Eg: {url}")
24
+ print(f"The demo service is at {url}")
25
+ if debug:
26
+ print("IP registered successfully.")
27
+ return True
28
+ else:
29
+ if debug:
30
+ print(f"Attempt {attempt + 1}: Failed: {response.text}")
31
+ except (socket.error, requests.exceptions.RequestException) as e:
32
+ if debug: # Print errors only if debug is True
33
+ print(f"Attempt {attempt + 1}: Error: {e}")
34
+
35
+ time.sleep(2) # Wait for 2 seconds before retrying
36
+
37
+ if debug:
38
+ print("Failed to register IP after 10 attempts.")
39
+ return False
40
+
41
+
42
+
43
+ def create_url(domain_name = "aiplatform.vcntt.tech"):
44
+ # Define the static domain name
45
+
46
+ # Read the KERNEL_NAMESPACE environment variable
47
+ kernel_namespace = os.getenv("KERNEL_NAMESPACE")
48
+
49
+ # Validate the environment variable
50
+ if not kernel_namespace:
51
+ kernel_namespace="undefined"
52
+
53
+ # Replace 'machinelearning' with 'appmachinepublic' in KERNEL_NAMESPACE
54
+ if kernel_namespace.startswith("machinelearning"):
55
+ transformed_namespace = kernel_namespace.replace("machinelearning", "appmachinepublic", 1)
56
+ else:
57
+ raise ValueError(f"The KERNEL_NAMESPACE '{kernel_namespace}' does not follow the expected format.")
58
+
59
+ # Create the final URL
60
+ url = f"https://{transformed_namespace}.{domain_name}"
61
+ return url, transformed_namespace
62
+
63
+
64
+ def get_args():
65
+ kcn_params = "config.yaml"
66
+ config_path="configs/config.yaml"
67
+ overrides = []
68
+
69
+ if os.environ.get('KCN_PARAMS') and os.environ.get('KCN_PARAMS') != '':
70
+ full_path = os.getenv('KCN_PARAMS')
71
+ config_path = os.path.join(config_path, kcn_params)
72
+ kcn_params = os.path.basename(full_path) # Extract the filename
73
+
74
+ if os.environ.get('KCN_OVERRIDES') and os.environ.get('KCN_OVERRIDES') != '':
75
+ overrides_env = os.getenv("KCN_OVERRIDES")
76
+ overrides = overrides_env.split('|') if overrides_env else []
77
+
78
+ with initialize(version_base=None, config_path=config_path):
79
+ args = compose(config_name=kcn_params)
80
+ return args
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aap_utils
3
- Version: 0.1
3
+ Version: 0.1.3
4
4
  Summary: A Python library for registering an IP address for AAP
5
5
  Author: Minh Dang
6
6
  Author-email: danghoangminh86@gmail.com
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="aap_utils", # The name of your library
5
- version="0.1",
5
+ version="0.1.3",
6
6
  description="A Python library for registering an IP address for AAP",
7
7
  author="Minh Dang",
8
8
  author_email="danghoangminh86@gmail.com",
@@ -1,29 +0,0 @@
1
- import socket
2
- import requests
3
- import time
4
-
5
- def register_demo(debug=False):
6
- for attempt in range(10):
7
- try:
8
- local_ip = socket.gethostbyname(socket.gethostname())
9
- response = requests.post(
10
- "http://hocmay-svc/aiplatform-api/demo/register/",
11
- json={"demo_ip": local_ip},
12
- headers={"Content-Type": "application/json"}
13
- )
14
- if response.ok:
15
- if debug:
16
- print("IP registered successfully.")
17
- return True
18
- else:
19
- if debug:
20
- print(f"Attempt {attempt + 1}: Failed: {response.text}")
21
- except (socket.error, requests.exceptions.RequestException) as e:
22
- if debug: # Print errors only if debug is True
23
- print(f"Attempt {attempt + 1}: Error: {e}")
24
-
25
- time.sleep(2) # Wait for 2 seconds before retrying
26
-
27
- if debug:
28
- print("Failed to register IP after 10 attempts.")
29
- return False
File without changes
File without changes
File without changes