def initialize_app(self, argv): self.LOG.debug('initialize_app') args = self.options if args.os_auth_token: if not args.os_auth_url: raise Exception('ERROR: please specify --os-auth-url') elif all([ args.os_auth_url, args.os_user_id or args.os_username, args.os_password, args.os_tenant_name or args.os_tenant_id or args.os_project_name or args.os_project_id ]): kwargs = dict() kwargs['auth_url'] = args.os_auth_url kwargs['password'] = args.os_password if args.os_user_id: kwargs['user_id'] = args.os_user_id if args.os_username: kwargs['username'] = args.os_username if args.os_tenant_id: kwargs['tenant_id'] = args.os_tenant_id if args.os_tenant_name: kwargs['tenant_name'] = args.os_tenant_name if args.os_cacert: kwargs['cacert'] = args.os_cacert if args.os_project_domain_name: kwargs['project_domain_name'] = args.os_project_domain_name self.cloud_obj = get_ext_cloud('openstack', **kwargs) elif os.path.isfile('/etc/ext_cloud/ext_cloud.conf'): # load from config file self.cloud_obj = get_ext_cloud('openstack') else: self.stderr.write(self.parser.format_usage()) raise Exception('ERROR: please specify authentication credentials')
def initialize_app(self, argv): self.LOG.debug('initialize_app') args = self.options if args.os_auth_token: if not args.os_auth_url: raise Exception('ERROR: please specify --os-auth-url') elif all([args.os_auth_url, args.os_user_id or args.os_username, args.os_password, args.os_tenant_name or args.os_tenant_id or args.os_project_name or args.os_project_id]): kwargs = dict() kwargs['auth_url'] = args.os_auth_url kwargs['password'] = args.os_password if args.os_user_id: kwargs['user_id'] = args.os_user_id if args.os_username: kwargs['username'] = args.os_username if args.os_tenant_id: kwargs['tenant_id'] = args.os_tenant_id if args.os_tenant_name: kwargs['tenant_name'] = args.os_tenant_name if args.os_cacert: kwargs['cacert'] = args.os_cacert self.cloud_obj = get_ext_cloud('openstack', **kwargs) elif os.path.isfile('/etc/ext_cloud/ext_cloud.conf'): # load from config file self.cloud_obj = get_ext_cloud('openstack') else: self.stderr.write(self.parser.format_usage()) raise Exception('ERROR: please specify authentication credentials')
#!/usr/bin/python from ext_cloud import get_ext_cloud from ext_cloud.BaseCloud.BaseCompute.BaseInstance import STATE import warnings warnings.filterwarnings("ignore") import sys cloud_obj = get_ext_cloud("openstack") services = cloud_obj.services.list_compute_services() down = 0 down_str = "" disabled = 0 disabled_str = "" for service in services: if service.state == 'down': down += 1 down_str += '[' + service.name + ':' + service.host + '] ' if service.status == 'disabled': disabled += 1 disabled_str += '[' + service.name + ':' + service.host + '] ' if not down and not disabled: sys.exit(0) msg = "" if down: msg += '{} compute service(s) down.[service name:host] {}'.format(down, down_str)
from os.path import dirname from sys import path from ext_cloud import get_ext_cloud basepath = dirname(__file__) basepath = basepath + "../../" path.append(basepath) # cloud_obj = get_ext_cloud("openstack",username='******', password='******', tenant_name='openstack', auth_url='http://10.233.52.56:5000/v2.0/', service_type='compute', region_name='regionOne') cloud_obj = get_ext_cloud("amazon", username='******', password='******', region_name='us-east-1') template = cloud_obj.templates.is_valid(file='/root/ext_cloud/Tests/Templates/AmazonBaseTemplate.template') print template
#!/usr/bin/python from ext_cloud import get_ext_cloud import warnings warnings.filterwarnings("ignore") import sys cloud_obj = get_ext_cloud("openstack") instances = cloud_obj.compute.get_instances_by_error_state() if len(instances) == 0: sys.exit(0) msg = '{} instance(s) in ERROR state.[Instance id: name] '.format(len(instances)) for instance in instances: msg += '[' + instance.id + ':' + instance.name + '] ' print msg sys.exit(1)
#!/usr/bin/python from ext_cloud import get_ext_cloud # cloud_obj = get_ext_cloud("openstack",username='******', password='******', tenant_name='openstack', auth_url='http://10.233.52.56:5000/v2.0/', service_type='compute', region_name='regionOne') cloud_obj = get_ext_cloud("amazon", username='******', password='******', region_name='us-east-1') # cloud_obj = get_ext_cloud("azure", subscription_id = 'cd42b929-848cd51f4c6c', certificate_path = './Tests/Azure/mycert.pem') instances = cloud_obj.compute.list_instances() for instance in instances: print instance
def get_cloud_obj(): from ext_cloud import get_ext_cloud return get_ext_cloud("openstack", username='******', password='******', tenant_name='admin', auth_url='http://192.168.3.130:5000/v2.0/')