<s> import json <EOL> import urllib <EOL> import urllib2 <EOL> from appcontroller_client import AppControllerClient <EOL> from custom_exceptions import AppScaleException <EOL> from local_state import LocalState <EOL> from local_state import APPSCALE_VERSION <EOL> class RegistrationHelper ( object ) : <EOL> """<STR_LIT>""" <EOL> PORTAL_URL = '<STR_LIT>' <EOL> DEPLOYMENTS_URL = PORTAL_URL + '<STR_LIT>' <EOL> ADD_DEPLOYMENT_URL = PORTAL_URL + '<STR_LIT>' <EOL> HTTP_BADREQUEST = <NUM_LIT> <EOL> HTTP_UNAUTHORIZED = <NUM_LIT> <EOL> HTTP_NOTFOUND = <NUM_LIT> <EOL> HTTP_METHODNOTALLOWED = <NUM_LIT> <EOL> @ classmethod <EOL> def update_deployment ( cls , deployment_type , nodes , deployment_id ) : <EOL> """<STR_LIT>""" <EOL> for node in nodes : <EOL> if '<STR_LIT>' in node : <EOL> del node [ '<STR_LIT>' ] <EOL> deployment_data = urllib . urlencode ( { <EOL> '<STR_LIT>' : deployment_type , <EOL> '<STR_LIT>' : json . dumps ( nodes ) , <EOL> '<STR_LIT>' : APPSCALE_VERSION <EOL> } ) <EOL> try : <EOL> response = urllib2 . urlopen ( <EOL> cls . DEPLOYMENTS_URL . format ( deployment_id ) , data = deployment_data ) <EOL> deployment = response . read ( ) <EOL> return json . loads ( deployment ) <EOL> except urllib2 . HTTPError as error : <EOL> if error . code == cls . HTTP_NOTFOUND : <EOL> raise AppScaleException ( '<STR_LIT>' ) <EOL> if error . code == cls . HTTP_METHODNOTALLOWED : <EOL> raise AppScaleException ( '<STR_LIT>' ) <EOL> if error . code == cls . HTTP_BADREQUEST : <EOL> raise AppScaleException ( error . read ( ) ) <EOL> @ classmethod <EOL> def appscale_has_deployment_id ( cls , head_node , keyname ) : <EOL> """<STR_LIT>""" <EOL> secret = LocalState . get_secret_key ( keyname ) <EOL> acc = AppControllerClient ( head_node , secret ) <EOL> return acc . deployment_id_exists ( ) <EOL> @ classmethod <EOL> def get_deployment_id ( cls , head_node , keyname ) : <EOL> """<STR_LIT>""" <EOL> secret = LocalState . get_secret_key ( keyname ) <EOL> acc = AppControllerClient ( head_node , secret ) <EOL> return acc . get_deployment_id ( ) <EOL> @ classmethod <EOL> def set_deployment_id ( cls , head_node , keyname , deployment_id ) : <EOL> """<STR_LIT>""" <EOL> secret = LocalState . get_secret_key ( keyname ) <EOL> acc = AppControllerClient ( head_node , secret ) <EOL> acc . set_deployment_id ( deployment_id ) </s>
