<s> """<STR_LIT>""" <EOL> from base import CliTask <EOL> from . . account . service import AzureAccount <EOL> from . . utils . collector import DataCollector <EOL> from . . utils . output import DataOutput <EOL> from . . logger import log <EOL> from . . instance . virtual_machine import VirtualMachine <EOL> from . . instance . cloud_service import CloudService <EOL> from . . management . request_result import RequestResult <EOL> from . . help import Help <EOL> class ComputeVmTask ( CliTask ) : <EOL> """<STR_LIT>""" <EOL> SSH_DEFAULT_PORT = <NUM_LIT> <EOL> def process ( self ) : <EOL> self . manual = Help ( ) <EOL> if self . __help ( ) : <EOL> return <EOL> self . result = DataCollector ( ) <EOL> self . out = DataOutput ( <EOL> self . result , <EOL> self . global_args [ '<STR_LIT>' ] , <EOL> self . global_args [ '<STR_LIT>' ] <EOL> ) <EOL> self . load_config ( ) <EOL> self . account = AzureAccount ( self . config ) <EOL> if self . command_args [ '<STR_LIT>' ] : <EOL> self . __list_instance_types ( ) <EOL> elif self . command_args [ '<STR_LIT>' ] : <EOL> self . __list_locations ( ) <EOL> else : <EOL> self . vm = VirtualMachine ( self . account ) <EOL> self . cloud_service = CloudService ( self . account ) <EOL> if self . command_args [ '<STR_LIT>' ] : <EOL> self . __create_cloud_service ( ) <EOL> self . __create_instance ( ) <EOL> elif self . command_args [ '<STR_LIT>' ] : <EOL> if self . command_args [ '<STR_LIT>' ] : <EOL> self . __delete_instance ( ) <EOL> else : <EOL> self . __delete_cloud_service ( ) <EOL> def __help ( self ) : <EOL> if self . command_args [ '<STR_LIT>' ] : <EOL> self . manual . show ( '<STR_LIT>' ) <EOL> else : <EOL> return False <EOL> return self . manual <EOL> def __list_instance_types ( self ) : <EOL> self . result . add ( '<STR_LIT>' , self . account . instance_types ( ) ) <EOL> self . out . display ( ) <EOL> def __list_locations ( self ) : <EOL> self . result . add ( '<STR_LIT>' , self . account . locations ( '<STR_LIT>' ) ) <EOL> self . out . display ( ) <EOL> def __create_instance ( self ) : <EOL> instance_type = self . command_args [ '<STR_LIT>' ] <EOL> if not instance_type : <EOL> instance_type = '<STR_LIT>' <EOL> fingerprint = u'<STR_LIT>' <EOL> if self . command_args [ '<STR_LIT>' ] : <EOL> fingerprint = self . cloud_service . add_certificate ( <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> self . command_args [ '<STR_LIT>' ] <EOL> ) <EOL> elif self . command_args [ '<STR_LIT>' ] : <EOL> fingerprint = self . command_args [ '<STR_LIT>' ] <EOL> linux_configuration = self . __prepare_linux_configuration ( fingerprint ) <EOL> network_configuration = self . __prepare_network ( ) <EOL> self . result . add ( <EOL> '<STR_LIT>' , <EOL> self . vm . create_instance ( <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> linux_configuration , <EOL> network_configuration , <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , <EOL> instance_type , <EOL> self . command_args [ '<STR_LIT>' ] <EOL> ) <EOL> ) <EOL> self . out . display ( ) <EOL> def __create_cloud_service ( self ) : <EOL> cloud_service_request_id = self . cloud_service . create ( <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> self . config . get_region_name ( ) <EOL> ) <EOL> if cloud_service_request_id > <NUM_LIT:0> : <EOL> request_result = RequestResult ( cloud_service_request_id ) <EOL> request_result . wait_for_request_completion ( <EOL> self . cloud_service . service <EOL> ) <EOL> def __delete_cloud_service ( self ) : <EOL> cloud_service = self . command_args [ '<STR_LIT>' ] <EOL> complete_deletion = True <EOL> request_id = self . cloud_service . delete ( <EOL> cloud_service , complete_deletion <EOL> ) <EOL> log . info ( <EOL> '<STR_LIT>' , <EOL> format ( cloud_service ) , format ( request_id ) <EOL> ) <EOL> def __delete_instance ( self ) : <EOL> instance_name = self . command_args [ '<STR_LIT>' ] <EOL> request_id = self . vm . delete_instance ( <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> instance_name <EOL> ) <EOL> log . info ( <EOL> '<STR_LIT>' , <EOL> format ( instance_name ) , format ( request_id ) <EOL> ) <EOL> def __prepare_linux_configuration ( self , fingerprint = u'<STR_LIT>' ) : <EOL> user = self . command_args [ '<STR_LIT>' ] <EOL> instance_name = self . command_args [ '<STR_LIT>' ] <EOL> password = self . command_args [ '<STR_LIT>' ] <EOL> custom_data = self . command_args [ '<STR_LIT>' ] <EOL> disable_ssh_password_authentication = False <EOL> if not user : <EOL> user = '<STR_LIT>' <EOL> if not instance_name : <EOL> instance_name = self . command_args [ '<STR_LIT>' ] <EOL> if not password : <EOL> disable_ssh_password_authentication = True <EOL> return self . vm . create_linux_configuration ( <EOL> user , <EOL> instance_name , <EOL> disable_ssh_password_authentication , <EOL> password , <EOL> custom_data , <EOL> fingerprint <EOL> ) <EOL> def __prepare_network ( self ) : <EOL> ssh_endpoint = self . __prepare_ssh ( ) <EOL> return self . vm . create_network_configuration ( <EOL> [ ssh_endpoint ] <EOL> ) <EOL> def __prepare_ssh ( self , ssh_local_port = SSH_DEFAULT_PORT ) : <EOL> ssh_public_port = self . command_args [ '<STR_LIT>' ] <EOL> if not ssh_public_port : <EOL> ssh_public_port = ssh_local_port <EOL> return self . vm . create_network_endpoint ( <EOL> '<STR_LIT>' , ssh_public_port , ssh_local_port , '<STR_LIT>' <EOL> ) </s>
