Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/devel' into upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Mar 10, 2017
2 parents 4e107e3 + c9b3a3f commit d9aeec3
Show file tree
Hide file tree
Showing 24 changed files with 402 additions and 466 deletions.
325 changes: 139 additions & 186 deletions IM/ConfManager.py

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions IM/InfrastructureInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,6 @@ def deserialize_auth(str_data):
newinf.auth = Authentication.deserialize(dic['auth'])
return newinf

def get_next_vm_id(self):
"""Get the next vm id available."""
with self._lock:
vmid = self.vm_id
self.vm_id += 1
return vmid

def delete(self):
"""
Set this Inf as deleted
Expand Down
228 changes: 94 additions & 134 deletions IM/InfrastructureManager.py

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions IM/VirtualMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ def __init__(self, inf, cloud_id, cloud, info, requested_radl, cloud_connector=N
"""Infrastructure which this VM is part of"""
self.id = cloud_id
"""The ID of the VM assigned by the cloud provider"""
if im_id is None:
self.im_id = inf.get_next_vm_id()
else:
self.im_id = im_id
self.im_id = im_id
"""The internal ID of the VM assigned by the IM"""
self.cloud = cloud
"""CloudInfo object with the information about the cloud provider"""
Expand Down
24 changes: 12 additions & 12 deletions IM/connectors/Azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import time
import uuid
from IM.uriparse import uriparse
from IM.VirtualMachine import VirtualMachine
from .CloudConnector import CloudConnector
Expand Down Expand Up @@ -342,7 +342,7 @@ def get_azure_vm_create_json(self, storage_account, vm_name, nics, radl, instanc
system.updateNewCredentialValues()
user_credentials = system.getCredentials()

os_disk_name = "osdisk-" + str(int(time.time() * 100))
os_disk_name = "osdisk-" + str(uuid.uuid1())

return {
'location': location,
Expand Down Expand Up @@ -474,18 +474,18 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):
res = []
i = 0
while i < num_vm:
group_name = None
try:
# Create the VM to get the nodename
now = int(time.time() * 100)
vm = VirtualMachine(inf, None, self.cloud, radl, requested_radl, self)
group_name = "rg-%s-%d" % (inf.id, vm.im_id)
storage_account_name = "st%d%d" % (now, vm.im_id)
uid = str(uuid.uuid1())
storage_account_name = "st-%s" % uid

vm_name = radl.systems[0].getValue("instance_name")
if vm_name:
vm_name = "%s%d" % (vm_name, now)
vm_name = "%s-%s" % (vm_name, uid)
else:
vm_name = "userimage%d" % now
vm_name = "userimage-%s" % uid

group_name = "rg-%s" % (vm_name)

# Create resource group for the VM
resource_client.resource_groups.create_or_update(group_name, {'location': location})
Expand All @@ -508,8 +508,7 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):
async_vm_creation = compute_client.virtual_machines.create_or_update(group_name, vm_name, vm_parameters)
azure_vm = async_vm_creation.result()

# Set the cloud id to the VM
vm.id = group_name + '/' + vm_name
vm = VirtualMachine(inf, group_name + '/' + vm_name, self.cloud, radl, requested_radl, self)
vm.info.systems[0].setValue('instance_id', group_name + '/' + vm_name)

self.attach_data_disks(vm, storage_account_name, credentials, subscription_id, location)
Expand All @@ -520,7 +519,8 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):
res.append((False, "Error creating the VM: " + str(ex)))

# Delete Resource group and everything in it
resource_client.resource_groups.delete(group_name)
if group_name:
resource_client.resource_groups.delete(group_name)

i += 1

Expand Down
5 changes: 3 additions & 2 deletions IM/connectors/AzureClassic.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import requests
import time
import os
import uuid
import tempfile
from IM.xmlobject import XMLObject
from IM.uriparse import uriparse
Expand Down Expand Up @@ -318,7 +319,7 @@ def gen_data_disks(self, system, storage_account):
disk_size = system.getFeature(
"disk." + str(cont) + ".size").getValue('G')

disk_name = "datadisk-1-" + str(int(time.time() * 100))
disk_name = "datadisk-1-" + str(uuid.uuid1())
disks += '''
<DataVirtualHardDisks>
<DataVirtualHardDisk>
Expand Down Expand Up @@ -436,7 +437,7 @@ def create_service(self, auth_data, region):
"""
Create a Azure Cloud Service and return the name
"""
service_name = "IM-" + str(int(time.time() * 100))
service_name = "IM-" + str(uuid.uuid1())
self.log_info("Create the service " + service_name + " in region: " + region)

try:
Expand Down
5 changes: 3 additions & 2 deletions IM/connectors/Docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import socket
import requests
import random
import uuid
from IM.uriparse import uriparse
from IM.VirtualMachine import VirtualMachine
from IM.config import Config
Expand Down Expand Up @@ -183,7 +184,7 @@ def _generate_create_svc_request_data(self, image_name, outports, vm, ssh_port,
if not name:
name = "imsvc"

svc_data['Name'] = "%s-%d" % (name, int(time.time() * 100))
svc_data['Name'] = "%s-%s" % (name, str(uuid.uuid1()))
svc_data['TaskTemplate'] = {}
svc_data['TaskTemplate']['ContainerSpec'] = {}
svc_data['TaskTemplate']['ContainerSpec']['Image'] = image_name
Expand Down Expand Up @@ -487,7 +488,7 @@ def _create_volumes(self, system, auth_data):
# user device as volume name
source = system.getValue("disk." + str(cont) + ".device")
if not source:
source = "d-%d-%d" % (int(time.time() * 100), cont)
source = "d-%s-%d" % (str(uuid.uuid1()), cont)
system.setValue("disk." + str(cont) + ".device", source)

# if the name of the source starts with / we assume it is a bind, so do not create a volume
Expand Down
3 changes: 2 additions & 1 deletion IM/connectors/EC2.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import time
import base64
import os
import uuid

try:
import boto.ec2
Expand Down Expand Up @@ -401,7 +402,7 @@ def create_security_group(self, conn, inf, radl, vpc=None):

def create_keypair(self, system, conn):
# create the keypair
keypair_name = "im-" + str(int(time.time() * 100))
keypair_name = "im-" + str(uuid.uuid1())
created = False

try:
Expand Down
7 changes: 4 additions & 3 deletions IM/connectors/GCE.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import time
import uuid
import os

try:
Expand Down Expand Up @@ -426,10 +427,10 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):
res = []
if num_vm > 1:
args['number'] = num_vm
args['base_name'] = "%s-%s" % (name.lower().replace("_", "-"), int(time.time() * 100))
args['base_name'] = "%s-%s" % (name.lower().replace("_", "-"), str(uuid.uuid1()))
nodes = driver.ex_create_multiple_nodes(**args)
else:
args['name'] = "%s-%s" % (name.lower().replace("_", "-"), int(time.time() * 100))
args['name'] = "%s-%s" % (name.lower().replace("_", "-"), str(uuid.uuid1()))
nodes = [driver.create_node(**args)]

for node in nodes:
Expand Down Expand Up @@ -600,7 +601,7 @@ def attach_volumes(self, vm, node):
"disk." + str(cont) + ".device")
self.log_debug(
"Creating a %d GB volume for the disk %d" % (int(disk_size), cont))
volume_name = "im-%d" % int(time.time() * 100.0)
volume_name = "im-%s" % str(uuid.uuid1())

location = self.get_node_location(node)
volume = node.driver.create_volume(
Expand Down
8 changes: 4 additions & 4 deletions IM/connectors/LibCloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import time
import uuid

try:
from libcloud.compute.base import NodeImage, NodeAuthSSHKey
Expand Down Expand Up @@ -224,7 +224,7 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):

args = {'size': instance_type,
'image': image,
'name': "%s-%s" % (name, int(time.time() * 100))}
'name': "%s-%s" % (name, str(uuid.uuid1()))}

keypair = None
public_key = system.getValue("disk.0.os.credentials.public_key")
Expand All @@ -240,7 +240,7 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):
else:
args["ex_keyname"] = keypair.name
elif not system.getValue("disk.0.os.credentials.password"):
keypair_name = "im-%d" % int(time.time() * 100.0)
keypair_name = "im-%s" % str(uuid.uuid1())
keypair = driver.create_key_pair(keypair_name)
system.setUserKeyCredentials(
system.getCredentials().username, None, keypair.private_key)
Expand Down Expand Up @@ -584,7 +584,7 @@ def attach_volumes(self, vm, node):
if disk_device:
disk_device = "/dev/" + disk_device
self.log_debug("Creating a %d GB volume for the disk %d" % (int(disk_size), cont))
volume_name = "im-%d" % int(time.time() * 100.0)
volume_name = "im-%s" % str(uuid.uuid1())

location = self.get_node_location(node)
volume = node.driver.create_volume(int(disk_size), volume_name, location=location)
Expand Down
2 changes: 1 addition & 1 deletion contextualization/ctxt_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def wait_thread(thread_data, output=None):
thread, result = thread_data
thread.join()
try:
_, (return_code, hosts_with_errors), _ = result.get(False)
_, (return_code, hosts_with_errors), _ = result.get(timeout=60)
except:
CtxtAgent.logger.exception('Error getting ansible results.')
return_code = -1
Expand Down
6 changes: 4 additions & 2 deletions doc/source/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,11 @@ keys are:
used as the label in the *deploy* section in the RADL.

* ``subscription_id`` indicates the subscription_id name associated to the credential.
This field is only used in the Azure and Azure Classic plugins.
This field is only used in the Azure and Azure Classic plugins. To create a user to use the Azure (ARM)
plugin check the documentation of the Azure python SDK:
`here <https://azure-sdk-for-python.readthedocs.io/en/latest/quickstart_authentication.html#using-ad-user-password>`_

OpenStack addicional fields
OpenStack additional fields
^^^^^^^^^^^^^^^^^^^^^^^^^^^

OpenStack has a set of additional fields to access a cloud site:
Expand Down
15 changes: 5 additions & 10 deletions test/unit/connectors/Azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ def test_30_updateVMInfo(self, credentials, compute_client, network_client):
azure_cloud = self.get_azure_cloud()

inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "rg0/im0", azure_cloud.cloud, radl, radl, azure_cloud)
vm = VirtualMachine(inf, "rg0/im0", azure_cloud.cloud, radl, radl, azure_cloud, 1)

instace_type = MagicMock()
instace_type.name = "instance_type1"
Expand Down Expand Up @@ -251,8 +250,7 @@ def test_40_stop(self, credentials, compute_client):
azure_cloud = self.get_azure_cloud()

inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "rg0/vm0", azure_cloud.cloud, "", "", azure_cloud)
vm = VirtualMachine(inf, "rg0/vm0", azure_cloud.cloud, "", "", azure_cloud, 1)

success, _ = azure_cloud.stop(vm, auth)

Expand All @@ -267,8 +265,7 @@ def test_50_start(self, credentials, compute_client):
azure_cloud = self.get_azure_cloud()

inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "rg0/vm0", azure_cloud.cloud, "", "", azure_cloud)
vm = VirtualMachine(inf, "rg0/vm0", azure_cloud.cloud, "", "", azure_cloud, 1)

success, _ = azure_cloud.start(vm, auth)

Expand Down Expand Up @@ -341,8 +338,7 @@ def test_55_alter(self, credentials, network_client, compute_client, storage_cli
nclient.public_ip_addresses.get.return_value = pub_ip_res

inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "rg0/vm0", azure_cloud.cloud, radl, radl, azure_cloud)
vm = VirtualMachine(inf, "rg0/vm0", azure_cloud.cloud, radl, radl, azure_cloud, 1)

success, _ = azure_cloud.alterVM(vm, new_radl, auth)

Expand All @@ -357,8 +353,7 @@ def test_60_finalize(self, credentials, resource_client):
azure_cloud = self.get_azure_cloud()

inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "rg0/vm0", azure_cloud.cloud, "", "", azure_cloud)
vm = VirtualMachine(inf, "rg0/vm0", azure_cloud.cloud, "", "", azure_cloud, 1)

success, _ = azure_cloud.finalize(vm, auth)

Expand Down
15 changes: 5 additions & 10 deletions test/unit/connectors/AzureClassic.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ def test_30_updateVMInfo(self, requests):
azure_cloud = self.get_azure_cloud()

inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", azure_cloud.cloud, radl, radl, azure_cloud)
vm = VirtualMachine(inf, "1", azure_cloud.cloud, radl, radl, azure_cloud, 1)

requests.side_effect = self.get_response

Expand All @@ -245,8 +244,7 @@ def test_40_stop(self, sleep, requests):
azure_cloud = self.get_azure_cloud()

inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", azure_cloud.cloud, "", "", azure_cloud)
vm = VirtualMachine(inf, "1", azure_cloud.cloud, "", "", azure_cloud, 1)

requests.side_effect = self.get_response

Expand All @@ -263,8 +261,7 @@ def test_50_start(self, sleep, requests):
azure_cloud = self.get_azure_cloud()

inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", azure_cloud.cloud, "", "", azure_cloud)
vm = VirtualMachine(inf, "1", azure_cloud.cloud, "", "", azure_cloud, 1)

requests.side_effect = self.get_response

Expand Down Expand Up @@ -303,8 +300,7 @@ def test_55_alter(self, sleep, requests):
azure_cloud = self.get_azure_cloud()

inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", azure_cloud.cloud, radl, radl, azure_cloud)
vm = VirtualMachine(inf, "1", azure_cloud.cloud, radl, radl, azure_cloud, 1)

requests.side_effect = self.get_response

Expand All @@ -321,8 +317,7 @@ def test_60_finalize(self, sleep, requests):
azure_cloud = self.get_azure_cloud()

inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", azure_cloud.cloud, "", "", azure_cloud)
vm = VirtualMachine(inf, "1", azure_cloud.cloud, "", "", azure_cloud, 1)

sleep.return_value = True
requests.side_effect = self.get_response
Expand Down
12 changes: 4 additions & 8 deletions test/unit/connectors/Docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ def test_30_updateVMInfo(self, requests):
docker_cloud = self.get_docker_cloud()

inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", docker_cloud.cloud, radl, radl, docker_cloud)
vm = VirtualMachine(inf, "1", docker_cloud.cloud, radl, radl, docker_cloud, 1)

requests.side_effect = self.get_response

Expand All @@ -249,8 +248,7 @@ def test_40_stop(self, requests):
docker_cloud = self.get_docker_cloud()

inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", docker_cloud.cloud, "", "", docker_cloud)
vm = VirtualMachine(inf, "1", docker_cloud.cloud, "", "", docker_cloud, 1)

requests.side_effect = self.get_response

Expand All @@ -265,8 +263,7 @@ def test_50_start(self, requests):
docker_cloud = self.get_docker_cloud()

inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", docker_cloud.cloud, "", "", docker_cloud)
vm = VirtualMachine(inf, "1", docker_cloud.cloud, "", "", docker_cloud, 1)

requests.side_effect = self.get_response

Expand All @@ -288,8 +285,7 @@ def test_60_finalize(self, requests):
docker_cloud = self.get_docker_cloud()

inf = MagicMock()
inf.get_next_vm_id.return_value = 1
vm = VirtualMachine(inf, "1", docker_cloud.cloud, radl, radl, docker_cloud)
vm = VirtualMachine(inf, "1", docker_cloud.cloud, radl, radl, docker_cloud, 1)

requests.side_effect = self.get_response

Expand Down
Loading

0 comments on commit d9aeec3

Please sign in to comment.