Further cleanup
* README is now relevant * Auth now properly skipped with os-image-url and os-auth-token provided
This commit is contained in:
68
README.rst
68
README.rst
@@ -1,10 +1,8 @@
|
|||||||
Python bindings to the OpenStack Glance API
|
Python bindings to the OpenStack Image API
|
||||||
=============================================
|
=============================================
|
||||||
|
|
||||||
This is a client for the OpenStack Glance API. There's a Python API (the
|
This is a client for the Glance which uses the OpenStack Image API. There's a
|
||||||
``glanceclient`` module), and a command-line script (``glance``). The
|
Python API (the ``glanceclient`` module), and a command-line script (``glance``).
|
||||||
Glance 2.0 API is still a moving target, so this module will remain in
|
|
||||||
"Beta" status until the API is finalized and fully implemented.
|
|
||||||
|
|
||||||
Development takes place via the usual OpenStack processes as outlined in
|
Development takes place via the usual OpenStack processes as outlined in
|
||||||
the `OpenStack wiki`_. The master repository is on GitHub__.
|
the `OpenStack wiki`_. The master repository is on GitHub__.
|
||||||
@@ -12,10 +10,12 @@ the `OpenStack wiki`_. The master repository is on GitHub__.
|
|||||||
__ http://wiki.openstack.org/HowToContribute
|
__ http://wiki.openstack.org/HowToContribute
|
||||||
__ http://github.com/openstack/python-glanceclient
|
__ http://github.com/openstack/python-glanceclient
|
||||||
|
|
||||||
This code a fork of `Rackspace's python-novaclient`__ which is in turn a fork of
|
This code is based on `OpenStack's python-keystoneclient`__ which is based on
|
||||||
|
`Rackspace's python-novaclient`__ which is in turn a fork of
|
||||||
`Jacobian's python-cloudservers`__. The python-glanceclient is licensed under
|
`Jacobian's python-cloudservers`__. The python-glanceclient is licensed under
|
||||||
the Apache License like the rest of OpenStack.
|
the Apache License like the rest of OpenStack.
|
||||||
|
|
||||||
|
__ http://github.com/openstack/python-keystoneclient
|
||||||
__ http://github.com/rackspace/python-novaclient
|
__ http://github.com/rackspace/python-novaclient
|
||||||
__ http://github.com/jacobian/python-cloudservers
|
__ http://github.com/jacobian/python-cloudservers
|
||||||
|
|
||||||
@@ -25,11 +25,12 @@ __ http://github.com/jacobian/python-cloudservers
|
|||||||
Python API
|
Python API
|
||||||
----------
|
----------
|
||||||
|
|
||||||
By way of a quick-start::
|
If you wish to use the internal python api directly, you must obtain an auth
|
||||||
|
token and identify which endpoint you wish to speak to manually. Once you have
|
||||||
|
done so, you can use the API::
|
||||||
|
|
||||||
# use v2.0 auth with http://example.com:5000/v2.0")
|
|
||||||
>>> from glanceclient.v1 import client
|
>>> from glanceclient.v1 import client
|
||||||
>>> glance = client.Client(username=USERNAME, password=PASSWORD, tenant_name=TENANT, auth_url=KEYSTONE_URL)
|
>>> glance = client.Client(endpoint=OS_IMAGE_ENDPOINT, token=OS_AUTH_TOKEN)
|
||||||
>>> glance.images.list()
|
>>> glance.images.list()
|
||||||
>>> image = glance.images.create(name="My Test Image")
|
>>> image = glance.images.create(name="My Test Image")
|
||||||
>>> print image.status
|
>>> print image.status
|
||||||
@@ -48,54 +49,29 @@ Command-line API
|
|||||||
----------------
|
----------------
|
||||||
|
|
||||||
Installing this package gets you a command-line tool, ``glance``, that you
|
Installing this package gets you a command-line tool, ``glance``, that you
|
||||||
can use to interact with Glance's Identity API.
|
can use to interact with Glance through the OpenStack Image API.
|
||||||
|
|
||||||
You'll need to provide your OpenStack username, password, tenant, and auth
|
You'll need to provide your OpenStack username, password, tenant, and auth
|
||||||
endpoint. You can do this with the ``--tenant_id``, ``--username``,
|
endpoint. You can do this with the ``--os-tenant-id``, ``--os-username``,
|
||||||
``--password``, and ``--auth_url`` params, but it's easier to just set them
|
``--os-password``, and ``--os-auth-url`` params, but it's easier to just set them
|
||||||
as environment variables::
|
as environment variables::
|
||||||
|
|
||||||
export OS_TENANT_id=
|
|
||||||
export OS_USERNAME=user
|
export OS_USERNAME=user
|
||||||
export OS_PASSWORD=pass
|
export OS_PASSWORD=pass
|
||||||
export OS_AUTH_URL=http://example.com:5000/v2.0
|
export OS_TENANT_ID=b363706f891f48019483f8bd6503c54b
|
||||||
|
export OS_AUTH_URL=http://auth.example.com:5000/v2.0
|
||||||
|
|
||||||
Since the Identity service that Glance uses can return multiple regional image
|
Since the Identity service that Glance uses can return multiple regional image
|
||||||
endpoints in the Service Catalog, you can specify the one you want with
|
endpoints in the Service Catalog, you can specify the one you want with
|
||||||
``--region_name`` (or ``export OS_REGION_NAME``).
|
``--region_name`` (or ``export OS_REGION_NAME``).
|
||||||
It defaults to the first in the list returned.
|
It defaults to the first in the list returned.
|
||||||
|
|
||||||
You'll find complete documentation on the shell by running
|
If you already have an auth token and endpoint, you may manually pass them
|
||||||
``glance help``::
|
in to skip automatic authentication with your identity service. Either define
|
||||||
|
them in command-line flags (``--os-image-url`` and ``--os-auth-token``) or in
|
||||||
|
environment variables::
|
||||||
|
|
||||||
usage: glance [--username USERNAME] [--password PASSWORD]
|
export OS_IMAGE_URL=http://glance.example.org:5000/v1
|
||||||
[--tenant_id TENANT_id]
|
export OS_AUTH_TOKEN=3bcc3d3a03f44e3d8377f9247b0ad155
|
||||||
[--auth_url AUTH_URL] [--region_name REGION_NAME]
|
|
||||||
<subcommand> ...
|
|
||||||
|
|
||||||
Command-line interface to the OpenStack Identity API.
|
You'll find complete documentation on the shell by running ``glance help``.
|
||||||
|
|
||||||
Positional arguments:
|
|
||||||
<subcommand>
|
|
||||||
catalog List all image services in service catalog
|
|
||||||
image-create Create new image
|
|
||||||
image-delete Delete image
|
|
||||||
image-list List images
|
|
||||||
image-update Update image's name and other properties
|
|
||||||
image-upload Upload an image file
|
|
||||||
image-download Download an image file
|
|
||||||
help Display help about this program or one of its
|
|
||||||
subcommands.
|
|
||||||
|
|
||||||
Optional arguments:
|
|
||||||
--username USERNAME Defaults to env[OS_USERNAME]
|
|
||||||
--password PASSWORD Defaults to env[OS_PASSWORD]
|
|
||||||
--tenant_name TENANT_NAME
|
|
||||||
Defaults to env[OS_TENANT_NAME]
|
|
||||||
--tenant_id TENANT_ID
|
|
||||||
Defaults to env[OS_TENANT_ID]
|
|
||||||
--auth_url AUTH_URL Defaults to env[OS_AUTH_URL]
|
|
||||||
--region_name REGION_NAME
|
|
||||||
Defaults to env[OS_REGION_NAME]
|
|
||||||
|
|
||||||
See "glance help COMMAND" for help on a specific command.
|
|
||||||
|
@@ -153,8 +153,8 @@ class OpenStackImagesShell(object):
|
|||||||
self.do_help(args)
|
self.do_help(args)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
auth_reqd = (utils.is_authentication_required(args.func) or
|
auth_reqd = (utils.is_authentication_required(args.func) and
|
||||||
not (args.os_auth_token and args.os_image_url))
|
not (args.os_auth_token and args.os_image_url))
|
||||||
|
|
||||||
if not auth_reqd:
|
if not auth_reqd:
|
||||||
endpoint = args.os_image_url
|
endpoint = args.os_image_url
|
||||||
|
5
setup.py
5
setup.py
@@ -20,7 +20,7 @@ def read(fname):
|
|||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="python-glanceclient",
|
name="python-glanceclient",
|
||||||
version="2012.1",
|
version="2012.1",
|
||||||
description="Client library for OpenStack Glance API",
|
description="Client library for OpenStack Image API",
|
||||||
long_description=read('README.rst'),
|
long_description=read('README.rst'),
|
||||||
url='https://github.com/openstack/python-glanceclient',
|
url='https://github.com/openstack/python-glanceclient',
|
||||||
license='Apache',
|
license='Apache',
|
||||||
@@ -36,8 +36,7 @@ setuptools.setup(
|
|||||||
'Operating System :: OS Independent',
|
'Operating System :: OS Independent',
|
||||||
'Programming Language :: Python',
|
'Programming Language :: Python',
|
||||||
],
|
],
|
||||||
#install_requires=requires,
|
install_requires=requires,
|
||||||
install_requires=[],
|
|
||||||
dependency_links=dependency_links,
|
dependency_links=dependency_links,
|
||||||
test_suite="nose.collector",
|
test_suite="nose.collector",
|
||||||
entry_points={'console_scripts': ['glance = glanceclient.shell:main']},
|
entry_points={'console_scripts': ['glance = glanceclient.shell:main']},
|
||||||
|
@@ -1,25 +1,21 @@
|
|||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
# Copyright 2012 OpenStack LLC
|
||||||
|
|
||||||
# Copyright 2010 United States Government as represented by the
|
|
||||||
# Administrator of the National Aeronautics and Space Administration.
|
|
||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
#
|
#
|
||||||
# Copyright 2010 OpenStack LLC.
|
# 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
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
# 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,
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
# implied.
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# See the License for the specific language governing permissions and
|
||||||
# License for the specific language governing permissions and limitations
|
# limitations under the License.
|
||||||
# under the License.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Installation script for Glance's development virtualenv
|
virtualenv installation script
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@@ -31,13 +27,19 @@ ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
|||||||
VENV = os.path.join(ROOT, '.venv')
|
VENV = os.path.join(ROOT, '.venv')
|
||||||
PIP_REQUIRES = os.path.join(ROOT, 'tools', 'pip-requires')
|
PIP_REQUIRES = os.path.join(ROOT, 'tools', 'pip-requires')
|
||||||
TEST_REQUIRES = os.path.join(ROOT, 'tools', 'test-requires')
|
TEST_REQUIRES = os.path.join(ROOT, 'tools', 'test-requires')
|
||||||
|
PY_VERSION = "python%s.%s" % (sys.version_info[0], sys.version_info[1])
|
||||||
|
|
||||||
|
|
||||||
def die(message, *args):
|
def die(message, *args):
|
||||||
print >> sys.stderr, message % args
|
print >>sys.stderr, message % args
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def check_python_version():
|
||||||
|
if sys.version_info < (2, 6):
|
||||||
|
die("Need Python Version >= 2.6")
|
||||||
|
|
||||||
|
|
||||||
def run_command(cmd, redirect_output=True, check_exit_code=True):
|
def run_command(cmd, redirect_output=True, check_exit_code=True):
|
||||||
"""
|
"""
|
||||||
Runs a command in an out-of-process shell, returning the
|
Runs a command in an out-of-process shell, returning the
|
||||||
@@ -56,94 +58,68 @@ def run_command(cmd, redirect_output=True, check_exit_code=True):
|
|||||||
|
|
||||||
|
|
||||||
HAS_EASY_INSTALL = bool(run_command(['which', 'easy_install'],
|
HAS_EASY_INSTALL = bool(run_command(['which', 'easy_install'],
|
||||||
check_exit_code=False).strip())
|
check_exit_code=False).strip())
|
||||||
HAS_VIRTUALENV = bool(run_command(['which', 'virtualenv'],
|
HAS_VIRTUALENV = bool(run_command(['which', 'virtualenv'],
|
||||||
check_exit_code=False).strip())
|
check_exit_code=False).strip())
|
||||||
|
|
||||||
|
|
||||||
def check_dependencies():
|
def check_dependencies():
|
||||||
"""Make sure virtualenv is in the path."""
|
"""Make sure virtualenv is in the path."""
|
||||||
|
|
||||||
|
print 'Checking for virtualenv...'
|
||||||
if not HAS_VIRTUALENV:
|
if not HAS_VIRTUALENV:
|
||||||
print 'not found.'
|
print 'not found.'
|
||||||
# Try installing it via easy_install...
|
# Try installing it via easy_install...
|
||||||
if HAS_EASY_INSTALL:
|
if HAS_EASY_INSTALL:
|
||||||
print 'Installing virtualenv via easy_install...',
|
print 'Installing virtualenv via easy_install...',
|
||||||
if not run_command(['which', 'easy_install']):
|
if not (run_command(['which', 'easy_install']) and
|
||||||
die('ERROR: virtualenv not found.\n\n'
|
run_command(['easy_install', 'virtualenv'])):
|
||||||
'Glance development requires virtualenv, please install'
|
die('ERROR: virtualenv not found.\n\nNova development'
|
||||||
' it using your favorite package management tool')
|
' requires virtualenv, please install it using your'
|
||||||
|
' favorite package management tool')
|
||||||
print 'done.'
|
print 'done.'
|
||||||
print 'done.'
|
print 'done.'
|
||||||
|
|
||||||
|
|
||||||
def create_virtualenv(venv=VENV):
|
def create_virtualenv(venv=VENV):
|
||||||
"""
|
"""Creates the virtual environment and installs PIP only into the
|
||||||
Creates the virtual environment and installs PIP only into the
|
|
||||||
virtual environment
|
virtual environment
|
||||||
"""
|
"""
|
||||||
print 'Creating venv...',
|
print 'Creating venv...',
|
||||||
run_command(['virtualenv', '-q', '--no-site-packages', VENV])
|
run_command(['virtualenv', '-q', '--no-site-packages', VENV])
|
||||||
print 'done.'
|
print 'done.'
|
||||||
print 'Installing pip in virtualenv...',
|
print 'Installing pip in virtualenv...',
|
||||||
if not run_command(['tools/with_venv.sh', 'easy_install',
|
if not run_command(['tools/with_venv.sh', 'easy_install', 'pip']).strip():
|
||||||
'pip>1.0']).strip():
|
|
||||||
die("Failed to install pip.")
|
die("Failed to install pip.")
|
||||||
print 'done.'
|
print 'done.'
|
||||||
|
|
||||||
|
|
||||||
def pip_install(*args):
|
|
||||||
run_command(['tools/with_venv.sh',
|
|
||||||
'pip', 'install', '--upgrade'] + list(args),
|
|
||||||
redirect_output=False)
|
|
||||||
|
|
||||||
|
|
||||||
def install_dependencies(venv=VENV):
|
def install_dependencies(venv=VENV):
|
||||||
print 'Installing dependencies with pip (this can take a while)...'
|
print 'Installing dependencies with pip (this can take a while)...'
|
||||||
|
run_command(['tools/with_venv.sh', 'pip', 'install', '-r',
|
||||||
pip_install('pip')
|
PIP_REQUIRES, '-r', TEST_REQUIRES], redirect_output=False)
|
||||||
|
|
||||||
pip_install('-r', PIP_REQUIRES)
|
|
||||||
pip_install('-r', TEST_REQUIRES)
|
|
||||||
|
|
||||||
# Tell the virtual env how to "import glance"
|
|
||||||
py_ver = _detect_python_version(venv)
|
|
||||||
pthfile = os.path.join(venv, "lib", py_ver, "site-packages", "glance.pth")
|
|
||||||
f = open(pthfile, 'w')
|
|
||||||
f.write("%s\n" % ROOT)
|
|
||||||
|
|
||||||
|
|
||||||
def _detect_python_version(venv):
|
|
||||||
lib_dir = os.path.join(venv, "lib")
|
|
||||||
for pathname in os.listdir(lib_dir):
|
|
||||||
if pathname.startswith('python'):
|
|
||||||
return pathname
|
|
||||||
raise Exception('Unable to detect Python version')
|
|
||||||
|
|
||||||
|
|
||||||
def print_help():
|
def print_help():
|
||||||
help = """
|
help = """
|
||||||
Glance development environment setup is complete.
|
Virtual environment configuration complete.
|
||||||
|
|
||||||
Glance development uses virtualenv to track and manage Python dependencies
|
To activate the virtualenv for the extent of your current shell
|
||||||
while in development and testing.
|
session you can run:
|
||||||
|
|
||||||
To activate the Glance virtualenv for the extent of your current shell session
|
$ source %s/bin/activate
|
||||||
you can run:
|
|
||||||
|
|
||||||
$ source .venv/bin/activate
|
Or, if you prefer, you can run commands in the virtualenv on a case by case
|
||||||
|
basis by running:
|
||||||
|
|
||||||
Or, if you prefer, you can run commands in the virtualenv on a case by case
|
$ tools/with_venv.sh <your command>
|
||||||
basis by running:
|
|
||||||
|
|
||||||
$ tools/with_venv.sh <your command>
|
""" % VENV
|
||||||
|
|
||||||
Also, make test will automatically use the virtualenv.
|
|
||||||
"""
|
|
||||||
print help
|
print help
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
|
check_python_version()
|
||||||
check_dependencies()
|
check_dependencies()
|
||||||
create_virtualenv()
|
create_virtualenv()
|
||||||
install_dependencies()
|
install_dependencies()
|
||||||
|
Reference in New Issue
Block a user