Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 71d2f58d authored by SIMONIN Matthieu's avatar SIMONIN Matthieu
Browse files

Storage: Cleaner (client) endpoints

parent 4480e213
No related branches found
No related tags found
No related merge requests found
Pipeline #555284 failed
# 1.2.2
- Get cleaner (client) endpoinf for the storage API
# 1.2.1 # 1.2.1
- StorageHomeUser now uses id as __attr_id (fix an issue in `__repr__`) - StorageHomeUser now uses id as __attr_id (fix an issue in `__repr__`)
......
...@@ -366,42 +366,46 @@ In [2]: # gk is your entry point ...@@ -366,42 +366,46 @@ In [2]: # gk is your entry point
conf_file = os.path.join(os.environ.get("HOME"), ".python-grid5000.yaml") conf_file = os.path.join(os.environ.get("HOME"), ".python-grid5000.yaml")
gk = Grid5000.from_yaml(conf_file) gk = Grid5000.from_yaml(conf_file)
print(gk.sites["rennes"].storage["msimonin"].access.list()) print(gk.sites["rennes"].storage["home"].access["msimonin"].rules.list())
#+END_SRC #+END_SRC
*** Set storage accesses (e.g for vms) *** Set storage accesses (e.g for vms)
#+BEGIN_SRC python :exports code :tangle examples/storage_set.py #+BEGIN_SRC python :exports code :tangle examples/storage_set.py
from netaddr import IPNetwork from netaddr import IPNetwork
import logging import logging
import os import os
import time import time
from grid5000 import Grid5000 from grid5000 import Grid5000
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
conf_file = os.path.join(os.environ.get("HOME"), ".python-grid5000.yaml") conf_file = os.path.join(os.environ.get("HOME"), ".python-grid5000.yaml")
gk = Grid5000.from_yaml(conf_file) gk = Grid5000.from_yaml(conf_file)
site = gk.sites["rennes"] site = gk.sites["rennes"]
job = site.jobs.create({"name": "pyg5k", job = site.jobs.create({"name": "pyg5k",
"command": "sleep 3600", "command": "sleep 3600",
"resources": "slash_22=1+nodes=1"}) "resources": "slash_22=1+nodes=1"})
while job.state != "running": while job.state != "running":
job.refresh() job.refresh()
print("Waiting the job [%s] to be running" % job.uid) print("Waiting the job [%s] to be running" % job.uid)
time.sleep(5) time.sleep(5)
subnet = job.resources_by_type['subnets'][0]
ip_network = [str(ip) for ip in IPNetwork(subnet)]
subnet = job.resources_by_type['subnets'][0] # create acces for all ips in the subnet
ip_network = [str(ip) for ip in IPNetwork(subnet)] access = site.storage["home"].access["msimonin"].rules.create({"ipv4": ip_network,
"termination": {
"job": job.uid,
"site": site.uid}})
# create acces for all ips in the subnet # listing the accesses
access = site.storage["msimonin"].access.create({"ipv4": ip_network, print(gk.sites["rennes"].storage["home"].access["msimonin"].rules.list())
"termination": {"job": job.uid,
"site": site.uid}})
#+END_SRC #+END_SRC
** Vlan API ** Vlan API
......
...@@ -9,4 +9,4 @@ logging.basicConfig(level=logging.DEBUG) ...@@ -9,4 +9,4 @@ logging.basicConfig(level=logging.DEBUG)
conf_file = os.path.join(os.environ.get("HOME"), ".python-grid5000.yaml") conf_file = os.path.join(os.environ.get("HOME"), ".python-grid5000.yaml")
gk = Grid5000.from_yaml(conf_file) gk = Grid5000.from_yaml(conf_file)
print(gk.sites["rennes"].storage["msimonin"].access.list()) print(gk.sites["rennes"].storage["home"].access["msimonin"].rules.list())
...@@ -25,6 +25,10 @@ subnet = job.resources_by_type['subnets'][0] ...@@ -25,6 +25,10 @@ subnet = job.resources_by_type['subnets'][0]
ip_network = [str(ip) for ip in IPNetwork(subnet)] ip_network = [str(ip) for ip in IPNetwork(subnet)]
# create acces for all ips in the subnet # create acces for all ips in the subnet
access = site.storage["msimonin"].access.create({"ipv4": ip_network, access = site.storage["home"].access["msimonin"].rules.create({"ipv4": ip_network,
"termination": {"job": job.uid, "termination": {
"job": job.uid,
"site": site.uid}}) "site": site.uid}})
# listing the accesses
print(gk.sites["rennes"].storage["home"].access["msimonin"].rules.list())
...@@ -62,12 +62,21 @@ class Deployment(RESTObject, RefreshMixin): ...@@ -62,12 +62,21 @@ class Deployment(RESTObject, RefreshMixin):
) )
class StorageHomeUser(RESTObject): class StorageGroup(RESTObject):
_id_attr = "id" _id_attr = "uid"
_managers = (("access", "StorageGroupAccessManager"),)
class StorageGroupAccess(RESTObject):
pass
class StorageHome(RESTObject):
_managers = (("access", "StorageHomeUserManager"),) class StorageGroupAccessList(RESTObject):
_managers = (("rules", "StorageGroupAccessListRulesManager"),)
class StorageGroupAccessListRule(RESTObject):
_id_attr = "id"
class Node(RESTObject): class Node(RESTObject):
...@@ -117,7 +126,7 @@ class Site(RESTObject): ...@@ -117,7 +126,7 @@ class Site(RESTObject):
("network_equipments", "SiteNetworkEquipmentManager"), ("network_equipments", "SiteNetworkEquipmentManager"),
("servers", "ServerManager"), ("servers", "ServerManager"),
("status", "SiteStatusManager"), ("status", "SiteStatusManager"),
("storage", "StorageHomeManager"), ("storage", "StorageManager"),
("vlans", "VlanManager"), ("vlans", "VlanManager"),
("vlansnodes", "VlanNodeManager"), ("vlansnodes", "VlanNodeManager"),
("vlansusers", "VlanUserManager"), ("vlansusers", "VlanUserManager"),
...@@ -162,26 +171,46 @@ class NodeManager(RetrieveMixin, BracketMixin, RESTManager): ...@@ -162,26 +171,46 @@ class NodeManager(RetrieveMixin, BracketMixin, RESTManager):
_from_parent_attrs = {"site": "site", "cluster": "uid"} _from_parent_attrs = {"site": "site", "cluster": "uid"}
class StorageHomeManager(RESTManager): class StorageManager(RESTManager, BracketMixin):
_path = "/sites/%(site)s/storage/home" _path = "/sites/%(site)s/storage"
_obj_cls = StorageHome _obj_cls = StorageGroup
_from_parent_attrs = {"site": "uid"} _from_parent_attrs = {"site": "uid"}
# NOTE(msimonin): grr ... need to fix the return values because it's not # NOTE(msimonin): grr ... need to fix the return values because it's not
# consistent with the rest of API # consistent with the rest of API
# So we fake a return value # home access: /sites/site/storage/home/username/access
# group storage access: sites/site/server/storage/access (but here storage isn't fixed)
# we transform that in something more restful
# - sites["rennes"].storage["home"]
# - sites["rennes"].storage["storage1"]
# To get a specific Manager based on the storage location (home or group
# storage on a dedicated server)
# On which we can perform regular operations on the access endpoint
# - sites["rennes"].storage["home"].access.[list|create]
# - sites["rennes"].storage["storage1"].access.[list|create]
@exc.on_http_error(exc.Grid5000GetError) @exc.on_http_error(exc.Grid5000GetError)
def __getitem__(self, key): def __getitem__(self, key):
return self._obj_cls(self, {"uid": key}) return self._obj_cls(self, {"uid": key})
class StorageHomeUserManager(RESTManager): class StorageGroupAccessManager(RESTManager, BracketMixin):
_path = "/sites/%(site)s/storage/home/%(user)s/access" _path = "/sites/%(site)s/storage/%(server)s/"
_obj_cls = StorageHomeUser _obj_cls = StorageGroupAccessList
_from_parent_attrs = {"site": "site", "user": "uid"} _from_parent_attrs = {"site": "site", "server": "uid"}
@exc.on_http_error(exc.Grid5000GetError)
def __getitem__(self, key):
return self._obj_cls(self, {"uid": key})
class StorageGroupAccessListRulesManager(RESTManager, BracketMixin):
_path = "/sites/%(site)s/storage/%(server)s/%(storage)s/access"
_obj_cls = StorageGroupAccessListRule
_from_parent_attrs = {"site": "site", "server": "server", "storage": "uid"}
# NOTE(msimonin): grr ... need to fix the return values because it's not
# consistent with the rest of API
@exc.on_http_error(exc.Grid5000GetError) @exc.on_http_error(exc.Grid5000GetError)
def list(self, **kwargs): def list(self, **kwargs):
"""Retrieve a list of objects. """Retrieve a list of objects.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment