Пример #1
0
 def _check_params(self):
     # the deployment strategy ensures that this key exists
     # use a different class if the destination is set using common_data, e.g. protocols
     if not any('ssh' in data for data in self.job.device['actions']['deploy']['methods']):
         self.errors = "Invalid device configuration - no suitable deploy method for ssh"
         return
     params = self.job.device['actions']['deploy']['methods']
     if 'identity_file' in self.job.device['actions']['deploy']['methods']['ssh']:
         check = check_ssh_identity_file(params)
         if check[0]:
             self.errors = check[0]
         elif check[1]:
             self.identity_file = check[1]
     if 'ssh' not in params:
         self.errors = "Empty ssh parameter list in device configuration %s" % params
         return
     if 'options' in params['ssh']:
         if any([option for option in params['ssh']['options'] if not isinstance(option, str)]):
             msg = [(option, type(option)) for option in params['ssh']['options'] if not isinstance(option, str)]
             self.errors = "[%s] Invalid device configuration: all options must be only strings: %s" % (self.name, msg)
             return
     if 'port' in params['ssh']:
         self.ssh_port = ["-p", "%s" % str(params['ssh']['port'])]
         self.scp_port = ["-P", "%s" % str(params['ssh']['port'])]
     if 'host' in params['ssh'] and params['ssh']['host']:
         # get the value from the protocol later.
         self.host = params['ssh']['host']
     if 'user' in params['ssh'] and params['ssh']['user']:
         self.ssh_user = params['ssh']['user']
     return params['ssh']
 def validate(self):
     super(SshAuthorize, self).validate()
     if 'to' in self.parameters:
         if self.parameters['to'] == 'ssh':
             return
     if 'authorize' in self.parameters:
         if self.parameters['authorize'] != 'ssh':
             return
     if not any(
             'ssh' in data
             for data in self.job.device['actions']['deploy']['methods']):
         # idempotency - leave self.identity_file as None
         return
     params = self.job.device['actions']['deploy']['methods']
     check = check_ssh_identity_file(params)
     if check[0]:
         self.errors = check[0]
     elif check[1]:
         self.identity_file = check[1]
     if self.valid:
         self.set_namespace_data(action=self.name,
                                 label='authorize',
                                 key='identity_file',
                                 value=self.identity_file)
         if 'authorize' in self.parameters:
             # only secondary connections set active.
             self.active = True
Пример #3
0
 def _check_params(self):
     # the deployment strategy ensures that this key exists
     # use a different class if the destination is set using common_data, e.g. protocols
     if not any('ssh' in data for data in self.job.device['actions']['deploy']['methods']):
         self.errors = "Invalid device configuration - no suitable deploy method for ssh"
         return
     params = self.job.device['actions']['deploy']['methods']
     if 'identity_file' in self.job.device['actions']['deploy']['methods']['ssh']:
         check = check_ssh_identity_file(params)
         if check[0]:
             self.errors = check[0]
         elif check[1]:
             self.identity_file = check[1]
     if 'ssh' not in params:
         self.errors = "Empty ssh parameter list in device configuration %s" % params
         return
     if 'options' in params['ssh']:
         if any([option for option in params['ssh']['options'] if not isinstance(option, str)]):
             msg = [(option, type(option)) for option in params['ssh']['options'] if not isinstance(option, str)]
             self.errors = "[%s] Invalid device configuration: all options must be only strings: %s" % (self.name, msg)
             return
     if 'port' in params['ssh']:
         self.ssh_port = ["-p", "%s" % str(params['ssh']['port'])]
         self.scp_port = ["-P", "%s" % str(params['ssh']['port'])]
     if 'host' in params['ssh'] and params['ssh']['host']:
         # get the value from the protocol later.
         self.host = params['ssh']['host']
     if 'user' in params['ssh'] and params['ssh']['user']:
         self.ssh_user = params['ssh']['user']
     return params['ssh']
Пример #4
0
 def test_ssh_identity(self):
     params = {
         'tftp': 'None',
         'usb': 'None',
         'ssh': {
             'host': '172.16.200.165', 'options': [
                 '-o', 'Compression=yes', '-o', 'UserKnownHostsFile=/dev/null',
                 '-o', 'PasswordAuthentication=no', '-o', 'StrictHostKeyChecking=no',
                 '-o', 'LogLevel=FATAL', '-l', 'root ', '-p', 22],
             'identity_file': 'device/dynamic_vm_keys/lava'
         }
     }
     check = check_ssh_identity_file(params)
     self.assertIsNone(check[0])
     self.assertIsNotNone(check[1])
     self.assertEqual(os.path.basename(check[1]), 'lava')
 def test_ssh_identity(self):
     params = {
         'tftp': 'None',
         'usb': 'None',
         'ssh': {
             'host': '172.16.200.165', 'options': [
                 '-o', 'Compression=yes', '-o', 'UserKnownHostsFile=/dev/null',
                 '-o', 'PasswordAuthentication=no', '-o', 'StrictHostKeyChecking=no',
                 '-o', 'LogLevel=FATAL', '-l', 'root ', '-p', 22],
             'identity_file': 'device/dynamic_vm_keys/lava'
         }
     }
     check = check_ssh_identity_file(params)
     self.assertIsNone(check[0])
     self.assertIsNotNone(check[1])
     self.assertEqual(os.path.basename(check[1]), 'lava')
Пример #6
0
 def validate(self):
     super(SshAuthorize, self).validate()
     if 'to' in self.parameters:
         if self.parameters['to'] == 'ssh':
             return
     if 'authorize' in self.parameters:
         if self.parameters['authorize'] != 'ssh':
             return
     if not any('ssh' in data for data in self.job.device['actions']['deploy']['methods']):
         # idempotency - leave self.identity_file as None
         return
     params = self.job.device['actions']['deploy']['methods']
     check = check_ssh_identity_file(params)
     if check[0]:
         self.errors = check[0]
     elif check[1]:
         self.identity_file = check[1]
     if self.valid:
         self.set_common_data('authorize', 'identity_file', self.identity_file)
         if 'authorize' in self.parameters:
             # only secondary connections set active.
             self.active = True