Added generic driver and neutron driver

Change-Id: I776d37ea63676faee003aa9c9902bb879b90b240
This commit is contained in:
Rajdeep Dua 2014-03-04 15:39:09 +05:30
parent b9ee4ae49c
commit 7611ac3520
2 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,26 @@
#!/usr/bin/env python
# Copyright (c) 2013 VMware, Inc. 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.
#
class DataSourceDriver(object):
def __init__(self, **creds):
raise NotImplementedError()
def get_all(self, type):
raise NotImplementedError()
def get_item(self, type, uuid):
raise NotImplementedError()

View File

@ -0,0 +1,74 @@
#!/usr/bin/env python
# Copyright (c) 2014 VMware, Inc. 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.
#
import logging
from neutronclient.v2_0 import client
logger = logging.getLogger(__name__)
class NeutronDriver(object):
USERNAME = "admin"
PASSWORD = "password"
AUTH_URL = "http://<IPADDRESS>/v2.0"
TENANT_NAME = "admin"
def __init__(self, **creds):
credentials = self._get_credentials()
self.neutron = client.Client(**credentials)
def update_from_datasource(self):
self.networks = self.neutron.list_networks()
def get_all(self, type):
if type == "networks":
return self.networks
def get_item(self, type, uuid):
raise NotImplementedError()
def _get_credentials(self):
d = {}
d['username'] = self.USERNAME
d['password'] = self.PASSWORD
d['auth_url'] = self.AUTH_URL
d['tenant_name'] = self.TENANT_NAME
return d
def main():
driver = NeutronDriver()
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
# create formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s -'
' %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
logger.info("Starting Neutron Sync Service")
driver.update_from_datasource()
logger.info("Sync completed")
logger.info("Networks %s" % driver.get_all("networks"))
if __name__ == '__main__':
try:
main()
except SystemExit:
# Let system.exit() calls complete normally
raise
except Exception:
raise