projects
/
osm
/
RO.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Partial fix for Bug 1408
[osm/RO.git]
/
RO-VIM-azure
/
osm_rovim_azure
/
vimconn_azure.py
diff --git
a/RO-VIM-azure/osm_rovim_azure/vimconn_azure.py
b/RO-VIM-azure/osm_rovim_azure/vimconn_azure.py
index
fc36638
..
3752f29
100755
(executable)
--- a/
RO-VIM-azure/osm_rovim_azure/vimconn_azure.py
+++ b/
RO-VIM-azure/osm_rovim_azure/vimconn_azure.py
@@
-14,7
+14,7
@@
##
import base64
##
import base64
-from osm_ro import vimconn
+from osm_ro
_plugin
import vimconn
import logging
import netaddr
import re
import logging
import netaddr
import re
@@
-41,7
+41,7
@@
if getenv('OSMRO_PDB_DEBUG'):
pdb.set_trace()
pdb.set_trace()
-class vimconnector(vimconn.
vimc
onnector):
+class vimconnector(vimconn.
VimC
onnector):
# Translate azure provisioning state to OSM provision state
# The first three ones are the transitional status once a user initiated action has been requested
# Translate azure provisioning state to OSM provision state
# The first three ones are the transitional status once a user initiated action has been requested
@@
-85,7
+85,7
@@
class vimconnector(vimconn.vimconnector):
"^Standard_B" will select a serie B maybe for test environment
"""
"^Standard_B" will select a serie B maybe for test environment
"""
- vimconn.
vimc
onnector.__init__(self, uuid, name, tenant_id, tenant_name, url, url_admin, user, passwd, log_level,
+ vimconn.
VimC
onnector.__init__(self, uuid, name, tenant_id, tenant_name, url, url_admin, user, passwd, log_level,
config, persistent_info)
# Variable that indicates if client must be reloaded or initialized
config, persistent_info)
# Variable that indicates if client must be reloaded or initialized
@@
-112,19
+112,19
@@
class vimconnector(vimconn.vimconnector):
self._config["subscription_id"] = config.get('subscription_id')
# self.logger.debug('Setting subscription to: %s', self.config["subscription_id"])
else:
self._config["subscription_id"] = config.get('subscription_id')
# self.logger.debug('Setting subscription to: %s', self.config["subscription_id"])
else:
- raise vimconn.
vimc
onnException('Subscription not specified')
+ raise vimconn.
VimC
onnException('Subscription not specified')
# REGION
if 'region_name' in config:
self.region = config.get('region_name')
else:
# REGION
if 'region_name' in config:
self.region = config.get('region_name')
else:
- raise vimconn.
vimc
onnException('Azure region_name is not specified at config')
+ raise vimconn.
VimC
onnException('Azure region_name is not specified at config')
# RESOURCE_GROUP
if 'resource_group' in config:
self.resource_group = config.get('resource_group')
else:
# RESOURCE_GROUP
if 'resource_group' in config:
self.resource_group = config.get('resource_group')
else:
- raise vimconn.
vimc
onnException('Azure resource_group is not specified at config')
+ raise vimconn.
VimC
onnException('Azure resource_group is not specified at config')
# VNET_NAME
if 'vnet_name' in config:
# VNET_NAME
if 'vnet_name' in config:
@@
-168,23
+168,23
@@
class vimconnector(vimconn.vimconnector):
resource = str(resource_id.split('/')[-1])
return resource
except Exception as e:
resource = str(resource_id.split('/')[-1])
return resource
except Exception as e:
- raise vimconn.
vimc
onnException("Unable to get resource name from resource_id '{}' Error: '{}'".
+ raise vimconn.
VimC
onnException("Unable to get resource name from resource_id '{}' Error: '{}'".
format(resource_id, e))
def _get_location_from_resource_group(self, resource_group_name):
try:
location = self.conn.resource_groups.get(resource_group_name).location
return location
format(resource_id, e))
def _get_location_from_resource_group(self, resource_group_name):
try:
location = self.conn.resource_groups.get(resource_group_name).location
return location
- except Exception
as e
:
- raise vimconn.
vimc
onnNotFoundException("Location '{}' not found".format(resource_group_name))
+ except Exception:
+ raise vimconn.
VimC
onnNotFoundException("Location '{}' not found".format(resource_group_name))
def _get_resource_group_name_from_resource_id(self, resource_id):
try:
rg = str(resource_id.split('/')[4])
return rg
def _get_resource_group_name_from_resource_id(self, resource_id):
try:
rg = str(resource_id.split('/')[4])
return rg
- except Exception
as e
:
- raise vimconn.
vimc
onnException("Unable to get resource group from invalid resource_id format '{}'".
+ except Exception:
+ raise vimconn.
VimC
onnException("Unable to get resource group from invalid resource_id format '{}'".
format(resource_id))
def _get_net_name_from_resource_id(self, resource_id):
format(resource_id))
def _get_net_name_from_resource_id(self, resource_id):
@@
-192,8
+192,8
@@
class vimconnector(vimconn.vimconnector):
try:
net_name = str(resource_id.split('/')[8])
return net_name
try:
net_name = str(resource_id.split('/')[8])
return net_name
- except Exception
as e
:
- raise vimconn.
vimc
onnException("Unable to get azure net_name from invalid resource_id format '{}'".
+ except Exception:
+ raise vimconn.
VimC
onnException("Unable to get azure net_name from invalid resource_id format '{}'".
format(resource_id))
def _check_subnets_for_vm(self, net_list):
format(resource_id))
def _check_subnets_for_vm(self, net_list):
@@
-208,16
+208,16
@@
class vimconnector(vimconn.vimconnector):
"""
Transforms a generic or azure exception to a vimcommException
"""
"""
Transforms a generic or azure exception to a vimcommException
"""
- if isinstance(e, vimconn.
vimc
onnException):
+ if isinstance(e, vimconn.
VimC
onnException):
raise
elif isinstance(e, AuthenticationError):
raise
elif isinstance(e, AuthenticationError):
- raise vimconn.
vimc
onnAuthException(type(e).__name__ + ': ' + str(e))
+ raise vimconn.
VimC
onnAuthException(type(e).__name__ + ': ' + str(e))
elif isinstance(e, ConnectionError):
elif isinstance(e, ConnectionError):
- raise vimconn.
vimc
onnConnectionException(type(e).__name__ + ': ' + str(e))
+ raise vimconn.
VimC
onnConnectionException(type(e).__name__ + ': ' + str(e))
else:
# In case of generic error recreate client
self.reload_client = True
else:
# In case of generic error recreate client
self.reload_client = True
- raise vimconn.
vimc
onnException(type(e).__name__ + ': ' + str(e))
+ raise vimconn.
VimC
onnException(type(e).__name__ + ': ' + str(e))
def _check_or_create_resource_group(self):
"""
def _check_or_create_resource_group(self):
"""
@@
-314,7
+314,7
@@
class vimconnector(vimconn.vimconnector):
self.logger.debug('dinamically obtained ip_profile: %s', ip_range)
break
else:
self.logger.debug('dinamically obtained ip_profile: %s', ip_range)
break
else:
- raise vimconn.
vimc
onnException("Cannot find a non-used subnet range in {}".
+ raise vimconn.
VimC
onnException("Cannot find a non-used subnet range in {}".
format(self.vnet_address_space))
else:
ip_profile = {"subnet_address": ip_profile['subnet_address']}
format(self.vnet_address_space))
else:
ip_profile = {"subnet_address": ip_profile['subnet_address']}
@@
-374,7
+374,8
@@
class vimconnector(vimconn.vimconnector):
if mac_address:
net_ifz['mac_address'] = mac_address
if mac_address:
net_ifz['mac_address'] = mac_address
- async_nic_creation = self.conn_vnet.network_interfaces.create_or_update(self.resource_group, nic_name, net_ifz)
+ async_nic_creation = self.conn_vnet.network_interfaces.create_or_update(self.resource_group, nic_name,
+ net_ifz)
nic_data = async_nic_creation.result()
created_items[nic_data.id] = True
self.logger.debug('created nic name %s', nic_name)
nic_data = async_nic_creation.result()
created_items[nic_data.id] = True
self.logger.debug('created nic name %s', nic_name)
@@
-416,25
+417,25
@@
class vimconnector(vimconn.vimconnector):
"""
It is not allowed to create new flavors in Azure, must always use an existing one
"""
"""
It is not allowed to create new flavors in Azure, must always use an existing one
"""
- raise vimconn.
vimc
onnAuthException("It is not possible to create new flavors in AZURE")
+ raise vimconn.
VimC
onnAuthException("It is not possible to create new flavors in AZURE")
def new_tenant(self, tenant_name, tenant_description):
"""
It is not allowed to create new tenants in azure
"""
def new_tenant(self, tenant_name, tenant_description):
"""
It is not allowed to create new tenants in azure
"""
- raise vimconn.
vimc
onnAuthException("It is not possible to create a TENANT in AZURE")
+ raise vimconn.
VimC
onnAuthException("It is not possible to create a TENANT in AZURE")
def new_image(self, image_dict):
"""
It is not allowed to create new images in Azure, must always use an existing one
"""
def new_image(self, image_dict):
"""
It is not allowed to create new images in Azure, must always use an existing one
"""
- raise vimconn.
vimc
onnAuthException("It is not possible to create new images in AZURE")
+ raise vimconn.
VimC
onnAuthException("It is not possible to create new images in AZURE")
def get_image_id_from_path(self, path):
"""Get the image id from image path in the VIM database.
Returns the image_id or raises a vimconnNotFoundException
"""
def get_image_id_from_path(self, path):
"""Get the image id from image path in the VIM database.
Returns the image_id or raises a vimconnNotFoundException
"""
- raise vimconn.
vimc
onnAuthException("It is not possible to obtain image from path in AZURE")
+ raise vimconn.
VimC
onnAuthException("It is not possible to obtain image from path in AZURE")
def get_image_list(self, filter_dict={}):
"""Obtain tenant images from VIM
def get_image_list(self, filter_dict={}):
"""Obtain tenant images from VIM
@@
-472,10
+473,10
@@
class vimconnector(vimconn.vimconnector):
else:
image_list = self._get_sku_image_list(publisher, offer, sku)
else:
else:
image_list = self._get_sku_image_list(publisher, offer, sku)
else:
- raise vimconn.
vimc
onnAuthException(
+ raise vimconn.
VimC
onnAuthException(
"List images in Azure must include name param with at least publisher")
else:
"List images in Azure must include name param with at least publisher")
else:
- raise vimconn.
vimc
onnAuthException("List images in Azure must include name param with at"
+ raise vimconn.
VimC
onnAuthException("List images in Azure must include name param with at"
" least publisher")
return image_list
" least publisher")
return image_list
@@
-608,13
+609,11
@@
class vimconnector(vimconn.vimconnector):
# At least one network must be provided
if not net_list:
# At least one network must be provided
if not net_list:
- raise vimconn.
vimc
onnException("At least one net must be provided to create a new VM")
+ raise vimconn.
VimC
onnException("At least one net must be provided to create a new VM")
# image_id are several fields of the image_id
image_reference = self._get_image_reference(image_id)
# image_id are several fields of the image_id
image_reference = self._get_image_reference(image_id)
-
-
try:
virtual_machine = None
created_items = {}
try:
virtual_machine = None
created_items = {}
@@
-629,7
+628,7
@@
class vimconnector(vimconn.vimconnector):
nic_name = vm_name + '-nic-' + str(idx)
vm_nic, nic_items = self._create_nic(net, nic_name, net.get('ip_address'), created_items)
vm_nics.append({'id': str(vm_nic.id)})
nic_name = vm_name + '-nic-' + str(idx)
vm_nic, nic_items = self._create_nic(net, nic_name, net.get('ip_address'), created_items)
vm_nics.append({'id': str(vm_nic.id)})
-
#
net['vim_id'] = vm_nic.id
+ net['vim_id'] = vm_nic.id
# cloud-init configuration
# cloud config
# cloud-init configuration
# cloud config
@@
-778,7
+777,7
@@
class vimconnector(vimconn.vimconnector):
else:
return availability_zone_list[availability_zone_index]
else:
else:
return availability_zone_list[availability_zone_index]
else:
- raise vimconn.
vimc
onnConflictException("No enough availability zones at VIM for this deployment")
+ raise vimconn.
VimC
onnConflictException("No enough availability zones at VIM for this deployment")
def _get_azure_availability_zones(self):
return self.AZURE_ZONES
def _get_azure_availability_zones(self):
return self.AZURE_ZONES
@@
-838,9
+837,9
@@
class vimconnector(vimconn.vimconnector):
created_items[data_disk.id] = True
else:
created_items[data_disk.id] = True
else:
- raise vimconn.
vimc
onnNotFoundException("Invalid image_id: %s ", image_id)
+ raise vimconn.
VimC
onnNotFoundException("Invalid image_id: %s ", image_id)
else:
else:
- raise vimconn.
vimc
onnNotFoundException("Invalid image_id: %s ", image_id)
+ raise vimconn.
VimC
onnNotFoundException("Invalid image_id: %s ", image_id)
# Attach the disk created
virtual_machine.storage_profile.data_disks.append({
# Attach the disk created
virtual_machine.storage_profile.data_disks.append({
@@
-853,7
+852,7
@@
class vimconnector(vimconn.vimconnector):
'disk_size_gb': disk.get('size')
})
self.logger.debug("attach disk name: %s", disk_name)
'disk_size_gb': disk.get('size')
})
self.logger.debug("attach disk name: %s", disk_name)
-
async_disk_attach =
self.conn_compute.virtual_machines.create_or_update(
+ self.conn_compute.virtual_machines.create_or_update(
self.resource_group,
virtual_machine.name,
virtual_machine
self.resource_group,
virtual_machine.name,
virtual_machine
@@
-886,8
+885,8
@@
class vimconnector(vimconn.vimconnector):
'sku': sku,
'version': version
}
'sku': sku,
'version': version
}
- except Exception
as e
:
- raise vimconn.
vimc
onnException(
+ except Exception:
+ raise vimconn.
VimC
onnException(
"Unable to get image_reference from invalid image_id format: '{}'".format(image_id))
# Azure VM names can not have some special characters
"Unable to get image_reference from invalid image_id format: '{}'".format(image_id))
# Azure VM names can not have some special characters
@@
-938,7
+937,7
@@
class vimconnector(vimconn.vimconnector):
if listedFilteredSizes:
return listedFilteredSizes[0]['name']
if listedFilteredSizes:
return listedFilteredSizes[0]['name']
- raise vimconn.
vimc
onnNotFoundException("Cannot find any flavor matching '{}'".format(str(flavor_dict)))
+ raise vimconn.
VimC
onnNotFoundException("Cannot find any flavor matching '{}'".format(str(flavor_dict)))
except Exception as e:
self._format_vimconn_exception(e)
except Exception as e:
self._format_vimconn_exception(e)
@@
-967,7
+966,7
@@
class vimconnector(vimconn.vimconnector):
self._reload_connection()
return True
except Exception as e:
self._reload_connection()
return True
except Exception as e:
- raise vimconn.
vimc
onnException("Connectivity issue with Azure API: {}".format(e))
+ raise vimconn.
VimC
onnException("Connectivity issue with Azure API: {}".format(e))
def get_network(self, net_id):
def get_network(self, net_id):
@@
-979,7
+978,7
@@
class vimconnector(vimconn.vimconnector):
network_list = self.get_network_list(filter_dict)
if not network_list:
network_list = self.get_network_list(filter_dict)
if not network_list:
- raise vimconn.
vimc
onnNotFoundException("network '{}' not found".format(net_id))
+ raise vimconn.
VimC
onnNotFoundException("network '{}' not found".format(net_id))
else:
return network_list[0]
else:
return network_list[0]
@@
-992,7
+991,7
@@
class vimconnector(vimconn.vimconnector):
filter_dict = {'name': res_name}
network_list = self.get_network_list(filter_dict)
if not network_list:
filter_dict = {'name': res_name}
network_list = self.get_network_list(filter_dict)
if not network_list:
- raise vimconn.
vimc
onnNotFoundException("network '{}' not found".format(net_id))
+ raise vimconn.
VimC
onnNotFoundException("network '{}' not found".format(net_id))
try:
# Subnet API fails (CloudError: Azure Error: ResourceNotFound)
try:
# Subnet API fails (CloudError: Azure Error: ResourceNotFound)
@@
-1003,7
+1002,7
@@
class vimconnector(vimconn.vimconnector):
except CloudError as e:
if e.error.error and "notfound" in e.error.error.lower():
except CloudError as e:
if e.error.error and "notfound" in e.error.error.lower():
- raise vimconn.
vimc
onnNotFoundException("network '{}' not found".format(net_id))
+ raise vimconn.
VimC
onnNotFoundException("network '{}' not found".format(net_id))
else:
self._format_vimconn_exception(e)
except Exception as e:
else:
self._format_vimconn_exception(e)
except Exception as e:
@@
-1084,7
+1083,7
@@
class vimconnector(vimconn.vimconnector):
except CloudError as e:
if e.error.error and "notfound" in e.error.error.lower():
except CloudError as e:
if e.error.error and "notfound" in e.error.error.lower():
- raise vimconn.
vimc
onnNotFoundException("No vm instance found '{}'".format(vm_id))
+ raise vimconn.
VimC
onnNotFoundException("No vm instance found '{}'".format(vm_id))
else:
self._format_vimconn_exception(e)
except Exception as e:
else:
self._format_vimconn_exception(e)
except Exception as e:
@@
-1109,7
+1108,7
@@
class vimconnector(vimconn.vimconnector):
if not v: # skip already deleted
continue
if not v: # skip already deleted
continue
- #self.logger.debug("Must delete item id: %s", item_id)
+ #
self.logger.debug("Must delete item id: %s", item_id)
# Obtain type, supported nic, disk or public ip
parsed_id = azure_tools.parse_resource_id(item_id)
# Obtain type, supported nic, disk or public ip
parsed_id = azure_tools.parse_resource_id(item_id)
@@
-1171,20
+1170,20
@@
class vimconnector(vimconn.vimconnector):
return None
except CloudError as e:
if e.error.error and "notfound" in e.error.error.lower():
return None
except CloudError as e:
if e.error.error and "notfound" in e.error.error.lower():
- raise vimconn.
vimc
onnNotFoundException("No vm found '{}'".format(vm_id))
+ raise vimconn.
VimC
onnNotFoundException("No vm found '{}'".format(vm_id))
else:
self._format_vimconn_exception(e)
except Exception as e:
self._format_vimconn_exception(e)
def delete_flavor(self, flavor_id):
else:
self._format_vimconn_exception(e)
except Exception as e:
self._format_vimconn_exception(e)
def delete_flavor(self, flavor_id):
- raise vimconn.
vimc
onnAuthException("It is not possible to delete a FLAVOR in AZURE")
+ raise vimconn.
VimC
onnAuthException("It is not possible to delete a FLAVOR in AZURE")
def delete_tenant(self, tenant_id,):
def delete_tenant(self, tenant_id,):
- raise vimconn.
vimc
onnAuthException("It is not possible to delete a TENANT in AZURE")
+ raise vimconn.
VimC
onnAuthException("It is not possible to delete a TENANT in AZURE")
def delete_image(self, image_id):
def delete_image(self, image_id):
- raise vimconn.
vimc
onnAuthException("It is not possible to delete a IMAGE in AZURE")
+ raise vimconn.
VimC
onnAuthException("It is not possible to delete a IMAGE in AZURE")
def get_vminstance(self, vm_id):
"""
def get_vminstance(self, vm_id):
"""
@@
-1197,7
+1196,7
@@
class vimconnector(vimconn.vimconnector):
vm = self.conn_compute.virtual_machines.get(self.resource_group, resName)
except CloudError as e:
if e.error.error and "notfound" in e.error.error.lower():
vm = self.conn_compute.virtual_machines.get(self.resource_group, resName)
except CloudError as e:
if e.error.error and "notfound" in e.error.error.lower():
- raise vimconn.
vimc
onnNotFoundException("No vminstance found '{}'".format(vm_id))
+ raise vimconn.
VimC
onnNotFoundException("No vminstance found '{}'".format(vm_id))
else:
self._format_vimconn_exception(e)
except Exception as e:
else:
self._format_vimconn_exception(e)
except Exception as e:
@@
-1222,7
+1221,7
@@
class vimconnector(vimconn.vimconnector):
}
return flavor
else:
}
return flavor
else:
- raise vimconn.
vimc
onnNotFoundException("flavor '{}' not found".format(flavor_id))
+ raise vimconn.
VimC
onnNotFoundException("flavor '{}' not found".format(flavor_id))
def get_tenant_list(self, filter_dict={}):
""" Obtains the list of tenants
def get_tenant_list(self, filter_dict={}):
""" Obtains the list of tenants
@@
-1290,7
+1289,7
@@
class vimconnector(vimconn.vimconnector):
"status": "VIM_ERROR",
"error_msg": str(e)
}
"status": "VIM_ERROR",
"error_msg": str(e)
}
- except vimconn.
vimc
onnNotFoundException as e:
+ except vimconn.
VimC
onnNotFoundException as e:
self.logger.error("VimConnNotFoundException %s when searching subnet", e)
out_nets[net_id] = {
"status": "DELETED",
self.logger.error("VimConnNotFoundException %s when searching subnet", e)
out_nets[net_id] = {
"status": "DELETED",