Skip to content

Commit 5703dd2

Browse files
Merge pull request #51 from abcdesktopio/dev
Dev
2 parents e54712f + 968558f commit 5703dd2

File tree

13 files changed

+431
-167
lines changed

13 files changed

+431
-167
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ jobs:
2424
# this is the target build image
2525
# debian_bookworm -> debian and bookworm
2626
# alpine_latest -> alpine and latest
27-
distribs: [ debian_bookworm, alpine_latest ]
27+
# distribs: [ debian_bookworm, alpine_latest ]
28+
distribs: [ alpine_latest ]
2829
runs-on: ${{ matrix.platform-runs }}
2930

3031
steps:
@@ -100,7 +101,8 @@ jobs:
100101
strategy:
101102
fail-fast: false
102103
matrix:
103-
distribs: [ debian_bookworm, alpine_latest ]
104+
# distribs: [ debian_bookworm, alpine_latest ]
105+
distribs: [ alpine_latest ]
104106
steps:
105107
- name: Login to Docker Hub
106108
uses: docker/login-action@v3

Dockerfile.debian

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3
22

3-
LABEL org.opencontainers.image.description abcdesktop.pyos
3+
LABEL org.opencontainers.image.description=abcdesktop.pyos
44

55
# upgrade
66
RUN apt-get update && apt-get upgrade -y && apt-get clean && rm -rf /var/lib/apt/lists/*
@@ -55,7 +55,7 @@ RUN mkdir -p /usr/share/geolite2 && \
5555

5656
COPY --from=ghcr.io/abcdesktopio/ntlm_auth:debian_bookworm /dist/*.deb /tmp
5757
RUN apt-get update && \
58-
apt-get install -y --no-install-recommends /tmp/*.deb && \
58+
apt-get install -y --allow-downgrades /tmp/*.deb && \
5959
apt-get clean && \
6060
rm -rf /var/lib/apt/lists/*
6161
RUN echo /usr/lib/x86_64-linux-gnu/samba >> /etc/ld.so.conf.d/x86_64-linux-gnu.conf && /usr/sbin/ldconfig

controllers/composer_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def removecontainer(self):
195195
def listcontainer(self):
196196
self.logger.debug('')
197197
(auth, user ) = self.validate_env()
198-
result = oc.od.composer.listContainerApp(auth, user)
198+
result = oc.od.composer.listContainerApps(auth, user)
199199
return Results.success(result=result)
200200

201201
@cherrypy.expose

controllers/manager_controller.py

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ def handle_image_POST( self, json_images ):
426426
raise cherrypy.HTTPError(status=400, message='Invalid parameters Bad Request')
427427
return json_put
428428

429-
def handle_image_DELETE( self, image ):
429+
def handle_image_DELETE( self, image:str )->str:
430430
self.logger.debug('')
431431

432432
# image can be an sha_id or an repotag
@@ -447,7 +447,7 @@ def handle_image_DELETE( self, image ):
447447
cherrypy.response.status = 404
448448
return "Not found"
449449

450-
def handle_image_PATCH( self, image=None, json_images=None ):
450+
def handle_image_PATCH( self, image:str=None, json_images=None ):
451451
self.logger.debug('')
452452
# image can be an sha_id or an repotag
453453
# it is always a str type
@@ -502,7 +502,7 @@ def handle_desktop_GET( self, args ):
502502
desktop_name = args[0]
503503
if not isinstance( desktop_name, str):
504504
raise cherrypy.HTTPError(status=400, message='Invalid parameters Bad Request')
505-
505+
506506
if len(args)==1:
507507
# get information for a desktop
508508
# /API/manager/desktop/hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773
@@ -513,11 +513,28 @@ def handle_desktop_GET( self, args ):
513513
if args[1]=="resources_usage":
514514
# specify desktop
515515
if len(args)==2 :
516-
# list container for a desktop
516+
# resources_usage for a desktop
517517
# /API/manager/desktop/hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773/resources_usage
518518
resource = oc.od.composer.get_desktop_resources_usage(desktop_name)
519519
return resource
520520

521+
if args[1]=="pod":
522+
# /API/manager/desktop/hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773/pod/pod_id/resources_usage
523+
if len(args)==4 and args[3]=="resources_usage":
524+
#
525+
# args[0] -> desktop_name
526+
# args[1] -> pod
527+
# args[2] -> pod_name or pod_id
528+
# args[3] -> resources_usage
529+
# /API/manager/desktop/hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773/pod/pod_id/resources_usage
530+
pod_name = args[2]
531+
if not isinstance( pod_name, str):
532+
raise cherrypy.HTTPError(status=400, message='Invalid parameters Bad Request')
533+
self.logger.debug(f'get pod resources usage for {desktop_name} {pod_name}')
534+
resource = oc.od.composer.get_pod_resources_usage(desktop_name=desktop_name, pod_name=pod_name)
535+
return resource
536+
# /API/manager/desktop/hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773/container/container_id/resources_usage
537+
521538
if args[1]=="container":
522539
# /API/manager/desktop/hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773/container
523540
# specify desktop
@@ -535,6 +552,24 @@ def handle_desktop_GET( self, args ):
535552
# /API/manager/desktop/hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773/container/container_id
536553
container = oc.od.composer.describe_container( desktop_name, container=container_id )
537554
return container
555+
556+
if len(args)==4 and args[3]=="resources_usage":
557+
#
558+
# args[0] -> desktop_name
559+
# args[1] -> container
560+
# args[2] -> container_name or container_id
561+
# args[3] -> resources_usage
562+
# /API/manager/desktop/hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773/container/container_id/resources_usage
563+
container_name = args[2]
564+
if not isinstance( container_name, str):
565+
raise cherrypy.HTTPError(status=400, message='Invalid parameters Bad Request')
566+
self.logger.debug(f'get ephemeralcontainer resources usage for {desktop_name} {container_name}')
567+
# get ephemeralcontainer resources usage
568+
# /API/manager/desktop
569+
# /hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773/container/container_id/resources_usage
570+
resource = oc.od.composer.get_container_resources_usage(desktop_name=desktop_name, container_name=container_name)
571+
return resource
572+
# /API/manager/desktop/hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773/container/container_id/resources_usage
538573

539574
raise cherrypy.HTTPError(status=400, message='Invalid parameters Bad Request')
540575

@@ -548,19 +583,19 @@ def handle_desktop_DELETE( self, args ):
548583
desktop_name = args[0]
549584
if not isinstance( desktop_name, str):
550585
raise cherrypy.HTTPError(status=400, message='Invalid parameters Bad Request')
586+
551587
if len(args)==1:
552588
# delete a desktop
553589
# DELETE /API/manager/desktops/hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773
554590
delete_desktop = oc.od.composer.remove_desktop_byname(desktop_name)
555591
return delete_desktop
556592

557593
# use a specify desktop
558-
if len(args)==3 and args[1]=="container":
594+
if len(args)==3 and args[1] in [ "container", "pod" ] :
559595
# delete a container for a desktop
560596
# /API/manager/desktops/hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773/container/7f77381f778b1214c780762185a2a345ed00cfd1022f18cbd37902af041aff40
561597
container_id = args[2]
562-
oc.od.composer.stop_container_byname( desktop_name, container=container_id )
563-
oc.od.composer.remove_container_byname( desktop_name, container=container_id )
598+
stopped_container = oc.od.composer.stop_container_byname( desktop_name, container=container_id )
564599
return container_id
565600
raise cherrypy.HTTPError(status=400, message='Invalid parameters Bad Request')
566601

group

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ input:x:107:
4747
sgx:x:108:
4848
kvm:x:109:
4949
render:x:110:
50-
balloon:x:4096:
50+
_ssh:x:111:
51+
rdma:x:112:
52+
polkitd:x:999:
5153
nogroup:x:65534:
52-
render:x:110:
5354
ssh:x:4095:
5455
{{ gid }}:x:{{ gidNumber }}:{{ uid }}

gshadow

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
root:*::
1+
root:*::
22
daemon:*::
33
bin:*::
44
sys:*::
@@ -47,4 +47,6 @@ input:!::
4747
sgx:!::
4848
kvm:!::
4949
render:!::
50+
polkitd:!::
51+
rdma:!::
5052
{{ gid }}:!::{{ uid }}

oc/od/composer.py

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import oc.od.desktop
3131
import oc.od.services
3232
import oc.od.tracking
33+
34+
# type need for garbage collector
3335
from kubernetes.client.models.v1_pod_list import V1PodList
3436
from kubernetes.client.rest import ApiException
3537

@@ -203,37 +205,65 @@ def runwebhook( c, messageinfo=None ):
203205
def remove_desktop_byname( desktop_name:str ):
204206
myOrchestrator = selectOrchestrator()
205207
(authinfo, userinfo) = myOrchestrator.find_userinfo_authinfo_by_desktop_name( name=desktop_name )
208+
if not isinstance( authinfo, AuthInfo) or not isinstance( userinfo, AuthUser) :
209+
raise ODError( status=404, message='desktop not found')
206210
return removedesktop( authinfo, userinfo )
207211

208-
def stop_container_byname( desktop_name:str, container ):
212+
def stop_container_byname( desktop_name:str, container:str )->bool:
209213
myOrchestrator = selectOrchestrator()
210214
(authinfo, userinfo) = myOrchestrator.find_userinfo_authinfo_by_desktop_name( name=desktop_name )
211-
return myOrchestrator.stopContainerApp( authinfo, userinfo, container )
215+
if not isinstance( authinfo, AuthInfo) or not isinstance( userinfo, AuthUser) :
216+
raise ODError( status=404, message='desktop not found')
217+
return myOrchestrator.stopContainerApp( authinfo, userinfo, desktop_name, container )
212218

213219
def list_container_byname( desktop_name:str ):
214220
myOrchestrator = selectOrchestrator()
215-
(authinfo, userinfo) = myOrchestrator.find_userinfo_authinfo_by_desktop_name( name=desktop_name )
216-
return myOrchestrator.listContainerApp(authinfo, userinfo)
221+
(authinfo, userinfo, myDesktop) = myOrchestrator.find_userinfo_authinfo_desktop_by_desktop_name( name=desktop_name )
222+
if not isinstance( myDesktop, oc.od.desktop.ODDesktop) :
223+
raise ODError( status=404, message='desktop not found')
224+
if not isinstance( authinfo, AuthInfo) or not isinstance( userinfo, AuthUser) :
225+
raise ODError( status=404, message='desktop not found')
226+
return myOrchestrator.listContainerApps(authinfo, userinfo, myDesktop, services.apps )
217227

218228
def describe_desktop_byname( desktop_name:str ):
219229
myOrchestrator = selectOrchestrator()
220-
pod = myOrchestrator.describe_desktop_byname( desktop_name )
221-
return pod
230+
myPod = myOrchestrator.describe_desktop_byname( desktop_name )
231+
if not isinstance( myPod, dict ):
232+
raise ODError( status=404, message='desktop not found')
233+
return myPod
222234

223235
def describe_container_byname( desktop_name:str , container_id:str ):
224236
myOrchestrator = selectOrchestrator()
225237
container = myOrchestrator.describe_container( desktop_name, container_id )
226238
return container
227239

228-
def remove_container_byname(desktop_name: str, container_id:str):
240+
def remove_container_byname(desktop_name:str, container:str):
229241
myOrchestrator = selectOrchestrator()
230242
(authinfo, userinfo) = myOrchestrator.find_userinfo_authinfo_by_desktop_name( name=desktop_name )
231-
return myOrchestrator.removeContainerApp(authinfo,userinfo,container_id=container_id)
243+
if not isinstance( authinfo, AuthInfo) or not isinstance( userinfo, AuthUser) :
244+
raise ODError( status=404, message='desktop not found')
245+
return myOrchestrator.removeContainerApp(authinfo,userinfo,desktop_name,container)
246+
247+
def get_pod_resources_usage(desktop_name:str, pod_name:str):
248+
myOrchestrator = selectOrchestrator()
249+
(authinfo, userinfo) = myOrchestrator.find_userinfo_authinfo_by_desktop_name( name=desktop_name )
250+
if not isinstance( authinfo, AuthInfo) or not isinstance( userinfo, AuthUser) :
251+
raise ODError( status=404, message='desktop not found')
252+
return myOrchestrator.get_pod_resources_usage(authinfo,userinfo,pod_name=pod_name)
253+
254+
def get_container_resources_usage(desktop_name:str, container_name:str):
255+
myOrchestrator = selectOrchestrator()
256+
(authinfo, userinfo) = myOrchestrator.find_userinfo_authinfo_by_desktop_name( name=desktop_name )
257+
if not isinstance( authinfo, AuthInfo) or not isinstance( userinfo, AuthUser) :
258+
raise ODError( status=404, message='desktop not found')
259+
return myOrchestrator.get_container_resources_usage( authinfo, userinfo, container_name=container_name)
232260

233261
def get_desktop_resources_usage(desktop_name:str):
234262
myOrchestrator = selectOrchestrator()
235263
(authinfo, userinfo) = myOrchestrator.find_userinfo_authinfo_by_desktop_name( name=desktop_name )
236-
return myOrchestrator.getdesktop_resources_usage(authinfo,userinfo )
264+
if not isinstance( authinfo, AuthInfo) or not isinstance( userinfo, AuthUser) :
265+
raise ODError( status=404, message='desktop not found')
266+
return myOrchestrator.getdesktop_resources_usage(authinfo,userinfo)
237267

238268

239269
def fakednsquery( userid ):
@@ -378,7 +408,7 @@ def finddesktop( authinfo, userinfo ):
378408
return myDesktop
379409

380410

381-
def prepareressources( authinfo, userinfo ):
411+
def prepareressources( authinfo: AuthInfo, userinfo: AuthUser ):
382412
"""prepareressources for user from authinfo
383413
call Orchestrator.prepareressources
384414
@@ -390,7 +420,7 @@ def prepareressources( authinfo, userinfo ):
390420
myOrchestrator.prepareressources( authinfo=authinfo, userinfo=userinfo )
391421

392422

393-
def stopContainerApp(auth, user, podname, containerid):
423+
def stopContainerApp(authinfo: AuthInfo, userinfo: AuthUser, podname:str, containerid:str):
394424
"""stop container application if the container belongs to the user
395425
Args:
396426
authinfo (AuthInfo): authentification data
@@ -406,15 +436,15 @@ def stopContainerApp(auth, user, podname, containerid):
406436
logger.info('stopcontainer' )
407437
# new Orchestrator Object
408438
myOrchestrator = selectOrchestrator()
409-
myDesktop = myOrchestrator.findDesktopByUser( auth, user )
439+
myDesktop = myOrchestrator.findDesktopByUser( authinfo, userinfo )
410440
if not isinstance( myDesktop, oc.od.desktop.ODDesktop):
411441
raise ODError(status=404,message='stopcontainer::findDesktopByUser not found')
412442

413-
if not myOrchestrator.isPodBelongToUser( auth, user, podname ):
414-
services.fail2ban.fail_login( user.userid )
443+
if not myOrchestrator.isPodBelongToUser( authinfo, userinfo, podname ):
444+
services.fail2ban.fail_login( userinfo.userid )
415445
raise ODError( status=401, message='stopcontainer::invalid user')
416446

417-
result = myOrchestrator.stopContainerApp( auth, user, podname, containerid )
447+
result = myOrchestrator.stopContainerApp( authinfo, userinfo, podname, containerid )
418448
return result
419449

420450

@@ -468,7 +498,7 @@ def getldifsecretuserinfo( authinfo, userinfo ):
468498
secretuserinfo = myOrchestrator.getldifsecretuserinfo( authinfo, userinfo )
469499
return secretuserinfo
470500

471-
def listContainerApp(authinfo, userinfo):
501+
def listContainerApps(authinfo, userinfo):
472502
# new Orchestrator Object
473503
myOrchestrator = selectOrchestrator()
474504
myDesktop = myOrchestrator.findDesktopByUser( authinfo, userinfo )

oc/od/error.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
class ODError(Exception):
1818
def __init__(self, status:int=500, message:str=None ):
19+
self.status = status
1920
super().__init__(message)
2021

2122
class ODResourceNotFound(ODError):

0 commit comments

Comments
 (0)