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 = (
'acl',
'monitor',
'request',
'occi',
)
# 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 import login
class OcciAuthForm(AuthenticationForm):
""" An authentication form for the OCCI implementation. """
def __init__(self, request, *args, **kwargs):
super(OcciAuthForm, self).__init__(*args, **kwargs)
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 json
# import urllib3
......@@ -16,6 +33,7 @@ loginData = {"username": username, "password": password}
# Csinalunk egy sessiont, hogy a cookie ami az auth-ert felelos
# automatikusan benne maradjon az osszes keresunkben
with requests.Session() as session:
session.timeout = None
headers = {"Content-Type": "application/json", "Referer": server}
# Csrf-Token a bejelentkezeshez
req = session.get(server + "occi/login/", headers=headers,
......@@ -68,7 +86,7 @@ with requests.Session() as session:
vmid = json.loads(req.text)["resources"][0]["id"]
req = session.get(server + "occi/compute/" + vmid + "/",
headers=headers, verify=False)
print("compute-"+str(vmid))
print("compute-" + str(vmid))
print("------------")
print("status_code: " + str(req.status_code))
print
......@@ -100,12 +118,12 @@ with requests.Session() as session:
headers["X-CSRFToken"] = req.cookies['csrftoken']
except:
pass
actionatrs = {"method": "cold"}
actionatrs = {"method": "warm"}
actioninv = {"action": action + "restart", "attributes": actionatrs}
req = session.post(server + "occi/compute/" + vmid + "/",
headers=headers, verify=False,
data=json.dumps(actioninv))
print("compute-"+str(vmid) + "-restart")
print("compute-" + str(vmid) + "-restart")
print("-----------------")
print("status_code: " + str(req.status_code))
print
......@@ -118,12 +136,12 @@ with requests.Session() as session:
headers["X-CSRFToken"] = req.cookies['csrftoken']
except:
pass
actioninv["action"] = action + "suspend"
actioninv["attributes"]["method"] = "suspend"
actioninv["action"] = action + "stop"
actioninv["attributes"]["method"] = "graceful"
req = session.post(server + "occi/compute/" + vmid + "/",
headers=headers, verify=False,
data=json.dumps(actioninv))
print("compute-" + str(vmid) + "-suspend")
print("compute-" + str(vmid) + "-stop")
print("-----------------")
print("status_code: " + str(req.status_code))
print
......@@ -136,11 +154,11 @@ with requests.Session() as session:
headers["X-CSRFToken"] = req.cookies["csrftoken"]
except:
pass
actioninv["action"] = action + "noaction"
actioninv["action"] = action + "renew"
req = session.post(server + "occi/compute/" + vmid + "/",
headers=headers, verify=False,
data=json.dumps(actioninv))
print("compute-" + str(vmid) + "-noaction")
print("compute-" + str(vmid) + "-renew")
print("-------------------")
print("status_code: " + str(req.status_code))
print
......@@ -186,6 +204,50 @@ with requests.Session() as session:
indent=4, separators=(",", ": ")))
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
req = session.get(server + "occi/logout/", headers=headers,
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 """
......@@ -75,6 +93,7 @@ class Kind(Category):
class Action(Category):
""" OCCI 1.2 - CORE - Classification - Action """
def __init(self, *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 """
from vm.models.instance import InstanceTemplate
......@@ -211,21 +229,46 @@ CREDENTIALS_ATTRIBUTES = [
"connect to the compute instance."),
]
CREDENTIALS_MIXIN = Mixin("http://circlecloud.org/occi/infrastructure#",
CREDENTIALS_MIXIN = Mixin("http://circlecloud.org/occi/infrastructure/" +
"compute#",
"credentials",
title="Credentials Mixin",
attributes=CREDENTIALS_ATTRIBUTES,
applies="http://schemas.ogf.org/occi/" +
"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",
title="OS Template")
ACTION_ARRAYS = [
COMPUTE_ACTIONS,
# NETWORK_ACTIONS,
# STORAGE_ACTIONS,
NETWORK_ACTIONS,
STORAGE_ACTIONS,
LEASETIME_ACTIONS,
]
......@@ -235,9 +278,10 @@ def ALL_KINDS():
RESOURCE_KIND,
LINK_KIND,
COMPUTE_KIND,
# NETWORK_KIND,
# STORAGE_KIND,
# NETWORKINTERFACE_KIND
NETWORK_KIND,
STORAGE_KIND,
NETWORKINTERFACE_KIND,
STORAGELINK_KIND,
]
......@@ -255,10 +299,11 @@ def os_tpl_mixins(user):
def ALL_MIXINS(user):
mixins = [
# IPNETWORK_MIXIN,
# IPNETWORKINTERFACE_MIXIN,
IPNETWORK_MIXIN,
IPNETWORKINTERFACE_MIXIN,
CREDENTIALS_MIXIN,
OS_TPL_MIXIN,
LEASETIME_MIXIN,
]
template_mixins = os_tpl_mixins(user)
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 """
from django.http import HttpResponse
......@@ -7,6 +25,7 @@ import json
class OcciException(Exception):
""" The superclass for OCCI exceptions. It creates a response to be
returned when an error occures. """
def __init__(self, *args, **kwargs):
message = kwargs.get("message", "An error occured.")
status = kwargs.get("status", 400)
......@@ -17,6 +36,7 @@ class OcciException(Exception):
class OcciResourceInstanceNotExist(OcciException):
""" An exception to be raised when a resource instance which has been
asked for does not exist. """
def __init__(self, *args, **kwargs):
if "message" not in kwargs:
kwargs["message"] = "The resource instance does not exist."
......@@ -26,6 +46,7 @@ class OcciResourceInstanceNotExist(OcciException):
class OcciActionInvocationError(OcciException):
""" An exception to be raised when an action could not be invoked on
an entity instance for some reason """
def __init__(self, *args, **kwargs):
if "message" not in kwargs:
kwargs["message"] = "Could not invoke action."
......@@ -35,6 +56,7 @@ class OcciActionInvocationError(OcciException):
class OcciResourceCreationError(OcciException):
""" An exception to be raised when a resource instance could not be
created for a reason. """
def __init__(self, *args, **kwargs):
if "message" not in kwargs:
kwargs["message"] = "Could not create resource instance."
......@@ -44,6 +66,7 @@ class OcciResourceCreationError(OcciException):
class OcciResourceDeletionError(OcciException):
""" An exception to be raised when a resource instance could not be
deleted for some reason. """
def __init__(self, *args, **kwargs):
if "message" not in kwargs:
kwargs["message"] = "Could not delete resource instance."
......@@ -53,6 +76,7 @@ class OcciResourceDeletionError(OcciException):
class OcciRequestNotValid(OcciException):
""" An exception to be raised when the request sent by the client is
not valid for a reason. (e.g, wrong content type, etc.) """
def __init__(self, *args, **kwargs):
if "message" not in kwargs:
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 views import (OcciLoginView, OcciLogoutView, OcciQueryInterfaceView,
OcciComputeView, OcciComputeCollectionView)
OcciComputeView, OcciComputeCollectionView,
OcciStorageView, OcciStorageCollectionView,
OcciNetworkView, OcciNetworkCollectionView)
urlpatterns = [
......@@ -9,4 +29,8 @@ urlpatterns = [
url(r'^-/$', OcciQueryInterfaceView.as_view()),
url(r'^compute/$', OcciComputeCollectionView.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