Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_paramiko_connection(_):
proxmox = ProxmoxAPI('proxmox', user='root', backend='ssh_paramiko', port=123)
session = proxmox._store['session']
eq_(session.ssh_client.connect.call_args[0], ('proxmox',))
eq_(session.ssh_client.connect.call_args[1], {'username': 'root',
'allow_agent': True,
'key_filename': None,
'look_for_keys': True,
'timeout': 5,
'password': None,
'port': 123})
def setUp(self, _):
super(TestParamikoSuiteWithSudo, self).__init__(sudo=True)
self.proxmox = ProxmoxAPI('proxmox', user='root', backend='ssh_paramiko', port=123, sudo=True)
self.client = self.proxmox._store['session'].ssh_client
self.session = self.client.get_transport().open_session()
self._set_stderr('200 OK')
self._set_stdout('')
def test_https_connection(req_session):
response = {'ticket': 'ticket',
'CSRFPreventionToken': 'CSRFPreventionToken'}
req_session.request.return_value = response
ProxmoxAPI('proxmox', user='root@pam', password='secret', port=123, verify_ssl=False)
call = req_session.return_value.request.call_args[1]
eq_(call['url'], 'https://proxmox:123/api2/json/access/ticket')
eq_(call['data'], {'username': 'root@pam', 'password': 'secret'})
eq_(call['method'], 'post')
eq_(call['verify'], False)
def test_https_connection_wth_port_in_host(req_session):
response = {'ticket': 'ticket',
'CSRFPreventionToken': 'CSRFPreventionToken'}
req_session.request.return_value = response
ProxmoxAPI('proxmox:123', user='root@pam', password='secret', port=124, verify_ssl=False)
call = req_session.return_value.request.call_args[1]
eq_(call['url'], 'https://proxmox:123/api2/json/access/ticket')
eq_(call['data'], {'username': 'root@pam', 'password': 'secret'})
eq_(call['method'], 'post')
eq_(call['verify'], False)
if userresource is None:
raise ValueError("No proxmox user found!! Please use proxmoxutil command to update user credentials")
user = userresource.properties[PROPERTIES_USER]
password = userresource.properties[PROPERTIES_PASSWORD]
authrealm = userresource.properties[PROPERTIES_AUTHREALM]
puser = user+'@'+authrealm
primary = proxmoxutil.listprimary()
if primary is None:
raise ValueError("Primary proxmox hypervisor not found!! Please use proxmoxutil command to update primary hypervisor")
hypervisor = primary.properties[PROPERTIES_HYPERVISOR]
print "Authenticating "+puser +" on "+ hypervisor
proxmox = ProxmoxAPI(hypervisor, user=puser, password=password, verify_ssl=False)
node = proxmox.nodes(hostresource.properties[HYPERVISOR])
hostname = hostresource.properties[HOSTNAME]
vmid = int(hostresource.properties[HOSTID])
ostemplate = str(hostresource.properties[PROPERTIES_OSTEMPLATE])
cpulimit = int(hostresource.properties[PROPERTIES_CPULIMIT])
cpuunits = int(hostresource.properties[PROPERTIES_CPUUNITS])
memory = int(hostresource.properties[PROPERTIES_MEMORY])
swap = int(hostresource.properties[PROPERTIES_SWAP])
storage = hostresource.properties[PROPERTIES_STORAGE]
disk = int(hostresource.properties[PROPERTIES_DISK])
disksize="%dG"%(disk)
interfaces = hostresource.properties[INTERFACES]
i=0
netconfig = dict()
def setUp(self, _):
self.proxmox = ProxmoxAPI('proxmox', user='root', backend='ssh_paramiko', port=123)
self.client = self.proxmox._store['session'].ssh_client
self.session = self.client.get_transport().open_session()
self._set_stderr('200 OK')
self._set_stdout('')
@raises(ResourceException)
def test_error_with_extra_output(self):
self._set_stderr("Extra output\n500 whoops")
self.proxmox.nodes('proxmox').get()
@raises(ResourceException)
def test_error(self):
self._set_stderr("500 whoops")
self.proxmox.nodes('proxmox').get()
swap = module.params['swap']
storage = module.params['storage']
hostname = module.params['hostname']
if module.params['ostemplate'] is not None:
template_store = module.params['ostemplate'].split(":")[0]
timeout = module.params['timeout']
# If password not set get it from PROXMOX_PASSWORD env
if not api_password:
try:
api_password = os.environ['PROXMOX_PASSWORD']
except KeyError as e:
module.fail_json(msg='You should set api_password param or use PROXMOX_PASSWORD environment variable')
try:
proxmox = ProxmoxAPI(api_host, user=api_user, password=api_password, verify_ssl=validate_certs)
global VZ_TYPE
VZ_TYPE = 'openvz' if float(proxmox.version.get()['version']) < 4.0 else 'lxc'
except Exception as e:
module.fail_json(msg='authorization on proxmox cluster failed with exception: %s' % e)
# If vmid not set get the Next VM id from ProxmoxAPI
# If hostname is set get the VM id from ProxmoxAPI
if not vmid and state == 'present':
vmid = get_nextvmid(module, proxmox)
elif not vmid and hostname:
hosts = get_vmid(proxmox, hostname)
if len(hosts) == 0:
module.fail_json(msg="Vmid could not be fetched => Hostname doesn't exist (action: %s)" % state)
vmid = hosts[0]
elif not vmid:
__copyright__ = '(c) Oleg Butovich 2013-2017'
__licence__ = 'MIT'
import os
from proxmoxer.backends.base_ssh import ProxmoxBaseSSHSession, BaseBackend
try:
import paramiko
except ImportError:
import sys
sys.stderr.write("Chosen backend requires 'paramiko' module\n")
sys.exit(1)
class ProxmoxParamikoSession(ProxmoxBaseSSHSession):
def __init__(self, host,
username,
password=None,
private_key_file=None,
port=22,
timeout=5,
sudo=False):
self.host = host
self.username = username
self.password = password
self.private_key_file = private_key_file
self.port = port
self.timeout = timeout
self.sudo = sudo
self.ssh_client = self._connect()