aap-utils 0.1__tar.gz → 0.1.2__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,10 +1,15 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aap_utils
3
- Version: 0.1
3
+ Version: 0.1.2
4
4
  Summary: A Python library for registering an IP address for AAP
5
+ Home-page: UNKNOWN
5
6
  Author: Minh Dang
6
7
  Author-email: danghoangminh86@gmail.com
8
+ License: UNKNOWN
9
+ Platform: UNKNOWN
7
10
  Classifier: Programming Language :: Python :: 3
8
11
  Classifier: License :: OSI Approved :: MIT License
9
12
  Classifier: Operating System :: OS Independent
10
- Requires-Dist: requests
13
+
14
+ UNKNOWN
15
+
@@ -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,55 @@
1
+ import socket
2
+ import requests
3
+ import time
4
+ import os
5
+
6
+ def register_demo(debug=False):
7
+ for attempt in range(10):
8
+ try:
9
+ local_ip = socket.gethostbyname(socket.gethostname())
10
+ response = requests.post(
11
+ "http://hocmay-svc/aiplatform-api/demo/register/",
12
+ json={"demo_ip": local_ip},
13
+ headers={"Content-Type": "application/json"}
14
+ )
15
+ if response.ok:
16
+ url, namespace = create_url()
17
+ # print(f"The demo service is at {namespace}.your_custorm_domain/demo/. Eg: {url}")
18
+ print(f"The demo service is at {url}")
19
+ if debug:
20
+ print("IP registered successfully.")
21
+ return True
22
+ else:
23
+ if debug:
24
+ print(f"Attempt {attempt + 1}: Failed: {response.text}")
25
+ except (socket.error, requests.exceptions.RequestException) as e:
26
+ if debug: # Print errors only if debug is True
27
+ print(f"Attempt {attempt + 1}: Error: {e}")
28
+
29
+ time.sleep(2) # Wait for 2 seconds before retrying
30
+
31
+ if debug:
32
+ print("Failed to register IP after 10 attempts.")
33
+ return False
34
+
35
+
36
+
37
+ def create_url(domain_name = "aiplatform.vcntt.tech"):
38
+ # Define the static domain name
39
+
40
+ # Read the KERNEL_NAMESPACE environment variable
41
+ kernel_namespace = os.getenv("KERNEL_NAMESPACE")
42
+
43
+ # Validate the environment variable
44
+ if not kernel_namespace:
45
+ kernel_namespace="undefined"
46
+
47
+ # Replace 'machinelearning' with 'appmachinepublic' in KERNEL_NAMESPACE
48
+ if kernel_namespace.startswith("machinelearning"):
49
+ transformed_namespace = kernel_namespace.replace("machinelearning", "appmachinepublic", 1)
50
+ else:
51
+ raise ValueError(f"The KERNEL_NAMESPACE '{kernel_namespace}' does not follow the expected format.")
52
+
53
+ # Create the final URL
54
+ url = f"https://{transformed_namespace}.{domain_name}/demo/"
55
+ return url, transformed_namespace
@@ -1,10 +1,15 @@
1
1
  Metadata-Version: 2.1
2
- Name: aap_utils
3
- Version: 0.1
2
+ Name: aap-utils
3
+ Version: 0.1.2
4
4
  Summary: A Python library for registering an IP address for AAP
5
+ Home-page: UNKNOWN
5
6
  Author: Minh Dang
6
7
  Author-email: danghoangminh86@gmail.com
8
+ License: UNKNOWN
9
+ Platform: UNKNOWN
7
10
  Classifier: Programming Language :: Python :: 3
8
11
  Classifier: License :: OSI Approved :: MIT License
9
12
  Classifier: Operating System :: OS Independent
10
- Requires-Dist: requests
13
+
14
+ UNKNOWN
15
+
@@ -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.2",
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