Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BlueAngelHost #7

Merged
merged 3 commits into from
Nov 28, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 39 additions & 51 deletions cloudomate/hoster/vps/blueangelhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

from future import standard_library

from bs4 import BeautifulSoup
from bs4 import Tag
from past.builtins import unicode

from cloudomate.gateway.bitpay import BitPay
from cloudomate.hoster.vps.solusvm_hoster import SolusvmHoster
Expand All @@ -25,7 +26,6 @@


class BlueAngelHost(SolusvmHoster):
CLIENT_DATA_URL = 'https://www.billing.blueangelhost.com/modules/servers/solusvmpro/get_client_data.php'
CART_URL = 'https://www.billing.blueangelhost.com/cart.php?a=view'

# true if you can enable tuntap in the control panel
Expand Down Expand Up @@ -97,20 +97,16 @@ def get_configuration(self):
def get_status(self):
status = super().get_status()

# Retrieve the vserverid
page = self._browser.open(status.clientarea.url)
match = re.search(r'vserverid = (\d+)', page.text)
identifier = match.group(1)

millis = int(round(time.time() * 1000)) # Needed for some reason
page = self._browser.open('{}?vserverid={}&_={}'.format(self.CLIENT_DATA_URL, identifier, millis))
# Get server stats
page = self._browser.open('{}&api=json&act=vpsmanage&stats=1'.format(status.clientarea.url))
data = page.json()

memory = VpsStatusResource(self._convert_gigabyte(data['memoryused']),
self._convert_gigabyte(data['memorytotal']))
storage = VpsStatusResource(self._convert_gigabyte(data['hddused']), self._convert_gigabyte(data['hddtotal']))
bandwidth = VpsStatusResource(self._convert_gigabyte(data['bandwidthused']),
self._convert_gigabyte(data['bandwidthtotal']))
memory = VpsStatusResource(data['info']['ram']['used']/1024.0,
MattSkala marked this conversation as resolved.
Show resolved Hide resolved
data['info']['ram']['limit']/1024.0)
storage = VpsStatusResource(data['info']['disk']['used_gb'],
data['info']['disk']['limit_gb'])
bandwidth = VpsStatusResource(data['info']['bandwidth']['used_gb'],
data['info']['bandwidth']['limit_gb'])

return VpsStatus(memory, storage, bandwidth, status.online, status.expiration, status.clientarea)

Expand All @@ -133,22 +129,6 @@ def purchase(self, wallet, option):
Hoster-specific methods that are needed to perform the actions
'''

@staticmethod
def _convert_gigabyte(s):
n = float(s.split(' ')[0])
if 'KB' in s:
n /= 1024.0 * 1024.0
elif 'MB' in s:
n /= 1024.0
elif 'GB' in s:
pass
elif 'TB' in s:
n *= 1024.0
else:
raise ValueError('Unknown unit in string {}'.format(s))

return n

@classmethod
def _parse_options(cls, page, is_kvm=False):
month = page.find('div', {'id': 'monthly_price'})
Expand Down Expand Up @@ -223,7 +203,7 @@ def get_server_information_from_email(self):
for email in self.get_emails():
e_id = email['id']
title = email['title']
if 'ready' in title:
if 'ready' in title.lower():
email_id = e_id
break
self._browser.open(self.email_url + '?id=' + email_id)
Expand All @@ -240,30 +220,38 @@ def get_server_information_from_email(self):


ps = soup.findAll('p')
pattern1 = re.compile(r'(?:<.*>)*((?:Main IP\s*:\s*)|'
r'(?:Root pass\s*:\S*)|(?:Username\s*:\s*)|'
r'(?:SSH Port\s))(.*)(?:<.*>)', re.MULTILINE)
pattern2 = re.compile(r'(?:<p>)*((?:UserName:)|(?:Password:))(.*)(?:<.*>)')

# map of server_info fields to the labels in the e-mail
server_keyword = 'Hostname'
server_fields = {
'ip_address': 'Main IP',
'server_user': 'Username',
'server_password': 'Root Password'
}

vm_keyword = 'Manager Details'
vm_fields = {
'vmuser': 'Username',
'vmuser_password': 'Password'
}

for p in ps:
for (k, v) in re.findall(pattern1, str(p)):
if 'Main IP' in k and not server_info['ip_address']:
server_info['ip_address'] = v
elif 'Root pass' in k and not server_info['server_password']:
server_info['server_password'] = v
elif 'Username' in k and not server_info['server_user']:
server_info['server_user'] = v
cpum = re.match(r'(?:<p>)*Panel URL\s*:\s*.*href="(.*)\/".*(?:<.*>)', str(p))
if cpum:
server_info['control_panel_url'] = cpum.group(1)

for (k, v) in re.findall(pattern2, str(p)):
if 'UserName' in k and not server_info['vmuser']:
server_info['vmuser'] = v
elif 'Password' in k and not server_info['vmuser_password']:
server_info['vmuser_password'] = v
for line in p:
self._parse_email_section(p, line, server_keyword, server_fields, server_info)
self._parse_email_section(p, line, vm_keyword, vm_fields, server_info)
if isinstance(line, Tag) and line.name == 'a':
server_info['control_panel_url'] = unicode(line.next)

return server_info

@staticmethod
def _parse_email_section(p, line, keyword, fields, server_info):
if keyword in p.text:
for key, label in fields.items():
line_str = unicode(line)
if label in line_str:
server_info[key] = line_str.split(':')[1].strip()

@staticmethod
def _extract_emails(soup):
table = soup.find('table', {'id': 'tableEmailsList'}).tbody
Expand Down