-
Notifications
You must be signed in to change notification settings - Fork 40
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
Feat/volume groups #305
Open
Gevorg-Khachatryan-97
wants to merge
58
commits into
main
Choose a base branch
from
feat/volume_groups
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat/volume groups #305
Changes from 23 commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
70c4f5a
volume groups module
500583a
black fix
alaa-bish 6149e89
volume groups module, disks
5245925
volume groups module, default spec
f2745b3
Merge remote-tracking branch 'origin/feat/volume_groups' into feat/vo…
ab90fd9
sanity fix
alaa-bish 8c93b89
volume groups module, vms, clients
24900eb
Merge branch 'main' into feat/volume_groups
efe2aec
volume groups module, clients
03e2cd7
sanity fix
alaa-bish 280fdbc
volume groups delete, clients detaching
c07fd6f
Merge remote-tracking branch 'origin/feat/volume_groups' into feat/vo…
6b40e91
volume groups delete, vms detaching
a22a5ed
vms fixes, requirements
4aacccf
doc fix
alaa-bish 6c2ac7a
attachment fixes
9d93ee5
Merge remote-tracking branch 'origin/feat/volume_groups' into feat/vo…
73e3ee6
doc fix
alaa-bish 84a67da
Merge branch 'feat/volume_groups' of https://github.com/nutanix/nutan…
alaa-bish db02f43
black fix
alaa-bish 4b4c23b
disks, requirements
56dc345
black fix
alaa-bish 7dd12fc
chap auth validation
dd7fd23
optimizing
0cb8659
vg base spec idempotency
f2585bf
black fix
alaa-bish c5dba97
vg disks update
7671d2f
Merge remote-tracking branch 'origin/feat/volume_groups' into feat/vo…
e952ed6
sanity fix
alaa-bish cbc18a3
vg disks update, fix
378ff7f
Merge remote-tracking branch 'origin/feat/volume_groups' into feat/vo…
d0b910d
black fix
alaa-bish 734b0dd
vg disks update, fix
bada3e5
Merge remote-tracking branch 'origin/feat/volume_groups' into feat/vo…
120bf5c
vg disks idempotency
fcab4eb
black fix
alaa-bish 88453b6
vg vms and clients update
6442d44
sanity fix
alaa-bish 0bf05ff
vg vms and clients update
760417c
response fixes
7e2c148
black fix
alaa-bish d30d293
fixes
cd12727
fixes
5185789
fixes
3978fb0
Merge branch 'main' into feat/volume_groups
91f3eb0
volume group's info module
4905add
volume group's info module fix
667d438
sanity fix
alaa-bish 61a6498
volume group's module fix
ceb9cc4
volume group's module fix, clients attaching by uuid
465e19f
volume group's module fix, clients requirements
74bc2d3
volume group's module fix, clients requirements
4854a98
volume group's module fix, result status fix
68108e5
sub tusks messages
df88adf
black fix
alaa-bish df9cdf5
sub tasks messages
a82ef32
Merge remote-tracking branch 'origin/feat/volume_groups' into feat/vo…
892624e
sub tasks failing fixes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,3 +71,4 @@ action_groups: | |
- ntnx_ndb_slas_info | ||
- ntnx_ndb_databases | ||
- ntnx_ndb_clusters_info | ||
- ntnx_volume_groups |
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,54 @@ | ||
# This file is part of Ansible | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
from __future__ import absolute_import, division, print_function | ||
|
||
__metaclass__ = type | ||
|
||
from copy import deepcopy | ||
|
||
|
||
class Clients: | ||
@classmethod | ||
def get_spec(cls, iscsi_client, chap_auth=False): | ||
payload = cls._get_default_spec() | ||
spec, error = cls._build_spec_iscsi_client(payload, iscsi_client, chap_auth) | ||
if error: | ||
return None, error | ||
return spec, None | ||
|
||
@staticmethod | ||
def _get_default_spec(): | ||
return deepcopy({"enabledAuthentications": "NONE"}) | ||
|
||
@staticmethod | ||
def _build_spec_iscsi_client(payload, iscsi_client, chap_auth): | ||
|
||
if iscsi_client.get("uuid"): | ||
payload["extId"] = iscsi_client["uuid"] | ||
elif iscsi_client.get("iscsi_iqn"): | ||
payload["iscsiInitiatorName"] = iscsi_client["iscsi_iqn"] | ||
elif iscsi_client.get("iscsi_ip"): | ||
payload["iscsiInitiatorNetworkId"] = { | ||
"$objectType": "common.v1.config.IPAddressOrFQDN", | ||
"$reserved": { | ||
"$fqObjectType": "common.v1.r0.a3.config.IPAddressOrFQDN" | ||
}, | ||
"$unknownFields": {}, | ||
"ipv4": { | ||
"$objectType": "common.v1.config.IPv4Address", | ||
"$reserved": { | ||
"$fqObjectType": "common.v1.r0.a3.config.IPv4Address" | ||
}, | ||
"$unknownFields": {}, | ||
"value": iscsi_client["iscsi_ip"], | ||
}, | ||
} | ||
if iscsi_client.get("client_password"): | ||
if chap_auth: | ||
payload["clientSecret"] = iscsi_client["client_password"] | ||
|
||
payload["enabledAuthentications"] = "CHAP" | ||
else: | ||
error = "parameters are required together: CHAP_auth, client_password" | ||
return None, error | ||
return payload, None |
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,55 @@ | ||
# This file is part of Ansible | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
from __future__ import absolute_import, division, print_function | ||
|
||
__metaclass__ = type | ||
|
||
from copy import deepcopy | ||
|
||
from .groups import get_entity_uuid | ||
|
||
|
||
class VDisks: | ||
@classmethod | ||
def get_spec(cls, module, vdisk): | ||
payload = cls._get_default_spec() | ||
spec, error = cls._build_spec_vdisk(module, payload, vdisk) | ||
if error: | ||
return None, error | ||
return spec, None | ||
|
||
@staticmethod | ||
def _get_default_spec(): | ||
return deepcopy( | ||
{ | ||
"diskSizeBytes": None, | ||
"diskDataSourceReference": { | ||
"$objectType": "common.v1.config.EntityReference", | ||
"$reserved": { | ||
"$fqObjectType": "common.v1.r0.a3.config.EntityReference" | ||
}, | ||
"$unknownFields": {}, | ||
"extId": None, | ||
"entityType": "STORAGE_CONTAINER", | ||
}, | ||
} | ||
) | ||
|
||
@staticmethod | ||
def _build_spec_vdisk(module, payload, vdisk): | ||
|
||
disk_size_bytes = vdisk["size_gb"] * 1024 * 1024 * 1024 | ||
|
||
payload["diskSizeBytes"] = disk_size_bytes | ||
uuid, error = get_entity_uuid( | ||
vdisk["storage_container"], | ||
module, | ||
key="container_name", | ||
entity_type="storage_container", | ||
) | ||
if error: | ||
return None, error | ||
|
||
payload["diskDataSourceReference"]["extId"] = uuid | ||
|
||
return payload, None |
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,156 @@ | ||
# This file is part of Ansible | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
from __future__ import absolute_import, division, print_function | ||
|
||
__metaclass__ = type | ||
|
||
from copy import deepcopy | ||
|
||
from .clusters import get_cluster_uuid | ||
from .prism import Prism | ||
from .vms import get_vm_uuid | ||
|
||
|
||
class VolumeGroup(Prism): | ||
__BASEURL__ = "/api/storage/v4.0.a2/config" | ||
|
||
def __init__(self, module): | ||
resource_type = "/volume-groups" | ||
super(VolumeGroup, self).__init__(module, resource_type=resource_type) | ||
self.build_spec_methods = { | ||
"name": self._build_spec_name, | ||
"desc": self._build_spec_desc, | ||
"cluster": self._build_spec_cluster, | ||
"target_prefix": self._build_spec_target_prefix, | ||
"target_password": self._build_spec_target_password, | ||
"load_balance": self._build_spec_load_balance, | ||
"flash_mode": self._build_spec_flash_mode, | ||
} | ||
|
||
def create_vdisk(self, spec, volume_group_uuid, method="POST", endpoint="disks"): | ||
Gevorg-Khachatryan-97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
resp = self.update(spec, volume_group_uuid, method=method, endpoint=endpoint) | ||
resp["task_uuid"] = resp["data"]["extId"][-36:] | ||
return resp | ||
|
||
def attach_vm( | ||
self, spec, volume_group_uuid, method="POST", endpoint="$actions/attach-vm" | ||
Gevorg-Khachatryan-97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
): | ||
|
||
resp = self.update(spec, volume_group_uuid, method=method, endpoint=endpoint) | ||
resp["task_uuid"] = resp["data"]["extId"][-36:] | ||
return resp | ||
|
||
def attach_iscsi_client( | ||
self, | ||
spec, | ||
volume_group_uuid, | ||
method="POST", | ||
endpoint="/$actions/attach-iscsi-client", | ||
): | ||
|
||
resp = self.update(spec, volume_group_uuid, method=method, endpoint=endpoint) | ||
resp["task_uuid"] = resp["data"]["extId"][-36:] | ||
return resp | ||
|
||
def detach_vm(self, volume_group_uuid, vm, method="POST"): | ||
vm_uuid = vm["extId"] | ||
endpoint = "$actions/detach-vm/{0}".format(vm_uuid) | ||
resp = self.update(uuid=volume_group_uuid, method=method, endpoint=endpoint) | ||
resp["task_uuid"] = resp["data"]["extId"][-36:] | ||
return resp | ||
|
||
def detach_iscsi_client(self, volume_group_uuid, client, method="POST"): | ||
client_uuid = client["extId"] | ||
endpoint = "$actions/detach-iscsi-client/{0}".format(client_uuid) | ||
resp = self.update(uuid=volume_group_uuid, method=method, endpoint=endpoint) | ||
resp["task_uuid"] = resp["data"]["extId"][-36:] | ||
return resp | ||
|
||
def _get_default_spec(self): | ||
return deepcopy( | ||
{ | ||
"name": "", | ||
"loadBalanceVmAttachments": False, | ||
"sharingStatus": "SHARED", | ||
"clusterReference": None, | ||
"usageType": "USER", | ||
} | ||
) | ||
|
||
def _build_spec_name(self, payload, value): | ||
payload["name"] = value | ||
return payload, None | ||
|
||
def _build_spec_desc(self, payload, value): | ||
payload["description"] = value | ||
return payload, None | ||
|
||
def _build_spec_target_prefix(self, payload, value): | ||
payload["iscsiTargetPrefix"] = value | ||
return payload, None | ||
|
||
def _build_spec_target_password(self, payload, value): | ||
payload["targetSecret"] = value | ||
payload["enabledAuthentications"] = "CHAP" | ||
return payload, None | ||
|
||
def _build_spec_load_balance(self, payload, value): | ||
payload["loadBalanceVmAttachments"] = value | ||
return payload, None | ||
|
||
def _build_spec_flash_mode(self, payload, value): | ||
|
||
if value: | ||
payload["storageFeatures"] = { | ||
"$objectType": "storage.v4.config.StorageFeatures", | ||
"$reserved": { | ||
"$fqObjectType": "storage.v4.r0.a2.config.StorageFeatures" | ||
}, | ||
"$unknownFields": {}, | ||
"flashMode": { | ||
"$objectType": "storage.v4.config.FlashMode", | ||
"$reserved": {"$fqObjectType": "storage.v4.r0.a2.config.FlashMode"}, | ||
"$unknownFields": {}, | ||
"isEnabled": True, | ||
}, | ||
} | ||
return payload, None | ||
|
||
def _build_spec_cluster(self, payload, param): | ||
uuid, err = get_cluster_uuid(param, self.module) | ||
if err: | ||
return None, err | ||
payload["clusterReference"] = uuid | ||
return payload, None | ||
|
||
def get_vm_spec(self, vm): | ||
uuid, error = get_vm_uuid(vm, self.module) | ||
if error: | ||
return None, error | ||
spec = {"extId": uuid} | ||
return spec, None | ||
|
||
def get_client_spec(self, client): | ||
spec = {"extId": client["uuid"]} | ||
return spec, None | ||
|
||
|
||
# Helper functions | ||
|
||
|
||
def get_volume_group_uuid(config, module): | ||
if "name" in config: | ||
service_group = VolumeGroup(module) | ||
name = config["name"] | ||
uuid = service_group.get_uuid(name) | ||
if not uuid: | ||
error = "Volume Group {0} not found.".format(name) | ||
return None, error | ||
elif "uuid" in config: | ||
uuid = config["uuid"] | ||
else: | ||
error = "Config {0} doesn't have name or uuid key".format(config) | ||
return None, error | ||
|
||
return uuid, None |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can create a convert func in utils which can be used by other modules as well