<s> import os <EOL> import pdb <EOL> import sys <EOL> import tempfile <EOL> sys . path . append ( "<STR_LIT>" ) <EOL> from translator . toscalib . tosca_template import ToscaTemplate <EOL> from core . models import Node , NodeLabel , Site , Deployment , SiteDeployment <EOL> from xosresource import XOSResource <EOL> class XOSNode ( XOSResource ) : <EOL> provides = "<STR_LIT>" <EOL> xos_model = Node <EOL> def get_xos_args ( self ) : <EOL> args = { "<STR_LIT:name>" : self . obj_name } <EOL> site = None <EOL> siteName = self . get_requirement ( "<STR_LIT>" , throw_exception = False ) <EOL> if siteName : <EOL> site = self . get_xos_object ( Site , login_base = siteName ) <EOL> args [ "<STR_LIT>" ] = site <EOL> deploymentName = self . get_requirement ( "<STR_LIT>" , throw_exception = False ) <EOL> if deploymentName : <EOL> deployment = self . get_xos_object ( Deployment , name = deploymentName ) <EOL> if site : <EOL> siteDeployment = self . get_xos_object ( SiteDeployment , site = site , deployment = deployment , throw_exception = True ) <EOL> args [ "<STR_LIT>" ] = siteDeployment <EOL> return args <EOL> def postprocess ( self , obj ) : <EOL> labels = [ ] <EOL> for label_name in self . get_requirements ( "<STR_LIT>" ) : <EOL> labels . append ( self . get_xos_object ( NodeLabel , name = label_name ) ) <EOL> if labels : <EOL> self . info ( "<STR_LIT>" % obj ) <EOL> obj . labels = labels <EOL> obj . save ( ) <EOL> def create ( self ) : <EOL> xos_args = self . get_xos_args ( ) <EOL> if not xos_args . get ( "<STR_LIT>" , None ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if not xos_args . get ( "<STR_LIT>" , None ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> node = Node ( ** xos_args ) <EOL> node . caller = self . user <EOL> node . save ( ) <EOL> self . postprocess ( node ) <EOL> self . info ( "<STR_LIT>" % ( str ( node ) , str ( node . site ) , str ( node . site_deployment . deployment ) ) ) <EOL> def delete ( self , obj ) : <EOL> super ( XOSNode , self ) . delete ( obj ) </s>
