self.logger.debug("Config: %s", config)
scopes = ["https://www.googleapis.com/auth/cloud-platform"]
self.credentials = None
- if (
- "credentials" in config
- ):
+ if "credentials" in config:
self.logger.debug("Setting credentials")
# Settings Google Cloud credentials dict
credentials_body = config["credentials"]
if not network_list:
return []
else:
- self.logger.debug(
- "get_network Return: network_list[0] %s", network_list[0]
- )
+ self.logger.debug("get_network Return: network_list[0] %s", network_list[0])
return network_list[0]
def delete_network(self, net_id, created_items=None):
return vm_name_aux.lower()
def get_flavor_id_from_data(self, flavor_dict):
- self.logger.debug(
- "get_flavor_id_from_data begin: flavor_dict %s", flavor_dict
- )
+ self.logger.debug("get_flavor_id_from_data begin: flavor_dict %s", flavor_dict)
filter_dict = flavor_dict or {}
try:
cpus = filter_dict.get("vcpus") or 0
memMB = filter_dict.get("ram") or 0
- numberInterfaces = len(filter_dict.get("interfaces", [])) or 4 # Workaround (it should be 0)
+ # Workaround (it should be 0)
+ numberInterfaces = len(filter_dict.get("interfaces", [])) or 4
# Filter
filtered_machines = []
self.logger.debug("New random name: %s", random_name)
break
else:
- self.logger.error("Exception generating random name (%s) for the instance", name)
+ self.logger.error(
+ "Exception generating random name (%s) for the instance", name
+ )
self._format_vimconn_exception(e)
return random_name
] = "regions/%s/subnetworks/" % self.region + net.get("name")
else:
net_iface["subnetwork"] = net.get("net_id")
- # According to documentation "type" can be only ONE_TO_ONE_NAT and the recomended value for "name" is "External NAT",
- # so an external IP will be generated for the instance
- # TODO: check if it's possible to allow internet access to the instance with no external IP
- net_iface["accessConfigs"] = [
- {"type": "ONE_TO_ONE_NAT", "name": "External NAT"}
- ]
+ # In order to get an external IP address, the key "accessConfigs" must be used
+ # in the interace. It has to be of type "ONE_TO_ONE_NAT" and name "External NAT"
+ if net.get("floating_ip", False) or (
+ net["use"] == "mgmt" and self.config.get("use_floating_ip")
+ ):
+ net_iface["accessConfigs"] = [
+ {"type": "ONE_TO_ONE_NAT", "name": "External NAT"}
+ ]
network_interfaces.append(net_iface)
self.logger.error("new_vminstance rollback fail {}".format(e2))
else:
- self.logger.debug("Exception creating new vminstance: %s", e, exc_info=True)
+ self.logger.debug(
+ "Exception creating new vminstance: %s", e, exc_info=True
+ )
self._format_vimconn_exception(e)
-
def _build_metadata(self, vm_name, cloud_config):
# initial metadata
if cloud_config:
self.logger.debug("cloud config: %s", cloud_config)
_, userdata = self._create_user_data(cloud_config)
- metadata["items"].append(
- {"key": "user-data", "value": userdata}
- )
+ metadata["items"].append({"key": "user-data", "value": userdata})
# either password of ssh-keys are required
# we will always use ssh-keys, in case it is not available we will generate it
return metadata
-
def _generate_keys(self):
"""Method used to generate a pair of private/public keys.
This method is used because to create a vm in Azure we always need a key or a password
return private_key, public_key
-
def _get_unused_vm_name(self, vm_name):
"""
Checks the vm name and in case it is used adds a suffix to the name to allow creation
)
)
self._format_vimconn_exception(e)
-