<s> import logging <EOL> import os <EOL> import shutil <EOL> from django . conf import settings <EOL> from rest_framework . serializers import ValidationError <EOL> logger = logging . getLogger ( __name__ ) <EOL> class TimeoutException ( Exception ) : <EOL> pass <EOL> class MaxFailuresException ( Exception ) : <EOL> pass <EOL> class GroupNotFoundException ( Exception ) : <EOL> pass <EOL> class GroupExistsException ( Exception ) : <EOL> pass <EOL> class DeleteGroupException ( Exception ) : <EOL> pass <EOL> class RuleNotFoundException ( Exception ) : <EOL> pass <EOL> class RuleExistsException ( Exception ) : <EOL> pass <EOL> class SecurityGroupRule ( object ) : <EOL> def __init__ ( self , protocol , from_port , to_port , rule ) : <EOL> self . protocol = protocol <EOL> self . from_port = from_port <EOL> self . to_port = to_port <EOL> self . rule = rule <EOL> class SecurityGroup ( object ) : <EOL> def __init__ ( self , name , description , group_id , vpc_id , rules , rules_egress ) : <EOL> self . name = name <EOL> self . description = description <EOL> self . group_id = group_id <EOL> self . vpc_id = vpc_id <EOL> self . rules = rules <EOL> self . rules_egress = rules_egress <EOL> class BaseCloudProvider ( object ) : <EOL> REQUIRED_MESSAGE = '<STR_LIT>' <EOL> SHORT_NAME = None <EOL> LONG_NAME = None <EOL> ACTION_STOP = '<STR_LIT>' <EOL> ACTION_START = '<STR_LIT:start>' <EOL> ACTION_TERMINATE = '<STR_LIT>' <EOL> ACTION_LAUNCH = '<STR_LIT>' <EOL> ACTION_PROVISION = '<STR_LIT>' <EOL> ACTION_ORCHESTRATE = '<STR_LIT>' <EOL> ACTION_SSH = '<STR_LIT>' <EOL> def __init__ ( self , account = None , * args , ** kwargs ) : <EOL> if account : <EOL> from stackdio . api . cloud . models import CloudAccount <EOL> assert isinstance ( account , CloudAccount ) <EOL> self . account = account <EOL> self . provider_storage = os . path . join ( settings . FILE_STORAGE_DIRECTORY , <EOL> '<STR_LIT>' , <EOL> account . slug ) if self . account else None <EOL> if self . provider_storage and not os . path . isdir ( self . provider_storage ) : <EOL> os . makedirs ( self . provider_storage ) <EOL> def destroy ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . provider_storage : <EOL> return <EOL> if os . path . isdir ( self . provider_storage ) : <EOL> logger . info ( '<STR_LIT>' . format ( <EOL> self . provider_storage <EOL> ) ) <EOL> shutil . rmtree ( self . provider_storage ) <EOL> self . provider_storage = None <EOL> @ classmethod <EOL> def get_provider_choice ( cls ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( cls , '<STR_LIT>' ) or not cls . SHORT_NAME : <EOL> raise AttributeError ( '<STR_LIT>' ) <EOL> if not hasattr ( cls , '<STR_LIT>' ) or not cls . LONG_NAME : <EOL> raise AttributeError ( '<STR_LIT>' ) <EOL> return cls . SHORT_NAME , cls . LONG_NAME <EOL> def get_required_fields ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ classmethod <EOL> def get_provider_data ( cls , validated_data , all_data ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def validate_provider_data ( self , serializer_attrs , all_data ) : <EOL> """<STR_LIT>""" <EOL> errors = { } <EOL> for key in self . get_required_fields ( ) : <EOL> value = all_data . get ( key ) <EOL> if not value : <EOL> errors . setdefault ( key , [ ] ) . append ( <EOL> '<STR_LIT>' . format ( key ) <EOL> ) <EOL> if errors : <EOL> raise ValidationError ( errors ) <EOL> return serializer_attrs <EOL> @ classmethod <EOL> def validate_image_id ( cls , image_id ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ classmethod <EOL> def register_dns ( cls , hosts ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ classmethod <EOL> def unregister_dns ( cls , hosts ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) </s>
