def __init__(self, **kwargs): kc_args = {} if kwargs.get('endpoint'): kc_args['endpoint'] = kwargs.get('endpoint') if kwargs.get('token'): kc_args['token'] = kwargs.get('token') print kc_args self.glclient = glanceClient('1', **kc_args) self.glclient2 = glanceClient('2', **kc_args) self.dockerimages = []
def create_image(self): config = self.config.get('environment') glance_config = config.get('glance') self.get_auth() token = self.auth.get_token(self.session) glance = glanceClient('1', endpoint=glance_config['endpoint'], token=token) #images = glance.images.list() for image in glance_config['images']: image_url = glance_config['images'][image].split('/') image_name = image_url[len(image_url) - 1].split('.img') glance.images.create(name=image, disk_format="qcow2", container_format="bare", location=glance_config['images'][image])
def getGlanceClient(auth_url, username, password, project_name, user_domain_name, project_domain_name): auth = v3.Password(auth_url= auth_url, username = username, password= password, project_name = project_name, user_domain_name = user_domain_name, project_domain_name = project_domain_name) sess = session.Session(auth=auth) glance = glanceClient("2", session=sess) return glance
class GlanceHealthCheck(): def __init__(self, ks, nv): self.imageURL = "http://cloud-images.ubuntu.com/saucy/current/saucy-server-cloudimg-amd64-disk1.img" self.imageFile = "/root/RPCHealthCheckImage.img" self.imageName = "RPCHealthCheckImage" self.snapName = "RPCHealthCheckSnapshot" self.image = None self.snapshot = None self.snapID = None self.client = None log(".", 1, "Glance Init:") try: from glanceclient import Client as glanceClient except ImportError, err: raise RPCHCError( "Unable to import python libraries for glance client. Please make sure python-glanceclient is installed." ) self.client = glanceClient( "1", endpoint=ks.service["image"]["endpoints"][0]["adminURL"], token=ks.token) try: self.image = nv.client.images.find(name=self.imageName) except novaExceptions.NotFound: pass else: log( "W", 2, "HealthCheck Image \"%s\" already exists with ID %s. Verify cleanup below." % (self.imageName, self.image.id)) log(".", 1, "Glance Init Complete") return
def get_glance_client(sess): """get OpenStack glance client""" return glanceClient('2', session=sess)