def details_server(self, _id=None, name=None): cs = self.list_cloudservers() for server in cs: if server.id == _id or server.name == name: pt = PrettyTable(['key', 'value']) # for csf in self.list_cloudservers_flavors(): # pt.add_row([csf.id, csf.name, csf.minDisk, csf.minRam]) # pt.align['key'] = 'r' pt.align['value'] = 'l' #TODO -- use the same technique with the other part of the library # print server attributes with introspection <=== <=== attrs_to_show = ['status', 'id'] for a in attrs_to_show: pt.add_row([a, getattr(server, a)]) #TODO -- display image info # pt.add_row(['image', self.get_cloudserver_flavor(server.image['id']).name]) pt.add_row(['flavor', self.get_cloudserver_flavor(server.flavor['id']).name]) # pt.add_row(['password', server.get_password()]) pt.add_row(['progress', server.progress]) # pt.add_row(['adminPass', server.get_password()]) for srv_net in server.networks['public']: pt.add_row(['network public (%s)' % get_ip_family(srv_net), srv_net]) for srv_net in server.networks['private']: pt.add_row(['network private (%s)' % get_ip_family(srv_net), srv_net]) pt.add_row(['created on', server.created]) print pt
def details_server(self, _id=None, name=None): cs = self.list_cloudservers() for server in cs: if server.id == _id or server.name == name: pt = PrettyTable(['key', 'value']) # for csf in self.list_cloudservers_flavors(): # pt.add_row([csf.id, csf.name, csf.minDisk, csf.minRam]) # pt.align['key'] = 'r' pt.align['value'] = 'l' #TODO -- use the same technique with the other part of the library # print server attributes with introspection <=== <=== attrs_to_show = ['status', 'id'] for a in attrs_to_show: pt.add_row([a, getattr(server, a)]) #TODO -- display image info # pt.add_row(['image', self.get_cloudserver_flavor(server.image['id']).name]) pt.add_row([ 'flavor', self.get_cloudserver_flavor(server.flavor['id']).name ]) # pt.add_row(['password', server.get_password()]) pt.add_row(['progress', server.progress]) # pt.add_row(['adminPass', server.get_password()]) for srv_net in server.networks['public']: pt.add_row([ 'network public (%s)' % get_ip_family(srv_net), srv_net ]) for srv_net in server.networks['private']: pt.add_row([ 'network private (%s)' % get_ip_family(srv_net), srv_net ]) pt.add_row(['created on', server.created]) self.r(0, str(pt), INFO)
def run(self): ''' create a server, wait for completion, aka server status in ('ACTIVE', 'ERROR', 'UNKNOWN') poll_time polling time waiting for completion in seconds ''' logging.debug("Starting %s" % self.threadID) statuses = ['ACTIVE', 'ERROR', 'UNKNOWN'] cs = pyrax.cloudservers server = cs.servers.create(self.name, self.image_id, self.flavor_id) logging.debug('polling server creation progress (%d)' % self.poll_time) while server.status not in statuses: if self._terminate == True: logging.debug("terminating thread %s" % self.name) return time.sleep(1) if int(time.time()) % self.poll_time == 0: # mitigate polling server creation progress server.get() logging.debug('server \'%s\', status:%s, progress:%s' % (server.name, server.status, server.progress)) msg_queue.put('server \'%s\': %s %s' % (server.name, server.status, server.progress)) if server.status == 'ACTIVE': d = { 'name': server.name, 'id': server.id, 'status': server.status, 'adminPass': server.adminPass, 'networks': server.networks } # print info pt = PrettyTable(['key', 'value']) pt.add_row(['name', d['name']]) pt.add_row(['id', d['id']]) pt.add_row(['status', d['status']]) pt.add_row(['adminPass', d['adminPass']]) for srv_net in d['networks']['public']: pt.add_row( ['network public (%s)' % get_ip_family(srv_net), srv_net]) for srv_net in server.networks['private']: pt.add_row( ['network private (%s)' % get_ip_family(srv_net), srv_net]) pt.align['key'] = 'l' pt.align['value'] = 'l' self.r(0, str(pt), INFO) print # return info else: cmd_out = ('Error. Cannot create server \'%s\' (status:%s)' % (server.name, server.status)) msg_queue.put(cmd_out) self.r(1, cmd_out, ERROR) return None logging.debug("Exiting %s" % self.name)
def run(self): ''' create a server, wait for completion, aka server status in ('ACTIVE', 'ERROR', 'UNKNOWN') poll_time polling time waiting for completion in seconds ''' logging.debug("Starting %s" % self.threadID) statuses = ['ACTIVE', 'ERROR', 'UNKNOWN'] cs = pyrax.cloudservers server = cs.servers.create(self.name, self.image_id, self.flavor_id) logging.debug('polling server creation progress (%d)' % self.poll_time) while server.status not in statuses: if self._terminate == True: logging.debug("terminating thread %s" % self.name) return time.sleep(1) if int(time.time()) % self.poll_time == 0: # mitigate polling server creation progress server.get() logging.debug('server \'%s\', status:%s, progress:%s' % (server.name, server.status, server.progress)) msg_queue.put('server \'%s\': %s %s' % (server.name, server.status, server.progress)) if server.status == 'ACTIVE': d = { 'name' : server.name, 'id' : server.id, 'status' : server.status, 'adminPass' : server.adminPass, 'networks' : server.networks } # print info pt = PrettyTable(['key', 'value']) pt.add_row(['name', d['name']]) pt.add_row(['id', d['id']]) pt.add_row(['status', d['status']]) pt.add_row(['adminPass', d['adminPass']]) for srv_net in d['networks']['public']: pt.add_row(['network public (%s)' % get_ip_family(srv_net), srv_net]) for srv_net in server.networks['private']: pt.add_row(['network private (%s)' % get_ip_family(srv_net), srv_net]) pt.align['key'] = 'l' pt.align['value'] = 'l' self.r(0, str(pt), INFO) print # return info else: cmd_out = ('Error. Cannot create server \'%s\' (status:%s)' % (server.name, server.status)) msg_queue.put(cmd_out) self.r(1, cmd_out, ERROR) return None logging.debug("Exiting %s" % self.name)