-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from EncoreTechnologies/feature/nic-actions
feature/nic-actions
- Loading branch information
Showing
5 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env python | ||
# Copyright 2024 Encore Technologies | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from lib.action_base import BaseAction | ||
|
||
|
||
class VmNicAttach(BaseAction): | ||
def run(self, attach_timeout, gateway, ip_addr, method, network_id, vm_id, open_nebula=None): | ||
# Create one session | ||
one = self.pyone_session_create(open_nebula) | ||
|
||
# Create nic attributes | ||
nic_attributes = "NIC=[IP={}, NETWORK_ID={}, GATEWAY={}, METHOD={}]".format(ip_addr, | ||
network_id, | ||
gateway, | ||
method) | ||
|
||
# Attach nic | ||
one.vm.attachnic(vm_id, nic_attributes) | ||
|
||
# Wait for nic to attach | ||
lcm_state = self.wait_for_vm(one, vm_id, attach_timeout) | ||
|
||
# Check if nic was attached | ||
if lcm_state != 3: | ||
return (False, "Timed out waiting for VM {} to enter running state after attaching NIC".format(vm_id)) | ||
else: | ||
return (True, "Succesfully attached NIC to VM {}".format(vm_id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
name: vm_nic_attach | ||
runner_type: python-script | ||
description: Attaches a nic to the given VM | ||
enabled: true | ||
entry_point: vm_nic_attach.py | ||
parameters: | ||
attach_timeout: | ||
type: integer | ||
description: How long to wait to confirm the nic is attached | ||
required: false | ||
default: 30 | ||
gateway: | ||
type: string | ||
description: Gateway to specify for the NIC | ||
required: true | ||
ip_addr: | ||
type: string | ||
description: IP Address to specify for the NIC | ||
required: true | ||
method: | ||
type: string | ||
description: Method to specify for the NIC | ||
required: false | ||
default: "static" | ||
network_id: | ||
type: integer | ||
description: ID of the Network in Open Nebula to use for the NIC | ||
required: true | ||
vm_id: | ||
type: integer | ||
description: ID of the VM in Open Nebula | ||
required: true | ||
open_nebula: | ||
type: string | ||
description: > | ||
Pre-Configured Open Nebula connection details | ||
required: false | ||
default: ~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python | ||
# Copyright 2024 Encore Technologies | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from lib.action_base import BaseAction | ||
|
||
|
||
class VmNicDetach(BaseAction): | ||
def run(self, detach_timeout, nic_id, vm_id, open_nebula=None): | ||
# Create one session | ||
one = self.pyone_session_create(open_nebula) | ||
|
||
# Detach nic | ||
one.vm.detachnic(vm_id, nic_id) | ||
|
||
# Wait for nic to detach | ||
lcm_state = self.wait_for_vm(one, vm_id, detach_timeout) | ||
|
||
# Check if nic was detached | ||
if lcm_state != 3: | ||
return (False, "Timed out waiting for VM {} to enter running state after detaching NIC".format(vm_id)) | ||
else: | ||
return (True, "Succesfully detached NIC from VM {}".format(vm_id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
name: vm_nic_detach | ||
runner_type: python-script | ||
description: Detaches a nic from the given VM | ||
enabled: true | ||
entry_point: vm_nic_detach.py | ||
parameters: | ||
detach_timeout: | ||
type: integer | ||
description: How long to wait to confirm the nic is detached | ||
required: false | ||
default: 30 | ||
nic_id: | ||
type: integer | ||
description: ID of the nic on the VM that we want to detach | ||
required: true | ||
vm_id: | ||
type: integer | ||
description: ID of the VM to detach the nic from | ||
required: true | ||
open_nebula: | ||
type: string | ||
description: > | ||
Pre-Configured Open Nebula connection details | ||
required: false | ||
default: ~ |