Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
okeanos-LoD
Commits
97f42752
Unverified
Commit
97f42752
authored
Jul 03, 2015
by
Avraam Tsantekidis
Browse files
LAM-38 First implementation of vm provisioning
parent
4358a8ae
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/__init__.py
0 → 100644
View file @
97f42752
core/provision.py
0 → 100644
View file @
97f42752
from
os.path
import
join
,
expanduser
from
ConfigParser
import
ConfigParser
from
kamaki.clients
import
ClientError
from
kamaki.clients.utils
import
https
from
kamaki.cli.config
import
Config
as
KamakiConfig
https
.
patch_ignore_ssl
()
import
argparse
from
kamaki.clients
import
astakos
,
cyclades
def
parse_kamakirc
(
filepath
=
None
):
"""
Parse the kamaki configuration
"""
parser
=
ConfigParser
()
# Default to ~/.kamakirc if filepath is not given
if
filepath
==
None
:
filepath
=
join
(
expanduser
(
'~'
),
".kamakirc"
)
parser
.
read
(
filepath
)
return
parser
class
Provisioner
:
"""
Provisioner is responsible to provision virtual machines for a specified
okeanos team
"""
def
__init__
(
self
,
cloud_name
,
project_name
):
self
.
project_name
=
project_name
# Load .kamakirc configuration
self
.
config
=
KamakiConfig
()
cloud_section
=
self
.
config
.
_sections
[
'cloud'
][
cloud_name
]
# Get the authentication url and token
auth_url
,
auth_token
=
cloud_section
[
'url'
],
cloud_section
[
'token'
]
# Create the astakos client
self
.
astakos
=
astakos
.
AstakosClient
(
auth_url
,
auth_token
)
# Create the cyclades client
computeURL
=
self
.
astakos
.
get_endpoint_url
(
cyclades
.
CycladesComputeClient
.
service_type
)
self
.
cyclades
=
cyclades
.
CycladesComputeClient
(
computeURL
,
auth_token
)
def
find_flavor
(
self
,
vcpus
=
1
,
ram
=
1024
,
disk
=
40
,
**
kwargs
):
"""
:param vcpus: Number of cpus
:param ram: Amount of ram megabytes
:param disk: Amount of disk gigabytes
:param kwargs:
:return: first flavor objects that matches the criteria
"""
for
flavor
in
self
.
cyclades
.
list_flavors
(
detail
=
True
):
if
flavor
[
'ram'
]
==
ram
and
flavor
[
'vcpus'
]
==
vcpus
and
flavor
[
'disk'
]
==
disk
:
return
flavor
return
None
def
find_image
(
self
,
image_name
=
"debian"
,
version
=
""
,
**
kwargs
):
for
image
in
self
.
cyclades
.
list_images
(
detail
=
True
):
if
image_name
in
image
[
'name'
]
and
version
in
image
[
'name'
]:
return
image
return
None
def
find_project_id
(
self
,
**
kwargs
):
filter
=
{
'name'
:
kwargs
.
get
(
"project_name"
)
}
return
self
.
astakos
.
get_projects
(
**
filter
)[
0
]
def
create_vm
(
self
,
vm_name
=
None
,
**
kwargs
):
flavor_id
=
self
.
find_flavor
(
**
kwargs
)[
'id'
]
image_id
=
self
.
find_image
(
**
kwargs
)[
'id'
]
project_id
=
self
.
find_project_id
(
**
kwargs
)[
'id'
]
try
:
print
self
.
cyclades
.
create_server
(
name
=
vm_name
,
flavor_id
=
flavor_id
,
image_id
=
image_id
,
project_id
=
project_id
,
networks
=
[])
except
ClientError
as
ex
:
print
ex
if
__name__
==
"__main__"
:
parser
=
argparse
.
ArgumentParser
(
description
=
"Okeanos VM provisioning"
)
parser
.
add_argument
(
'--cloud'
,
type
=
str
,
dest
=
"cloud"
,
default
=
"lambda"
)
parser
.
add_argument
(
'--project-name'
,
type
=
str
,
dest
=
"project_name"
,
default
=
"lambda.grnet.gr"
)
args
=
parser
.
parse_args
()
provisioner
=
Provisioner
(
cloud_name
=
args
.
cloud
,
project_name
=
args
.
project_name
)
provisioner
.
create_vm
(
vm_name
=
"to mikro ubuntu sto livadi"
,
project_name
=
args
.
project_name
)
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