Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
RECIRCLE
/
interface-openstack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
2
Merge Requests
4
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d0137d0e
authored
Jul 07, 2019
by
Belákovics Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix get_vm method
parent
8edd7811
Pipeline
#737
passed with stage
in 40 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
34 deletions
+34
-34
implementation/vm/instance.py
+23
-28
main.py
+11
-6
No files found.
implementation/vm/instance.py
View file @
d0137d0e
from
interface
_openstack.interface
.vm.instance
import
InstanceInterface
from
interface
_openstack.interface
.vm.resources
import
Instance
,
Flavor
from
interface.vm.instance
import
InstanceInterface
from
interface.vm.resources
import
Instance
,
Flavor
from
openstack.exceptions
import
SDKException
from
novaclient
import
client
import
logging
...
...
@@ -38,6 +38,15 @@ class OSVirtualMachineManager(InstanceInterface):
self
.
openstack
=
cloud
@openstackError
def
_get_openstack_server
(
self
,
name_or_id
):
if
not
name_or_id
:
raise
ValueError
(
"Name or id doesn't given"
)
server_instance
=
self
.
openstack
.
compute
.
get_server
(
name_or_id
)
if
not
server_instance
:
raise
ValueError
(
"Could not get the vm"
)
return
server_instance
@openstackError
def
create_base_vm
(
self
,
name
,
flavor
,
networks
,
block_dev_map
):
devices
=
[]
b_device
=
block_dev_map
.
__dict__
...
...
@@ -102,59 +111,47 @@ class OSVirtualMachineManager(InstanceInterface):
@openstackError
def
get_vm
(
self
,
name_or_id
=
None
):
if
not
name_or_id
:
raise
ValueError
(
"Name or id doesn't given"
)
server_instance
=
self
.
openstack
.
compute
.
get_server
(
name_or_id
)
if
not
server_instance
:
raise
ValueError
(
"Could not get the vm"
)
return
self
.
convert_server_to_instance
(
server_instance
)
instance
=
self
.
_get_openstack_server
(
name_or_id
)
return
self
.
convert_server_to_instance
(
instance
)
@openstackError
def
start_vm
(
self
,
name_or_id
=
None
):
if
name_or_id
:
instance
=
self
.
openstack
.
compute
.
get_server
(
name_or_id
)
instance
=
self
.
_get_openstack_server
(
name_or_id
)
self
.
openstack
.
compute
.
start_server
(
instance
)
@openstackError
def
stop_vm
(
self
,
name_or_id
=
None
):
if
name_or_id
:
instance
=
self
.
openstack
.
compute
.
get_server
(
name_or_id
)
instance
=
self
.
_get_openstack_server
(
name_or_id
)
self
.
openstack
.
compute
.
stop_server
(
instance
)
@openstackError
def
suspend_vm
(
self
,
name_or_id
=
None
):
if
name_or_id
:
instance
=
self
.
openstack
.
compute
.
get_server
(
name_or_id
)
instance
=
self
.
_get_openstack_server
(
name_or_id
)
self
.
openstack
.
compute
.
suspend_server
(
instance
)
@openstackError
def
wake_up_vm
(
self
,
name_or_id
=
None
):
if
name_or_id
:
instance
=
self
.
openstack
.
compute
.
get_server
(
name_or_id
)
instance
=
self
.
_get_openstack_server
(
name_or_id
)
self
.
openstack
.
compute
.
resume_server
(
instance
)
@openstackError
def
reboot_vm
(
self
,
name_or_id
):
if
name_or_id
:
instance
=
self
.
openstack
.
compute
.
get_server
(
name_or_id
)
instance
=
self
.
_get_openstack_server
(
name_or_id
)
self
.
openstack
.
compute
.
reboot_server
(
instance
,
reboot_type
=
'SOFT'
)
@openstackError
def
reset_vm
(
self
,
name_or_id
):
if
name_or_id
:
instance
=
self
.
openstack
.
compute
.
get_server
(
name_or_id
)
instance
=
self
.
_get_openstack_server
(
name_or_id
)
self
.
openstack
.
compute
.
reboot_server
(
instance
,
reboot_type
=
'HARD'
)
@openstackError
def
destroy_vm
(
self
,
name_or_id
):
if
name_or_id
:
instance
=
self
.
openstack
.
compute
.
get_server
(
name_or_id
)
instance
=
self
.
_get_openstack_server
(
name_or_id
)
self
.
openstack
.
compute
.
delete_server
(
instance
)
@openstackError
def
get_status
(
self
,
name_or_id
):
if
name_or_id
:
instance
=
self
.
openstack
.
compute
.
get_server
(
name_or_id
)
instance
=
self
.
_get_openstack_server
(
name_or_id
)
return
instance
.
status
@openstackError
...
...
@@ -166,16 +163,14 @@ class OSVirtualMachineManager(InstanceInterface):
@openstackError
def
resize_vm
(
self
,
name_or_id
,
resource
):
if
name_or_id
:
instance
=
self
.
openstack
.
get_server
(
name_or_id
)
instance
=
self
.
_get_openstack_server
(
name_or_id
)
flavor
=
self
.
openstack
.
compute
.
find_flavor
(
resource
[
'name'
])
self
.
openstack
.
compute
.
resize_server
(
instance
,
flavor
)
@openstackError
def
create_template
(
self
,
name_or_id
,
template_name
,
metadata
=
None
):
if
name_or_id
:
instance
=
self
.
openstack
.
compute
.
get_server
(
name_or_id
)
instance
=
self
.
_get_openstack_server
(
name_or_id
)
self
.
openstack
.
compute
.
create_server_image
(
instance
,
template_name
,
metadata
)
...
...
main.py
View file @
d0137d0e
...
...
@@ -40,8 +40,13 @@ for vm in interface.list_all_vm():
print
(
vm
.
JSON
())
print
(
"*"
*
50
)
print
(
interface
.
create_base_vm
(
"BaseTest"
,
"2"
,
networks
,
block_dev_map
)
.
JSON
())
#
print(interface.create_base_vm("BaseTest", "2", networks, block_dev_map).JSON())
print
(
"*********TEST SERVER**********"
)
print
(
interface
.
get_vm
(
"fb91a363-e23b-4fb6-8770-357509b753da"
)
.
JSON
())
print
(
"*********TEST SUSPEND**********"
)
interface
.
suspend_vm
(
"fb91a363-e23b-4fb6-8770-357509b753da"
)
# print(interface.convert_server_to_instance(server).JSON())
...
...
@@ -128,9 +133,9 @@ print('Floating IP:')
print
(
'
\t
Floating IP:
%
s'
%
floating_ip
)
#
print(router_manager.add_interface(router.id, inner_subnet.id)) # TODO: fix error msg
#
print(router_manager.add_gateway(router.id, public_network.id)) # TODO: fix it!
print
(
router_manager
.
add_interface
(
router
.
id
,
inner_subnet
.
id
))
# TODO: fix error msg
print
(
router_manager
.
add_gateway
(
router
.
id
,
public_network
.
id
))
# TODO: fix it!
#
print(floating_ip_manager.update(floating_ip.id, {
#
'port_id': vm_port.id
#
}))
print
(
floating_ip_manager
.
update
(
floating_ip
.
id
,
{
'port_id'
:
vm_port
.
id
}))
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