Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
client
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
2
Merge Requests
0
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5c4911f7
authored
Oct 02, 2014
by
Csók Tamás
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client: logging added and selenium fully depricated
parent
5e808e4a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
98 deletions
+34
-98
src/nsi/installer/cloud.py
+34
-98
No files found.
src/nsi/installer/cloud.py
View file @
5c4911f7
...
@@ -8,13 +8,9 @@ The Client job is to help the ease of use of the cloud system.
...
@@ -8,13 +8,9 @@ The Client job is to help the ease of use of the cloud system.
import
platform
import
platform
import
argparse
import
argparse
try
:
import
logging
from
selenium
import
webdriver
import
os
from
selenium.webdriver.common.by
import
By
from
time
import
gmtime
,
strftime
from
selenium.webdriver.support.ui
import
WebDriverWait
from
selenium.webdriver.support
import
expected_conditions
as
EC
except
ImportError
:
pass
class
Struct
:
class
Struct
:
...
@@ -43,119 +39,59 @@ def parse_arguments():
...
@@ -43,119 +39,59 @@ def parse_arguments():
parser
.
add_argument
(
parser
.
add_argument
(
"uri"
,
type
=
str
,
help
=
"Specific schema handler"
,
nargs
=
'?'
,
"uri"
,
type
=
str
,
help
=
"Specific schema handler"
,
nargs
=
'?'
,
default
=
None
)
default
=
None
)
parser
.
add_argument
(
"-u"
,
"--username"
,
type
=
str
)
parser
.
add_argument
(
"-p"
,
"--password"
,
type
=
str
)
parser
.
add_argument
(
parser
.
add_argument
(
"-d"
,
"--driver"
,
"-l"
,
"--loglevel"
,
help
=
"Select webdriver. Aside from Firefox, you have to install "
help
=
"The level of logging severity"
,
type
=
str
,
+
"first the proper driver."
,
type
=
str
,
choices
=
[
'DEBUG'
,
'INFO'
,
'WARNING'
,
'ERROR'
,
'CRITICAL'
],
choices
=
[
'firefox'
,
'chrome'
,
'ie'
,
'opera'
],
default
=
"INFO"
)
default
=
"firefox"
)
parser
.
add_argument
(
"-f"
,
"--logfile"
,
help
=
"Explicit location of the wanted logfile location and name"
,
type
=
str
,
default
=
(
"
%(directory)
s
\\
%(file)
s"
%
{
'directory'
:
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
'file'
:
'client.log'
}))
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
return
args
return
args
class
Browser
:
"""
Browser initialisation
Keyword arguments:
@param args -- args.driver tells us which installed browser
we want to use with selenium.
"""
def
__init__
(
self
,
args
):
self
.
args
=
args
if
args
.
driver
==
"firefox"
:
self
.
driver
=
webdriver
.
Firefox
()
elif
args
.
driver
==
"chrome"
:
self
.
driver
=
webdriver
.
Chrome
()
elif
args
.
driver
==
"ie"
:
self
.
driver
=
webdriver
.
Ie
()
elif
args
.
driver
==
"opera"
:
self
.
driver
=
webdriver
.
Opera
()
self
.
driver
.
implicitly_wait
(
10
)
def
login
(
self
):
"""
Eduid login based on the given console arguments
"""
driver
=
self
.
driver
args
=
self
.
args
if
args
.
username
is
not
None
:
driver
.
find_element_by_name
(
"j_username"
)
.
clear
()
driver
.
find_element_by_name
(
"j_username"
)
.
send_keys
(
args
.
username
)
if
args
.
password
is
not
None
:
driver
.
find_element_by_name
(
"j_password"
)
.
clear
()
driver
.
find_element_by_name
(
"j_password"
)
.
send_keys
(
args
.
password
)
if
args
.
username
is
not
None
and
args
.
password
is
not
None
:
driver
.
find_element_by_css_selector
(
"input[type='submit']"
)
.
click
()
def
main
(
self
):
"""
Use of the https://cloud.bme.hu/
Keyword arguments:
@return vm -- Necessarily parameters to connect
to the Virtual Machine
"""
vm
=
Struct
()
driver
=
self
.
driver
driver
.
maximize_window
()
driver
.
get
(
"https://cloud.bme.hu/"
)
# driver.find_element_by_css_selector("a[href*='/login/']").click()
# self.login()
vm
.
state
,
vm
.
protocol
=
""
,
"NONE"
try
:
while
vm
.
state
.
upper
()[:
3
]
not
in
(
"FUT"
,
"RUN"
):
WebDriverWait
(
driver
,
7200
)
.
until
(
EC
.
presence_of_element_located
((
By
.
CSS_SELECTOR
,
"#vm-details-pw-eye.fa.fa-eye-slash"
)))
vm
.
state
=
driver
.
find_element_by_css_selector
(
"#vm-details-state > span"
)
.
text
# cl: connection string converted to list
cl
=
driver
.
find_element_by_css_selector
(
"#vm-details-connection-string"
)
.
get_attribute
(
"value"
)
.
split
()
if
cl
[
0
]
==
"sshpass"
:
vm
.
protocol
=
"SSH"
vm
.
user
,
vm
.
host
=
cl
[
6
]
.
split
(
"@"
)
vm
.
password
,
vm
.
port
=
cl
[
2
],
cl
[
8
]
elif
cl
[
0
]
==
"rdesktop"
:
vm
.
protocol
=
"RDP"
vm
.
host
,
vm
.
port
=
cl
[
1
]
.
split
(
":"
)
vm
.
user
,
vm
.
password
=
cl
[
3
],
cl
[
5
]
driver
.
find_element_by_css_selector
(
"a[href*='/logout/']"
)
.
click
()
except
:
print
"Browser session timed out!"
raise
return
vm
def
main
():
def
main
():
"""
"""
Main program
Main program
"""
"""
try
:
args
=
parse_arguments
()
args
=
parse_arguments
()
logging
.
basicConfig
(
filename
=
'
%
s'
%
args
.
logfile
,
format
=
'
%(levelname)
s:
%(message)
s'
)
logger
=
logging
.
getLogger
()
logger
.
setLevel
(
args
.
loglevel
)
logger
.
info
(
"----------------------------"
)
logger
.
info
(
"Client started running at
%
s"
,
strftime
(
"
%
Y-
%
d-
%
m
%
H:
%
M:
%
S GMT"
,
gmtime
()))
try
:
if
args
.
uri
is
not
None
:
if
args
.
uri
is
not
None
:
logger
.
info
(
'Received the following URI:
%
s'
,
args
.
uri
)
vm
=
Struct
()
vm
=
Struct
()
x
,
vm
.
protocol
,
vm
.
user
,
vm
.
password
,
vm
.
host
,
vm
.
port
=
\
x
,
vm
.
protocol
,
vm
.
user
,
vm
.
password
,
vm
.
host
,
vm
.
port
=
\
args
.
uri
.
split
(
':'
,
5
)
args
.
uri
.
split
(
':'
,
5
)
vm
.
protocol
=
vm
.
protocol
.
upper
()
vm
.
protocol
=
vm
.
protocol
.
upper
()
vm
.
state
=
"RUN"
logger
.
debug
(
"The Client split it followingly: protocol ->
%
s | "
"user ->
%
s | password ->
%
s | "
"host ->
%
s | port ->
%
s"
,
vm
.
protocol
,
vm
.
user
,
vm
.
password
,
vm
.
host
,
vm
.
port
)
else
:
else
:
browser
=
Browser
(
args
)
logger
.
critical
(
"Client did not receive an URI which would be "
vm
=
browser
.
main
()
"necessary to continue"
)
browser
.
driver
.
quit
()
if
platform
.
system
()
==
"Linux"
:
if
platform
.
system
()
==
"Linux"
:
logger
.
debug
(
'Linux OS found, proceeding to connect methods'
)
from
cloud_connect_from_linux
import
connect
from
cloud_connect_from_linux
import
connect
elif
platform
.
system
()
==
"Windows"
:
elif
platform
.
system
()
==
"Windows"
:
logger
.
debug
(
'Windows OS found, proceeding to connect methods'
)
from
cloud_connect_from_windows
import
connect
from
cloud_connect_from_windows
import
connect
if
vm
.
state
.
upper
()[:
3
]
in
(
"FUT"
,
"RUN"
):
connect
(
vm
)
connect
(
vm
)
except
:
except
:
logger
.
exception
(
"An exception was raised before connect methods"
"could be invoked"
)
print
"Unknown error occurred! Please contact the developers!"
print
"Unknown error occurred! Please contact the developers!"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment