Commit 598c2c35 authored by Balazs's avatar Balazs

removed dependencies that can be installed from git repositories

parent 7b60ecf7
{
"initialise":[
{
"name": "initialise.integer",
"type": "number",
"value": 1
}
],
"activate":[
{
"name": "activate.integer",
"type": "number",
"value": 1
},
{
"name": "activate.string",
"type": "string",
"value": "immutable_init_value"
},
{
"name": "activate.float",
"type": "number",
"value": 0.11
}
],
"deploy":[
{
"name": "deploy.init_value",
"value": "immutable_init_value",
"type": "string"
}
],
"provision":[
{
"name": "provision.init_value",
"value": "immutable_init_value",
"type": "string"
},
{
"name": "provision.value",
"value": 12,
"type": "number"
}
],
"update":[
{
"name": "update.init_value",
"value": "immutable_init_value",
"type": "string"
}
]
}
Metadata-Version: 1.0
Name: mcn_cc_sdk
Version: 1.2
Summary: MCN Service Development Kit
Home-page: http://www.intel.com
Author: Intel Performance Learning Solutions Ltd, Intel Corporation.
Author-email: thijs.metsch@intel.com
License: Apache 2.0
Description: UNKNOWN
Platform: UNKNOWN
# Copyright (c) 2013-2015, Intel Performance Learning Solutions Ltd, Intel Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
General SDK for easy deployment of service instances.
"""
# Copyright (c) 2013-2015, Intel Performance Learning Solutions Ltd, Intel Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
MCN specific helper package.
"""
# Copyright (c) 2013-2015, Intel Performance Learning Solutions Ltd, Intel Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Module for the Deployment of Service Instance.
"""
import uuid
from heatclient import client
HEAT_VERSION = '1'
class Deployer(object):
"""
Used to interact with the deployment module.
"""
def __init__(self, endpoint):
"""
Initializes helper for deployment.
:param endpoint: endpoint of the CC internal deployment service.
"""
pass
def deploy(self, template, token, **kwargs):
"""
Deploy the stack define by a template. Will return identifier for this
stack.
:param template: The template.
:param token: token for this request.
:param kwargs: Optional arguments.
"""
raise NotImplementedError()
def update(self, identifier, template, token, **kwargs):
"""
Updates an already deployed stack.
:param identifier: Identifier of a previously deployed stack.
:param token: token for this request.
:param kwargs: Optional arguments.
"""
raise NotImplementedError()
def dispose(self, identifier, token):
"""
Disposes an deployed stack.
:param identifier: Identifier of a previously deployed stack.
:param token: token for this request.
"""
raise NotImplementedError()
def get_template(self, identifier, token):
"""
Retrieves the template describing the current instantiation of
the stack.
:param identifier: Identifier of a previously deployed stack.
:param token: token for this request.
"""
raise NotImplementedError()
def details(self, identifier, token):
"""
Retrieve details of the stack.
:param identifier: Identifier of a previously deployed stack.
:param token: token for this request.
"""
raise NotImplementedError()
def check_output(self, field_name, identifier, token):
"""
Check the results of a specific field in the outputs dictionary.
None if not yet found.
:param field_name: Name of the field as defined in the template.
:param identifier: Identifier of a previously deployed stack.
:param token: token for this request.
"""
raise NotImplementedError()
class HeatDeployer(Deployer):
"""
Used to interact with the deployment module (in this case Heat).
"""
def __init__(self, endpoint):
"""
Initializes helper for deployment.
:param endpoint: endpoint of the CC internal deployment service.
"""
self.endpoint = endpoint
def deploy(self, template, token, **kwargs):
"""
Deploy the stack define by a template. Will return identifier for this
stack.
:param template: The template.
:param token: token for this request.
:param kwargs: Optional arguments.
"""
if 'name' in kwargs:
name = kwargs['name']
kwargs.pop('name')
else:
# needs to start with letter!
name = 'stack_' + str(uuid.uuid1())
heat = client.Client(HEAT_VERSION, self.endpoint, token=token,
**kwargs)
body = {'stack_name': name,
'template': template}
if 'parameters' in kwargs:
body['parameters'] = kwargs['parameters']
tmp = heat.stacks.create(**body)
return tmp['stack']['id']
def update(self, identifier, template, token, **kwargs):
"""
Updates an already deployed stack.
:param identifier: Identifier of a previously deployed stack.
:param token: token for this request.
:param kwargs: Optional arguments.
"""
heat = client.Client(HEAT_VERSION, self.endpoint, token=token,
**kwargs)
body = {'template': template}
if 'parameters' in kwargs:
body['parameters'] = kwargs['parameters']
heat.stacks.update(identifier, **body)
def dispose(self, identifier, token):
"""
Disposes an deployed stack.
:param identifier: Identifier of a previously deployed stack.
:param token: token for this request.
"""
heat = client.Client(HEAT_VERSION, self.endpoint, token=token)
return heat.stacks.delete(identifier)
def get_template(self, identifier, token):
"""
Retrieves the template describing the current instantiation of
the stack.
:param identifier: Identifier of a previously deployed stack.
:param token: token for this request.
"""
heat = client.Client(HEAT_VERSION, self.endpoint, token=token)
res = heat.stacks.template(identifier)
return res
def details(self, identifier, token):
"""
Retrieve details of the stack.
:param identifier: Identifier of a previously deployed stack.
:param token: token for this request.
"""
heat = client.Client(HEAT_VERSION, self.endpoint, token=token)
stk = heat.stacks.get(identifier).to_dict()
# FYI: stack states are here: http://docs.aws.amazon.com/
# AWSCloudFormation/latest/UserGuide/using-cfn-describing-stacks.html
res = {'state': stk['stack_status'],
'name': stk['stack_name'],
'id': stk['id']}
if 'outputs' in stk:
res['output'] = stk['outputs']
return res
def check_output(self, field_name, identifier, token):
"""
Check the results of a specific field in the outputs dictionary.
None if not yet found.
:param field_name: Name of the field as defined in the template.
:param identifier: Identifier of a previously deployed stack.
:param token: token for this request.
"""
res = None
heat = client.Client(HEAT_VERSION, self.endpoint, token=token)
stk = heat.stacks.get(identifier).to_dict()
if 'outputs' in stk:
for item in stk['outputs']:
if item['output_key'] == field_name:
res = item['output_value']
return res
class AWSDeployer(Deployer):
"""
Deploys on AWS public cloud.
"""
This diff is collapsed.
# Copyright (c) 2014, Technische Universitaet Berlin
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Module dealing with monitoring relate calls.
"""
import time
import requests
from zabbix_api import ZabbixAPI
class Monitoring(object):
"""
Wraps around the MaaS.
"""
def get_address(self, token):
"""
Returns MaaS_IP
:param token: a security token
"""
raise NotImplementedError()
def get_metric(self, host, item, **kwargs):
"""
Returns the last value of "item" from "host"
:param host: hostname of itemholder
:param item: itemname of wanted item
:param kwargs: optional arguments
:return:
"""
raise NotImplementedError()
class ZabbixMonitoring(Monitoring):
"""
Wraps around the MaaS.
"""
# class variables to implement those as a singleton
__location = None
__address = None
__tenant = None
@classmethod
def set_location(cls, arg):
"""
Sets classvariable __location
:param arg: new location
"""
if arg != cls.__location:
cls.__location = arg
@classmethod
def get_location(cls):
"""
Returns classvariable __location
"""
return cls.__location
@classmethod
def set_address(cls, arg):
"""
Sets classvariable __address
:param arg: new address
"""
if arg != cls.__address:
cls.__address = arg
@classmethod
def get_tenant(cls):
"""
Returns classvariable __tenant
"""
return cls.__tenant
@classmethod
def set_tenant(cls, arg):
"""
Sets classvariable __tenant
:param arg: new tenant
"""
if arg != cls.__tenant:
cls.__tenant = arg
def __init__(self, endpoint='http://localhost:8888/maas/'):
"""
Initializes helper for monitoring.
:param endpoint: Optional maassm uri
"""
self.__endpoint = endpoint
self.__tenant = None
def get_address(self, token):
"""
Returns MaaS_IP
:param token: a security token
"""
if self.get_location() is not None:
# get address and return
hdr = {'x-tenant-name': self.get_tenant(), 'x-auth-token': token}
response = requests.get(self.__location, headers=hdr)
# check if the stack is deployed yet, selfcall otherwise
if 'CREATE_COMPLETE' in response.content:
# TODO: clean the messy parsing
self.set_address(
[x for x in response.content.splitlines()
if 'mcn.endpoint.maas=' in x]
[-1].split('=')[-1].strip('"'))
return self.__address
else:
time.sleep(30)
return self.get_address(token)
else:
return None
def get_metric(self, host, item, **kwargs):
"""
Returns the last value of "item" from "host"
:param host: hostname of itemholder
:param item: itemname of wanted item
:param kwargs: Optional parameter
:return:
"""
if self.__address is not None:
if 'password' in kwargs:
password = kwargs['password']
else:
password = 'zabbix'
if 'username' in kwargs:
username = kwargs['username']
else:
username = 'admin'
zapi = ZabbixAPI(server='http://'+self.__address+'/zabbix',
path="", log_level=0)
zapi.login(username, password)
hostid = zapi.host.get({"filter": {"host": host}})[0]["hostid"]
item_values = zapi.item.get({"params": {"hostids": hostid},
"filter": {"name": item,
"hostid": hostid}})
return item_values[0]["lastvalue"]
else:
return None
# Copyright (c) 2013-2015, Intel Performance Learning Solutions Ltd, Intel Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Module providing basic OCCI typing.
In your SO do:
from sdk.mcn import occi_ext
class MyBackend(occi_ext.Backend):
def deploy_me(self, entity, attributes, extras):
entity.actions = [occi_ext.PROVISION_ACTION]
def provision_me(self, entity, attributes, extras):
entity.actions = []
application = occi_ext.Application(MyBackend())
"""
__author__ = 'tmetsch'
from occi import backend
from occi import core_model
from occi import wsgi
SCHEME = 'http://schemas.mobile-cloud-networking.eu/occi/service#'
DEPLOY_ACTION = core_model.Action(SCHEME, 'deploy')
PROVISION_ACTION = core_model.Action(SCHEME, 'provision')
ATTRS = {'occi.mcn.stack.state': 'immutable',
'occi.mcn.stack.id': 'immutable'}
ORCHESTRATOR = core_model.Kind(SCHEME, 'orchestrator',
related=[core_model.Resource.kind],
attributes=ATTRS,
actions=[DEPLOY_ACTION,
PROVISION_ACTION])
class Application(wsgi.Application):
"""
A OCCI Application.
"""
def __call__(self, environ, response):
"""
Pass in token.
"""
if 'HTTP_X_AUTH_TOKEN' not in environ:
status = '403 Forbidden'
headers = [('Content-type', 'text/plain')]
response(status, headers)
return 'X-Auth-Token required...'
if 'HTTP_X_TENANT_NAME' not in environ:
status = '403 Forbidden'
headers = [('Content-type', 'text/plain')]
response(status, headers)
return 'X-Tenant-Name required...'
return self._call_occi(environ, response,
token=environ['HTTP_X_AUTH_TOKEN'],
tenant_name=environ['HTTP_X_TENANT_NAME'])
def __init__(self, so_backend, backends=None):
"""
Initialize the OCCI app.
"""
super(Application, self).__init__()
self.register_backend(ORCHESTRATOR, so_backend)
self.register_backend(DEPLOY_ACTION, so_backend)
self.register_backend(PROVISION_ACTION, so_backend)
if isinstance(backends, dict) and len(backends) > 0:
for item in backends:
self.register_backend(item, backends[item])
class Backend(backend.KindBackend, backend.ActionBackend):
"""
A simple backend to be extended by SO implementers.
"""
def deploy_me(self, entity, attributes, extras):
"""
Deploy the SO instance.
:param entity: The OCCI resource entity.
:param attributes: The attributes given during the OCCI call.
"""
raise NotImplementedError()
def provision_me(self, entity, attributes, extras):
"""
Provision the SO instance.
:param entity: The OCCI resource entity.
:param attributes: The attributes given during the OCCI call.
"""
raise NotImplementedError()
def action(self, entity, action, attributes, extras):
"""
Handles OCCI actions.
"""
if action not in entity.actions:
raise AttributeError('Not applicable atm.')
elif action == DEPLOY_ACTION:
self.deploy_me(entity, attributes, extras)
elif action == PROVISION_ACTION:
self.provision_me(entity, attributes, extras)
\ No newline at end of file
# Copyright (c) 2013-2015, Intel Performance Learning Solutions Ltd, Intel Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Module for the Provisioning of Service Instance.
"""
__author__ = 'tmetsch'
import abc
import paramiko
class Provisioner(object):
"""
Module to allow for provisioning of SICs.
"""
@abc.abstractmethod
def provision(self, endpoint, artifacts):
"""
Provision an SIC.
:param endpoint: Endpoint of the SIC to be provisioned.
:param artifacts: description of the provisioning steps.
"""
raise NotImplementedError('To be implemented.')
class SshProvisioner(Provisioner):
"""
Example SSH based provsioner.
"""
def provision(self, endpoint, artifacts, **kwargs):
if 'look_for_keys' not in kwargs:
kwargs['look_for_keys'] = False
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(endpoint, **kwargs)
stdin, stdout, stderr = client.exec_command(artifacts)
return stdout.read()
# Copyright (c) 2013-2015, Intel Performance Learning Solutions Ltd, Intel Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Module can handle request to Auth service.
"""
from keystoneclient.v2_0 import client