Initial OpenStack API support

This commit is contained in:
Dmitry Tantsur 2015-08-27 13:13:47 +02:00
parent 553ff0a0ff
commit 7e7b2af9ba
3 changed files with 86 additions and 1 deletions

54
metalsmith/deploy.py Normal file
View File

@ -0,0 +1,54 @@
# Copyright 2015 Red Hat, Inc.
#
# 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
import glanceclient
from keystoneclient.v2_0 import client as ks_client
from neutronclient.neutron import client as neu_client
LOG = logging.getLogger(__name__)
class API(object):
"""Various OpenStack API's."""
GLANCE_VERSION = '1'
NEUTRON_VERSION = '2.0'
def __init__(self, **kwargs):
LOG.debug('creating Keystone client')
self.keystone = ks_client.Client(**kwargs)
self.auth_token = self.keystone.auth_token
LOG.debug('creating service clients')
self.glance = glanceclient.Client(
self.GLANCE_VERSION, endpoint=self.get_endpoint('image'),
token=self.auth_token)
self.neutron = neu_client.Client(
self.NEUTRON_VERSION, endpoint_url=self.get_endpoint('network'),
token=self.auth_token)
def get_endpoint(self, service_type, endpoint_type='internalurl'):
service_id = self.keystone.services.find(type=service_type).id
endpoint = self.keystone.endpoints.find(service_id=service_id)
return getattr(endpoint, endpoint_type)
def deploy(profile, image):
"""Deploy an image on a given profile."""
LOG.debug('deploying image %(image)s on node with profile %(profile)s',
{'image': image, 'profile': profile})
API()

View File

@ -13,6 +13,36 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import logging
import sys
from metalsmith import deploy
LOG = logging.getLogger(__name__)
def main():
pass
parser = argparse.ArgumentParser(
description='Deployment and Scheduling tool for Bare Metal')
parser.add_argument('--debug', action='store_true',
help='output more logging')
parser.add_argument('-i', '--image', help='image to use (name or UUID)',
required=True)
parser.add_argument('profile', help='node profile to deploy')
args = parser.parse_args()
log_fmt = ('%(asctime)s %(levelname)s %(name)s: %(message)s' if args.debug
else '%(asctime)s %(message)s')
logging.basicConfig(
level=logging.DEBUG if args.debug else logging.INFO,
format=log_fmt)
try:
deploy.deploy(profile=args.profile, image=args.image)
except Exception as exc:
LOG.critical('%s', exc, exc_info=args.debug)
sys.exit(1)
else:
sys.exit(0)

View File

@ -1,4 +1,5 @@
pbr>=1.6,<2.0
python-glanceclient>=0.18.0
python-ironicclient>=0.6.0
python-keystoneclient>=1.6.0
python-neutronclient>=2.6.0,<3