# Pastebin za9EdWoK #!/usr/bin/env python # # Copyright (c) 2017 SWITCH http://www.switch.ch # # 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. # Author: Saverio Proto """ Example usage: python floatingips-quota.py -d python floatingips-quota.py """ import os import sys sys.path.append('../lib') import argparse import openstackapi import keystoneclient import time def get_environ(key, verbose=False): if key not in os.environ: print "ERROR:", key, "not define in environment" sys.exit(1) if verbose: if 'password' in key.lower(): key_value = '*' * len(os.environ[key]) else: key_value = os.environ[key] print "{}: {}".format(key, key_value) return os.environ[key] def main(): """ Set floatingip quota as instance quota """ parser = argparse.ArgumentParser( description="Sync quotas") parser.add_argument('-d', '--dry-run', help='dry run', action="store_true",required=False) parser.add_argument('-v', '--verbose', help='verbose', action='store_true') args = parser.parse_args() # get OS_* environment variables os_auth_url = get_environ('OS_AUTH_URL', args.verbose) os_username = get_environ('OS_USERNAME', args.verbose) os_password = get_environ('OS_PASSWORD', args.verbose) os_tenant_name = get_environ('OS_TENANT_NAME', args.verbose) os_region_name = get_environ('OS_REGION_NAME', args.verbose) api = openstackapi.OpenstackAPI(os_auth_url, os_username, os_password, os_project_name=os_tenant_name) neutron = api.neutron(os_region_name) nova = api.nova(os_region_name) projects = api.keystone.projects.list() for p in projects: quota = nova.quotas.get(p.id).instances command = "neutron quota-update --floatingip %d --tenant-id %s" % (quota,p.id) if args.dry_run: print command else: os.system(command) if __name__ == '__main__': main()