Exemplo n.º 1
0
    def __init__(self, config):
        global sess
        sess = session_create(config)
        self.keystone_client = keystone.Client(username=config['username'],
                                               password=config['password'],
                                               tenant_id=config['project'],
                                               auth_url=config['auth_url'],
                                               region_name=config['region_name'])

        heat_url = self.keystone_client \
            .service_catalog.url_for(service_type='orchestration',
                                     endpoint_type='publicURL')

        self.nova_client = nova.Client('2.1', region_name=config['region_name'], session=sess)
        self.cinder_client = cinder.Client('2', region_name=config['region_name'], session=sess)
        self.glance_client = glance.Client('2', region_name=config['region_name'], session=sess)
        self.neutron_client = neutron.Client(region_name=config['region_name'], session=sess)
        self.heat_client = heat.Client('1', region_name=config['region_name'], endpoint=heat_url, session=sess)

        functions = []
        threads = []
        self.print_servers = self.print_ips = self.print_scgps = self.print_keys = False
        self.print_volumes = self.print_snapshots = self.print_backups = False
        self.print_netowrks = self.print_routers = False
        self.print_images = self.print_owned_images = self.print_shared_imges = False
        self.print_cloudwatt_images = self.print_snapshots_images = False
        self.print_lbass = self.print_members = self.print_stacks = False

        def get_limits():
            try:
                self.nova_limits = self.nova_client.limits.get().to_dict()['absolute']
                self.cinder_limits = self.cinder_client.limits.get().to_dict()['absolute']
            except Exception as e:
                self.nova_limits = self.cinder_limits = []
                logging.error("Could not retrieve limits")

        functions.append(get_limits)

        def get_servers():
            try:
                self.flavors_dict = {}
                self.servers = map(lambda x: x.to_dict(), self.nova_client.servers.list())
                map(lambda x: self.flavors_dict.update({x.id: x}), self.nova_client.flavors.list())
            except Exception as e:
                self.servers = []
                logging.error("Could not retrieve list of servers")

        functions.append(get_servers)

        def get_floating_ips():
            try:
                self.ips = self.nova_client.floating_ips.list()
            except Exception as e:
                self.ips = []
                logging.error("Could not retrieve list of floating IPs")

        functions.append(get_floating_ips)

        def get_securitygps():
            try:
                self.securitygps = map(lambda x: x.to_dict(), self.nova_client \
                                       .security_groups.list())
            except Exception as e:
                self.securitygps = []
                logging.error("Could not retrieve list of security groups")

        functions.append(get_securitygps)

        def get_keys():
            try:
                self.keys = self.nova_client.keypairs.list()
            except Exception as e:
                self.keys = []
                logging.error("Could not retrieve list of keys")

        functions.append(get_keys)

        def get_images(project_id=config['project']):
            try:
                self.images_dict = {}
                self.images = []
                for image in self.glance_client.images.list():
                    self.images.append(image)
                copy_images = self.images
                map(lambda x: self.images_dict.update({x.id: x}), copy_images)
            except Exception as e:
                logging.error("Could not retrieve list of images")

        functions.append(get_images)

        def get_volumes():
            try:
                self.volumes = self.cinder_client.volumes.list()
            except Exception as e:
                self.volumes = []
                logging.error("Could not retrieve list of volumes")

        functions.append(get_volumes)

        def get_volumes_snapshots():
            try:
                self.snapshots = self.cinder_client.volume_snapshots.list()
            except Exception as e:
                self.snapshots = []
                logging.error("Could not retrieve list of snapshots")

        functions.append(get_volumes_snapshots)

        def get_volumes_backups():
            try:
                self.backups = self.cinder_client.backups.list()
            except Exception as e:
                self.backups = []
                logging.error("Could not retrieve list of backups")

        functions.append(get_volumes_backups)

        def get_networks():
            try:
                self.routers = self.neutron_client.list_routers()['routers']
                self.networks = self.neutron_client.list_networks()['networks']
                self.subnets = self.neutron_client.list_subnets()['subnets']
            except Exception as e:
                self.routers = self.networks = self.subnets = []
                logging.error("Could not retrieve list of networks")

        functions.append(get_networks)

        def get_lbass():
            try:
                self.lbass = self.neutron_client.list_pools()['pools']
                self.members = self.neutron_client.list_members()['members']
            except Exception as e:
                self.lbass = self.members = []
                logging.error("Could not retrieve lbass")

        functions.append(get_lbass)

        def get_stacks():
            try:
                self.stacks = self.heat_client.stacks.list()
            except Exception as e:
                self.stacks = []
                logging.error("Could not retrieve list of stacks")

        functions.append(get_stacks)

        for func in functions:
            t = threading.Thread(name=func, target=func)
            threads.append(t)
            t.start()
        for t in threads:
            t.join()
Exemplo n.º 2
0
 def authenticate_glance_admin(self, keystone):
     """Authenticates admin user with glance."""
     self.log.debug('Authenticating glance admin...')
     ep = keystone.service_catalog.url_for(service_type='image',
                                           endpoint_type='adminURL')
     return glance_client.Client(ep, token=keystone.auth_token)
Exemplo n.º 3
0
 def __init__(self, session):
     self.client = glance_client.Client(
         endpoint=session.get_endpoint("image"),
         token=session.token,
         insecure=session.insecure)
     self.project_id = session.project_id
Exemplo n.º 4
0
 def setUp(self):
     super(UrlParameterTest, self).setUp()
     self.api = ParameterFakeAPI({})
     self.gc = client.Client("http://fakeaddress.com")
     self.gc.images = images.ImageManager(self.api)
Exemplo n.º 5
0
 def factory_fn(token, endpoint):
     endpoint = re.sub(r'v(\d)/?$', '', endpoint)
     return glance.Client(endpoint=endpoint,
                          token=token,
                          insecure=credential.https_insecure,
                          cacert=credential.https_cacert)
Exemplo n.º 6
0
 def test_versioned_endpoint_with_minor_revision(self):
     gc = client.Client("http://example.com/v1.1")
     self.assertEqual("http://example.com", gc.http_client.endpoint)
Exemplo n.º 7
0
 def test_versioned_endpoint(self):
     gc = client.Client("http://example.com/v1")
     self.assertEqual("http://example.com", gc.http_client.endpoint)
Exemplo n.º 8
0
import time

sys.path.append("../third_client")
import keystoneclient.v2_0.client as ksclient
import glanceclient.v2.client as glclient
import novaclient.client as novaclient
import neutronclient.v2_0.client as netclient
import cinderclient.client as cinclient
import glanceclient.v1.client as gloneclient

username = '******'
password = '******'
tenant_name = 'tenant-zzh'
auth_url = 'https://identity.az1.dc1.fusionsphere.com:443/identity/v2.0'
image_id = 'da149d99-b252-4164-9d06-32fddbf88d75'

def prn_obj(obj):
    print ', '.join(['%s:%s' % item for item in obj.__dict__.items()])

if __name__ == '__main__':
    keystone = ksclient.Client(auth_url = auth_url,username = username,password = password,
                         tenant_name = tenant_name,insecure=True)

    glance_endpoint = keystone.service_catalog.url_for(service_type='image',endpoint_type='publicURL')

    glance = gloneclient.Client(version = '1', endpoint = glance_endpoint, token = keystone.auth_token, insecure=True)
    
    image = glance.images.get(image = image_id)

    prn_obj(image)
Exemplo n.º 9
0
def get_glance_client(session):
    """Get neutron client
    """
    gl = glanceclient.Client(session=session)
    assert check_glance_client(gl) is True
    return gl