Commit 04394fdf by Fukász Rómeó Ervin

occi: implemented network and storage with the links

compute instances can now be modified
minor bug fixes
parent 17a73b8c
Pipeline #443 failed with stage
in 0 seconds
...@@ -358,6 +358,7 @@ LOCAL_APPS = ( ...@@ -358,6 +358,7 @@ LOCAL_APPS = (
'acl', 'acl',
'monitor', 'monitor',
'request', 'request',
'occi',
) )
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
......
# Copyright 2017 Budapest University of Technology and Economics (BME IK)
#
# This file is part of CIRCLE Cloud.
#
# CIRCLE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth import login from django.contrib.auth import login
class OcciAuthForm(AuthenticationForm): class OcciAuthForm(AuthenticationForm):
""" An authentication form for the OCCI implementation. """ """ An authentication form for the OCCI implementation. """
def __init__(self, request, *args, **kwargs): def __init__(self, request, *args, **kwargs):
super(OcciAuthForm, self).__init__(*args, **kwargs) super(OcciAuthForm, self).__init__(*args, **kwargs)
self.request = request self.request = request
......
# Copyright 2017 Budapest University of Technology and Economics (BME IK)
#
# This file is part of CIRCLE Cloud.
#
# CIRCLE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
import requests import requests
import json import json
# import urllib3 # import urllib3
...@@ -16,6 +33,7 @@ loginData = {"username": username, "password": password} ...@@ -16,6 +33,7 @@ loginData = {"username": username, "password": password}
# Csinalunk egy sessiont, hogy a cookie ami az auth-ert felelos # Csinalunk egy sessiont, hogy a cookie ami az auth-ert felelos
# automatikusan benne maradjon az osszes keresunkben # automatikusan benne maradjon az osszes keresunkben
with requests.Session() as session: with requests.Session() as session:
session.timeout = None
headers = {"Content-Type": "application/json", "Referer": server} headers = {"Content-Type": "application/json", "Referer": server}
# Csrf-Token a bejelentkezeshez # Csrf-Token a bejelentkezeshez
req = session.get(server + "occi/login/", headers=headers, req = session.get(server + "occi/login/", headers=headers,
...@@ -68,7 +86,7 @@ with requests.Session() as session: ...@@ -68,7 +86,7 @@ with requests.Session() as session:
vmid = json.loads(req.text)["resources"][0]["id"] vmid = json.loads(req.text)["resources"][0]["id"]
req = session.get(server + "occi/compute/" + vmid + "/", req = session.get(server + "occi/compute/" + vmid + "/",
headers=headers, verify=False) headers=headers, verify=False)
print("compute-"+str(vmid)) print("compute-" + str(vmid))
print("------------") print("------------")
print("status_code: " + str(req.status_code)) print("status_code: " + str(req.status_code))
print print
...@@ -100,12 +118,12 @@ with requests.Session() as session: ...@@ -100,12 +118,12 @@ with requests.Session() as session:
headers["X-CSRFToken"] = req.cookies['csrftoken'] headers["X-CSRFToken"] = req.cookies['csrftoken']
except: except:
pass pass
actionatrs = {"method": "cold"} actionatrs = {"method": "warm"}
actioninv = {"action": action + "restart", "attributes": actionatrs} actioninv = {"action": action + "restart", "attributes": actionatrs}
req = session.post(server + "occi/compute/" + vmid + "/", req = session.post(server + "occi/compute/" + vmid + "/",
headers=headers, verify=False, headers=headers, verify=False,
data=json.dumps(actioninv)) data=json.dumps(actioninv))
print("compute-"+str(vmid) + "-restart") print("compute-" + str(vmid) + "-restart")
print("-----------------") print("-----------------")
print("status_code: " + str(req.status_code)) print("status_code: " + str(req.status_code))
print print
...@@ -118,12 +136,12 @@ with requests.Session() as session: ...@@ -118,12 +136,12 @@ with requests.Session() as session:
headers["X-CSRFToken"] = req.cookies['csrftoken'] headers["X-CSRFToken"] = req.cookies['csrftoken']
except: except:
pass pass
actioninv["action"] = action + "suspend" actioninv["action"] = action + "stop"
actioninv["attributes"]["method"] = "suspend" actioninv["attributes"]["method"] = "graceful"
req = session.post(server + "occi/compute/" + vmid + "/", req = session.post(server + "occi/compute/" + vmid + "/",
headers=headers, verify=False, headers=headers, verify=False,
data=json.dumps(actioninv)) data=json.dumps(actioninv))
print("compute-" + str(vmid) + "-suspend") print("compute-" + str(vmid) + "-stop")
print("-----------------") print("-----------------")
print("status_code: " + str(req.status_code)) print("status_code: " + str(req.status_code))
print print
...@@ -136,11 +154,11 @@ with requests.Session() as session: ...@@ -136,11 +154,11 @@ with requests.Session() as session:
headers["X-CSRFToken"] = req.cookies["csrftoken"] headers["X-CSRFToken"] = req.cookies["csrftoken"]
except: except:
pass pass
actioninv["action"] = action + "noaction" actioninv["action"] = action + "renew"
req = session.post(server + "occi/compute/" + vmid + "/", req = session.post(server + "occi/compute/" + vmid + "/",
headers=headers, verify=False, headers=headers, verify=False,
data=json.dumps(actioninv)) data=json.dumps(actioninv))
print("compute-" + str(vmid) + "-noaction") print("compute-" + str(vmid) + "-renew")
print("-------------------") print("-------------------")
print("status_code: " + str(req.status_code)) print("status_code: " + str(req.status_code))
print print
...@@ -186,6 +204,50 @@ with requests.Session() as session: ...@@ -186,6 +204,50 @@ with requests.Session() as session:
indent=4, separators=(",", ": "))) indent=4, separators=(",", ": ")))
print print
try:
headers["X-CSRFToken"] = req.cookies["csrftoken"]
except:
pass
req = session.get(server + "occi/network/1/", headers=headers,
verify=False)
print("storage")
print("-------")
print("status_code " + str(req.status_code))
print
print(json.dumps(json.loads(req.text), sort_keys=True,
indent=4, separators=(",", ": ")))
try:
headers["X-CSRFToken"] = req.cookies["csrftoken"]
except:
pass
req = session.post(server + "occi/network/1/", headers=headers,
verify=False, data=json.dumps({"action": "online"}))
print("storage")
print("-------")
print("status_code " + str(req.status_code))
print
print(json.dumps(json.loads(req.text), sort_keys=True,
indent=4, separators=(",", ": ")))
try:
headers["X-CSRFToken"] = req.cookies["csrftoken"]
except:
pass
req = session.post(server + "occi/compute/96/", headers=headers,
verify=False, data=json.dumps(
{
"attributes": {
"occi.compute.memory": 0.250
}
}))
print("computerehelelel")
print("-------")
print("status_code " + str(req.status_code))
print
print(json.dumps(json.loads(req.text), sort_keys=True,
indent=4, separators=(",", ": ")))
# Kijelentkezes # Kijelentkezes
req = session.get(server + "occi/logout/", headers=headers, req = session.get(server + "occi/logout/", headers=headers,
verify=False) verify=False)
......
# Copyright 2017 Budapest University of Technology and Economics (BME IK)
#
# This file is part of CIRCLE Cloud.
#
# CIRCLE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
""" Implementation of the OCCI - Core model classes """ """ Implementation of the OCCI - Core model classes """
...@@ -75,6 +93,7 @@ class Kind(Category): ...@@ -75,6 +93,7 @@ class Kind(Category):
class Action(Category): class Action(Category):
""" OCCI 1.2 - CORE - Classification - Action """ """ OCCI 1.2 - CORE - Classification - Action """
def __init(self, *args, **kwargs): def __init(self, *args, **kwargs):
super(Action, self).__init__(*args, **kwargs) super(Action, self).__init__(*args, **kwargs)
......
# Copyright 2017 Budapest University of Technology and Economics (BME IK)
#
# This file is part of CIRCLE Cloud.
#
# CIRCLE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
""" Required instances of the OCCI classes """ """ Required instances of the OCCI classes """
from vm.models.instance import InstanceTemplate from vm.models.instance import InstanceTemplate
...@@ -211,21 +229,46 @@ CREDENTIALS_ATTRIBUTES = [ ...@@ -211,21 +229,46 @@ CREDENTIALS_ATTRIBUTES = [
"connect to the compute instance."), "connect to the compute instance."),
] ]
CREDENTIALS_MIXIN = Mixin("http://circlecloud.org/occi/infrastructure#", CREDENTIALS_MIXIN = Mixin("http://circlecloud.org/occi/infrastructure/" +
"compute#",
"credentials", "credentials",
title="Credentials Mixin", title="Credentials Mixin",
attributes=CREDENTIALS_ATTRIBUTES, attributes=CREDENTIALS_ATTRIBUTES,
applies="http://schemas.ogf.org/occi/" + applies="http://schemas.ogf.org/occi/" +
"infrastructure#compute") "infrastructure#compute")
LEASETIME_ATTRIBUTES = [
Attribute("org.circlecloud.occi.leasetime.suspend", "String", False,
False, description="The time remaining until the compute " +
"instance is suspended."),
Attribute("org.circlecloud.occi.leasetime.remove", "String", False,
False, description="The time remaining until the compute " +
"instance is deleted."),
]
LEASETIME_ACTIONS = [
Action("http://circlecloud.org/occi/infrastructure/compute/action#",
"renew", title="Renew the lease time of the compute instance."),
]
LEASETIME_MIXIN = Mixin("http://circlecloud.org/occi/infrastucture/compute#",
"leasetime",
title="Compute Lease Time Mixin",
attributes=LEASETIME_ATTRIBUTES,
actions=LEASETIME_ACTIONS,
applies="http://schemas.ogf.org/occi/infrastructure" +
"#compute")
OS_TPL_MIXIN = Mixin("http://schemas.ogf.org/occi/infrastructure#", OS_TPL_MIXIN = Mixin("http://schemas.ogf.org/occi/infrastructure#",
"os_tpl", "os_tpl",
title="OS Template") title="OS Template")
ACTION_ARRAYS = [ ACTION_ARRAYS = [
COMPUTE_ACTIONS, COMPUTE_ACTIONS,
# NETWORK_ACTIONS, NETWORK_ACTIONS,
# STORAGE_ACTIONS, STORAGE_ACTIONS,
LEASETIME_ACTIONS,
] ]
...@@ -235,9 +278,10 @@ def ALL_KINDS(): ...@@ -235,9 +278,10 @@ def ALL_KINDS():
RESOURCE_KIND, RESOURCE_KIND,
LINK_KIND, LINK_KIND,
COMPUTE_KIND, COMPUTE_KIND,
# NETWORK_KIND, NETWORK_KIND,
# STORAGE_KIND, STORAGE_KIND,
# NETWORKINTERFACE_KIND NETWORKINTERFACE_KIND,
STORAGELINK_KIND,
] ]
...@@ -255,10 +299,11 @@ def os_tpl_mixins(user): ...@@ -255,10 +299,11 @@ def os_tpl_mixins(user):
def ALL_MIXINS(user): def ALL_MIXINS(user):
mixins = [ mixins = [
# IPNETWORK_MIXIN, IPNETWORK_MIXIN,
# IPNETWORKINTERFACE_MIXIN, IPNETWORKINTERFACE_MIXIN,
CREDENTIALS_MIXIN, CREDENTIALS_MIXIN,
OS_TPL_MIXIN, OS_TPL_MIXIN,
LEASETIME_MIXIN,
] ]
template_mixins = os_tpl_mixins(user) template_mixins = os_tpl_mixins(user)
for template in template_mixins: for template in template_mixins:
......
# Copyright 2017 Budapest University of Technology and Economics (BME IK)
#
# This file is part of CIRCLE Cloud.
#
# CIRCLE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
"""" Utilities for the OCCI implementation of CIRCLE """ """" Utilities for the OCCI implementation of CIRCLE """
from django.http import HttpResponse from django.http import HttpResponse
...@@ -7,6 +25,7 @@ import json ...@@ -7,6 +25,7 @@ import json
class OcciException(Exception): class OcciException(Exception):
""" The superclass for OCCI exceptions. It creates a response to be """ The superclass for OCCI exceptions. It creates a response to be
returned when an error occures. """ returned when an error occures. """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
message = kwargs.get("message", "An error occured.") message = kwargs.get("message", "An error occured.")
status = kwargs.get("status", 400) status = kwargs.get("status", 400)
...@@ -17,6 +36,7 @@ class OcciException(Exception): ...@@ -17,6 +36,7 @@ class OcciException(Exception):
class OcciResourceInstanceNotExist(OcciException): class OcciResourceInstanceNotExist(OcciException):
""" An exception to be raised when a resource instance which has been """ An exception to be raised when a resource instance which has been
asked for does not exist. """ asked for does not exist. """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
if "message" not in kwargs: if "message" not in kwargs:
kwargs["message"] = "The resource instance does not exist." kwargs["message"] = "The resource instance does not exist."
...@@ -26,6 +46,7 @@ class OcciResourceInstanceNotExist(OcciException): ...@@ -26,6 +46,7 @@ class OcciResourceInstanceNotExist(OcciException):
class OcciActionInvocationError(OcciException): class OcciActionInvocationError(OcciException):
""" An exception to be raised when an action could not be invoked on """ An exception to be raised when an action could not be invoked on
an entity instance for some reason """ an entity instance for some reason """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
if "message" not in kwargs: if "message" not in kwargs:
kwargs["message"] = "Could not invoke action." kwargs["message"] = "Could not invoke action."
...@@ -35,6 +56,7 @@ class OcciActionInvocationError(OcciException): ...@@ -35,6 +56,7 @@ class OcciActionInvocationError(OcciException):
class OcciResourceCreationError(OcciException): class OcciResourceCreationError(OcciException):
""" An exception to be raised when a resource instance could not be """ An exception to be raised when a resource instance could not be
created for a reason. """ created for a reason. """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
if "message" not in kwargs: if "message" not in kwargs:
kwargs["message"] = "Could not create resource instance." kwargs["message"] = "Could not create resource instance."
...@@ -44,6 +66,7 @@ class OcciResourceCreationError(OcciException): ...@@ -44,6 +66,7 @@ class OcciResourceCreationError(OcciException):
class OcciResourceDeletionError(OcciException): class OcciResourceDeletionError(OcciException):
""" An exception to be raised when a resource instance could not be """ An exception to be raised when a resource instance could not be
deleted for some reason. """ deleted for some reason. """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
if "message" not in kwargs: if "message" not in kwargs:
kwargs["message"] = "Could not delete resource instance." kwargs["message"] = "Could not delete resource instance."
...@@ -53,6 +76,7 @@ class OcciResourceDeletionError(OcciException): ...@@ -53,6 +76,7 @@ class OcciResourceDeletionError(OcciException):
class OcciRequestNotValid(OcciException): class OcciRequestNotValid(OcciException):
""" An exception to be raised when the request sent by the client is """ An exception to be raised when the request sent by the client is
not valid for a reason. (e.g, wrong content type, etc.) """ not valid for a reason. (e.g, wrong content type, etc.) """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
if "message" not in kwargs: if "message" not in kwargs:
kwargs["message"] = "The request is not valid." kwargs["message"] = "The request is not valid."
......
# Copyright 2017 Budapest University of Technology and Economics (BME IK)
#
# This file is part of CIRCLE Cloud.
#
# CIRCLE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from django.conf.urls import url from django.conf.urls import url
from views import (OcciLoginView, OcciLogoutView, OcciQueryInterfaceView, from views import (OcciLoginView, OcciLogoutView, OcciQueryInterfaceView,
OcciComputeView, OcciComputeCollectionView) OcciComputeView, OcciComputeCollectionView,
OcciStorageView, OcciStorageCollectionView,
OcciNetworkView, OcciNetworkCollectionView)
urlpatterns = [ urlpatterns = [
...@@ -9,4 +29,8 @@ urlpatterns = [ ...@@ -9,4 +29,8 @@ urlpatterns = [
url(r'^-/$', OcciQueryInterfaceView.as_view()), url(r'^-/$', OcciQueryInterfaceView.as_view()),
url(r'^compute/$', OcciComputeCollectionView.as_view()), url(r'^compute/$', OcciComputeCollectionView.as_view()),
url(r'^compute/(?P<id>\d+)/$', OcciComputeView.as_view()), url(r'^compute/(?P<id>\d+)/$', OcciComputeView.as_view()),
url(r'^storage/$', OcciStorageCollectionView.as_view()),
url(r'^storage/(?P<id>\d+)/$', OcciStorageView.as_view()),
url(r'^network/$', OcciNetworkCollectionView.as_view()),
url(r'^network/(?P<id>\d+)/$', OcciNetworkView.as_view()),
] ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment