<s> from django . core import urlresolvers <EOL> from django . template . defaultfilters import title <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from horizon import exceptions <EOL> from horizon import tables <EOL> from horizon . templatetags import sizeformat <EOL> from horizon . utils import filters <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . dashboards . project . database_backups import tables as backup_tables <EOL> ACTIVE_STATES = ( "<STR_LIT>" , ) <EOL> class TerminateInstance ( tables . BatchAction ) : <EOL> name = "<STR_LIT>" <EOL> action_present = _ ( "<STR_LIT>" ) <EOL> action_past = _ ( "<STR_LIT>" ) <EOL> data_type_singular = _ ( "<STR_LIT>" ) <EOL> data_type_plural = _ ( "<STR_LIT>" ) <EOL> classes = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def action ( self , request , obj_id ) : <EOL> api . trove . instance_delete ( request , obj_id ) <EOL> class RestartInstance ( tables . BatchAction ) : <EOL> name = "<STR_LIT>" <EOL> action_present = _ ( "<STR_LIT>" ) <EOL> action_past = _ ( "<STR_LIT>" ) <EOL> data_type_singular = _ ( "<STR_LIT>" ) <EOL> data_type_plural = _ ( "<STR_LIT>" ) <EOL> classes = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def allowed ( self , request , instance = None ) : <EOL> return ( ( instance . status in ACTIVE_STATES <EOL> or instance . status == '<STR_LIT>' ) ) <EOL> def action ( self , request , obj_id ) : <EOL> api . trove . instance_restart ( request , obj_id ) <EOL> class DeleteUser ( tables . DeleteAction ) : <EOL> name = "<STR_LIT>" <EOL> action_present = _ ( "<STR_LIT>" ) <EOL> action_past = _ ( "<STR_LIT>" ) <EOL> data_type_singular = _ ( "<STR_LIT>" ) <EOL> data_type_plural = _ ( "<STR_LIT>" ) <EOL> def delete ( self , request , obj_id ) : <EOL> datum = self . table . get_object_by_id ( obj_id ) <EOL> try : <EOL> api . trove . users_delete ( request , datum . instance . id , datum . name ) <EOL> except Exception : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> exceptions . handle ( request , msg ) <EOL> class DeleteDatabase ( tables . DeleteAction ) : <EOL> name = "<STR_LIT>" <EOL> action_present = _ ( "<STR_LIT>" ) <EOL> action_past = _ ( "<STR_LIT>" ) <EOL> data_type_singular = _ ( "<STR_LIT>" ) <EOL> data_type_plural = _ ( "<STR_LIT>" ) <EOL> def delete ( self , request , obj_id ) : <EOL> datum = self . table . get_object_by_id ( obj_id ) <EOL> try : <EOL> api . trove . database_delete ( request , datum . instance . id , datum . name ) <EOL> except Exception : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> exceptions . handle ( request , msg ) <EOL> class LaunchLink ( tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" <EOL> classes = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> class CreateBackup ( tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" <EOL> classes = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def allowed ( self , request , instance = None ) : <EOL> return request . user . has_perm ( '<STR_LIT>' ) <EOL> def get_link_url ( self , datam ) : <EOL> url = urlresolvers . reverse ( self . url ) <EOL> return url + "<STR_LIT>" % datam . id <EOL> class UpdateRow ( tables . Row ) : <EOL> ajax = True <EOL> def get_data ( self , request , instance_id ) : <EOL> instance = api . trove . instance_get ( request , instance_id ) <EOL> try : <EOL> flavor_id = instance . flavor [ '<STR_LIT:id>' ] <EOL> instance . full_flavor = api . trove . flavor_get ( request , flavor_id ) <EOL> except Exception : <EOL> pass <EOL> return instance <EOL> def get_ips ( instance ) : <EOL> if hasattr ( instance , "<STR_LIT>" ) : <EOL> if len ( instance . ip ) : <EOL> return instance . ip [ <NUM_LIT:0> ] <EOL> return _ ( "<STR_LIT>" ) <EOL> def get_size ( instance ) : <EOL> if hasattr ( instance , "<STR_LIT>" ) : <EOL> size_string = _ ( "<STR_LIT>" ) <EOL> vals = { '<STR_LIT:name>' : instance . full_flavor . name , <EOL> '<STR_LIT>' : sizeformat . mbformat ( instance . full_flavor . ram ) } <EOL> return size_string % vals <EOL> return _ ( "<STR_LIT>" ) <EOL> def get_databases ( user ) : <EOL> if hasattr ( user , "<STR_LIT>" ) : <EOL> databases = [ db . name for db in user . access ] <EOL> databases . sort ( ) <EOL> return '<STR_LIT:U+002CU+0020>' . join ( databases ) <EOL> return _ ( "<STR_LIT:->" ) <EOL> class InstancesTable ( tables . DataTable ) : <EOL> STATUS_CHOICES = ( <EOL> ( "<STR_LIT>" , True ) , <EOL> ( "<STR_LIT>" , True ) , <EOL> ( "<STR_LIT>" , True ) , <EOL> ( "<STR_LIT>" , True ) , <EOL> ( "<STR_LIT:error>" , False ) , <EOL> ) <EOL> name = tables . Column ( "<STR_LIT:name>" , <EOL> link = ( "<STR_LIT>" ) , <EOL> verbose_name = _ ( "<STR_LIT>" ) ) <EOL> ip = tables . Column ( get_ips , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> size = tables . Column ( get_size , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> attrs = { '<STR_LIT>' : '<STR_LIT:size>' } ) <EOL> status = tables . Column ( "<STR_LIT:status>" , <EOL> filters = ( title , filters . replace_underscores ) , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> status = True , <EOL> status_choices = STATUS_CHOICES ) <EOL> class Meta : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> status_columns = [ "<STR_LIT:status>" ] <EOL> row_class = UpdateRow <EOL> table_actions = ( LaunchLink , TerminateInstance ) <EOL> row_actions = ( CreateBackup , <EOL> RestartInstance , TerminateInstance ) <EOL> class UsersTable ( tables . DataTable ) : <EOL> name = tables . Column ( "<STR_LIT:name>" , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> host = tables . Column ( "<STR_LIT:host>" , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> databases = tables . Column ( get_databases , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> class Meta : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> table_actions = [ DeleteUser ] <EOL> row_actions = [ DeleteUser ] <EOL> def get_object_id ( self , datum ) : <EOL> return datum . name <EOL> class DatabaseTable ( tables . DataTable ) : <EOL> name = tables . Column ( "<STR_LIT:name>" , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> class Meta : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> table_actions = [ DeleteDatabase ] <EOL> row_actions = [ DeleteDatabase ] <EOL> def get_object_id ( self , datum ) : <EOL> return datum . name <EOL> class InstanceBackupsTable ( tables . DataTable ) : <EOL> name = tables . Column ( "<STR_LIT:name>" , <EOL> link = ( "<STR_LIT>" ) , <EOL> verbose_name = _ ( "<STR_LIT:Name>" ) ) <EOL> created = tables . Column ( "<STR_LIT>" , verbose_name = _ ( "<STR_LIT>" ) , <EOL> filters = [ filters . parse_isotime ] ) <EOL> location = tables . Column ( lambda obj : _ ( "<STR_LIT>" ) , <EOL> link = lambda obj : obj . locationRef , <EOL> verbose_name = _ ( "<STR_LIT>" ) ) <EOL> status = tables . Column ( "<STR_LIT:status>" , <EOL> filters = ( title , filters . replace_underscores ) , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> status = True , <EOL> status_choices = backup_tables . STATUS_CHOICES ) <EOL> class Meta : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> status_columns = [ "<STR_LIT:status>" ] <EOL> row_class = UpdateRow <EOL> table_actions = ( backup_tables . LaunchLink , backup_tables . DeleteBackup ) <EOL> row_actions = ( backup_tables . RestoreLink , backup_tables . DeleteBackup ) </s>
