Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions paddlecloud/paddlecloud/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,15 @@
# "admin_key": "/certs/admin.secret"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should contain type in this example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type => fstype
Done.

# }
#}
#for HostPath example:
#DATACENTERS = {
# ...
# "dc1":{
# "type": "hostpath",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe fstype is better?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

# "host_path": "/mnt/hdfs/",
# "mount_path" "/pfs/dc1/home/%s/" # mount_path % username
# }
#}
DATACENTERS = {
"datacenter1":{
"type": "cephfs",
Expand Down
5 changes: 2 additions & 3 deletions paddlecloud/paddlejob/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from paddle_job import PaddleJob
from cephfs_volume import CephFSVolume

__all__ = ["CephFSVolume", "PaddleJob"]
import volumes
__all__ = ["volumes", "PaddleJob"]
2 changes: 1 addition & 1 deletion paddlecloud/paddlejob/paddle_job.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import kubernetes
from kubernetes import client, config
import os
from cephfs_volume import CephFSVolume
from volumes import *

__all__ = ["PaddleJob"]
DEFAULT_PADDLE_PORT=7164
Expand Down
26 changes: 17 additions & 9 deletions paddlecloud/paddlejob/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from django.conf import settings
from kubernetes import client, config
from kubernetes.client.rest import ApiException
from . import PaddleJob, CephFSVolume
from . import PaddleJob
from volumes import CephFSVolume, HostPathVolume
from rest_framework.authtoken.models import Token
from rest_framework import viewsets, generics, permissions
from rest_framework.response import Response
Expand Down Expand Up @@ -40,14 +41,21 @@ def post(self, request, format=None):
dc = obj.get("datacenter")
volumes = []
for name, cfg in settings.DATACENTERS.items():
if cfg["type"] == "cephfs":
volumes.append(CephFSVolume(
monitors_addr = cfg["monitors_addr"],
user = cfg["user"],
secret_name = cfg["secret"],
mount_path = cfg["mount_path"] % username,
cephfs_path = cfg["cephfs_path"] % username
))
if dc == name:
if cfg["type"] == "cephfs":
volumes.append(CephFSVolume(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if monitors_addr user secret exists. Return an error code when parameters not found.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These parameters are in settings.py, I think we can check the configurations at the start-up phase of the cloud server. And maybe implement this feature in another PR is suitable.

monitors_addr = cfg["monitors_addr"],
user = cfg["user"],
secret_name = cfg["secret"],
mount_path = cfg["mount_path"] % username,
cephfs_path = cfg["cephfs_path"] % username
))
elif cfg["type"] == "hostpath":
volumes.append(HostPathVolume(
name = dc.replace("_", "-"),
host_path = cfg["host_path"],
mount_path = cfg["mount_path"] % username
))


paddle_job = PaddleJob(
Expand Down
4 changes: 4 additions & 0 deletions paddlecloud/paddlejob/volumes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from cephfs_volume import CephFSVolume
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems package volume is too small to exist. We can have:

def get_volume_config(**kwargs):
    __check_parameters(kwargs)
    tmpl = __get_template(kwargs["type"])
    return json.loads(__render(tmpl, kwargs))

Copy link
Collaborator Author

@Yancey0623 Yancey0623 May 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!I have use templates instead of package volume.Thanks a lot!
Done.

from hostpath_volume import HostPathVolume

__all__ = ["CephFSVolume", "HostPathVolume"]
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
from volume import Volume
__all__ = ["CephFSVolume"]


class Volume(object):
def __init__(self):
pass

@property
def volume(self):
return {}

@property
def volume_mount(self):
return {}

class CephFSVolume(Volume):
def __init__(self, monitors_addr, user, secret_name, mount_path, cephfs_path):
self._monitors = monitors_addr
Expand Down
23 changes: 23 additions & 0 deletions paddlecloud/paddlejob/volumes/hostpath_volume.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from volume import Volume
__all__ = ["HostPathVolume"]
class HostPathVolume(Volume):
def __init__(self, name, host_path, mount_path):
self._name = name
self._host_path = host_path
self._mount_path = mount_path

@property
def volume(self):
return {
"name": self._name,
"hostPath": {
"path": self._host_path
}
}

@property
def volume_mount(self):
return {
"name": self._name,
"mountPath": self._mount_path
}
12 changes: 12 additions & 0 deletions paddlecloud/paddlejob/volumes/volume.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

class Volume(object):
def __init__(self):
pass

@property
def volume(self):
return {}

@property
def volume_mount(self):
return {}