Skip to content

Commit

Permalink
Merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Feb 10, 2016
2 parents f2473cf + 17c5226 commit c8384bc
Show file tree
Hide file tree
Showing 18 changed files with 263 additions and 217 deletions.
13 changes: 10 additions & 3 deletions IM/CloudInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def __init__(self):
"""Server of the cloud provider"""
self.port = -1
"""Port of the cloud provider"""
self.protocol = ""
"""Protocol to connect to the cloud provider"""

def getCloudConnector(self):
"""
Expand All @@ -51,6 +53,8 @@ def __str__(self):
res += "type = " + self.type + ", "
if self.server:
res += "server = " + self.server + ", "
if self.protocol:
res += "protocol = " + self.protocol + ", "
if self.port != -1:
res += "port = " + str(self.port) + ", "

Expand All @@ -74,10 +78,13 @@ def get_cloud_list(auth_data):
cloud_item.id = cloud_item.type + str(i)
try:
if 'host' in auth and auth['host']:
pos = auth['host'].find('://')
pos = auth['host'].find(':', pos+1)
pos_pr = auth['host'].find('://')
if pos_pr != -1:
cloud_item.protocol = auth['host'][:pos_pr]
pos_pr += 2
pos = auth['host'].find(':', pos_pr+1)
if pos != -1:
cloud_item.server = auth['host'][:pos]
cloud_item.server = auth['host'][pos_pr+1:pos]
cloud_item.port = int(auth['host'][pos+1:])
else:
cloud_item.server = auth['host']
Expand Down
2 changes: 1 addition & 1 deletion IM/ConfManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ def wait_vm_running(self, vm, timeout, relaunch=False):
Returns: True if all the VMs are running or false otherwise
"""
timeout_retries = 0
retries = 0
retries = 1
delay = 10
wait = 0
while wait < timeout:
Expand Down
6 changes: 3 additions & 3 deletions IM/InfrastructureManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def _launch_group(sel_inf, deploy_group, deploys_group_cloud_list, cloud_list, c
concrete_system = concrete_systems[cloud_id][deploy.id][0]
if not concrete_system:
InfrastructureManager.logger.error("Error, no concrete system to deploy: " + deploy.id + " in cloud: " + cloud_id + ". Check if a correct image is being used")
exceptions.append("Error, no concrete system to deploy: " + deploy.id + ". Check if a correct image is being used")
exceptions.append("Error, no concrete system to deploy: " + deploy.id + ". Check if a correct image is being used.")
break

(username, _, _, _) = concrete_system.getCredentialValues()
Expand All @@ -190,7 +190,7 @@ def _launch_group(sel_inf, deploy_group, deploys_group_cloud_list, cloud_list, c
launched_vms = cloud.cloud.getCloudConnector().launch(sel_inf, launch_radl, requested_radl, remain_vm, auth)
except Exception, e:
InfrastructureManager.logger.exception("Error launching some of the VMs: %s" % e)
exceptions.append(e)
exceptions.append("Error launching the VMs of type %s to cloud ID %s of type %s. Cloud Provider Error: %s" % (concrete_system.name, cloud.cloud.id, cloud.cloud.type, e))
launched_vms = []
for success, launched_vm in launched_vms:
if success:
Expand All @@ -200,7 +200,7 @@ def _launch_group(sel_inf, deploy_group, deploys_group_cloud_list, cloud_list, c
remain_vm -= 1
else:
InfrastructureManager.logger.warn("Error launching some of the VMs: " + str(launched_vm))
exceptions.append(str(launched_vm))
exceptions.append("Error launching the VMs of type %s to cloud ID %s of type %s. %s" % (concrete_system.name, cloud.cloud.id, cloud.cloud.type, str(launched_vm)))
if not isinstance(launched_vm, str):
cloud.finalize(launched_vm, auth)
fail_cont += 1
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ recursive-include contextualization *
include IM/tosca/tosca-types/custom_types.yaml
include scripts/im
include etc/im.cfg
include etc/logging.conf
include LICENSE
include INSTALL
include NOTICE
Expand Down
3 changes: 3 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,6 @@ IM 1.4.2
IM 1.4.3
* Add IM_NODE_PUBLIC_IP and IM_NODE_PRIVATE_IP ansible variables
* Bugfixes in REST API
* Modify Docker connector using CpuShares as defined in swarm
* Enable to use a /etc/im/logging.conf file to config logging properties
* Bugfixes to OpenStack connector. Set default values to new versions.
26 changes: 12 additions & 14 deletions connectors/Docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,18 @@ def get_http_connection(self, auth_data):
"""

self.cert_file or os.path.isfile(self.cert_file)

url = uriparse(self.cloud.server)
auths = auth_data.getAuthInfo(DockerCloudConnector.type, url[1])

auths = auth_data.getAuthInfo(DockerCloudConnector.type, self.cloud.server)
if not auths:
self.logger.error("No correct auth data has been specified to Docker.")
return None
else:
auth = auths[0]

if url[0] == 'unix':
socket_path = "/" + url[1] + url[2]
if self.cloud.protocol == 'unix':
socket_path = "/" + self.cloud.server
conn = UnixHTTPConnection.UnixHTTPConnection(socket_path)
elif url[0] == 'https':
elif self.cloud.protocol == 'https':
if 'cert' in auth and 'key' in auth:
if os.path.isfile(self.cert_file) and os.path.isfile(self.key_file):
cert_file = self.cert_file
Expand All @@ -77,12 +76,12 @@ def get_http_connection(self, auth_data):
cert_file, key_file = self.get_user_cert_data(auth)
self.cert_file = cert_file
self.key_file = key_file
conn = httplib.HTTPSConnection(url[1], self.cloud.port, cert_file = cert_file, key_file = key_file)
conn = httplib.HTTPSConnection(self.cloud.server, self.cloud.port, cert_file = cert_file, key_file = key_file)
else:
conn = httplib.HTTPSConnection(url[1], self.cloud.port)
elif url[0] == 'http':
conn = httplib.HTTPSConnection(self.cloud.server, self.cloud.port)
elif self.cloud.protocol == 'http':
self.logger.warn("Using a unsecure connection to docker API!")
conn = httplib.HTTPConnection(url[1], self.cloud.port)
conn = httplib.HTTPConnection(self.cloud.server, self.cloud.port)

return conn

Expand Down Expand Up @@ -147,12 +146,11 @@ def setIPs(self, vm, cont_info):
- cont_info(dict): JSON information about the container
"""

url = uriparse(self.cloud.server)
if url[0] == 'unix':
if self.cloud.protocol == 'unix':
# TODO: This will not get the correct IP if the hostname of the machine is not correctly set
public_ips = [socket.gethostbyname(socket.getfqdn())]
else:
public_ips = [socket.gethostbyname(url[1])]
public_ips = [socket.gethostbyname(self.cloud.server)]
private_ips = []
if str(cont_info["NetworkSettings"]["IPAddress"]):
private_ips.append(str(cont_info["NetworkSettings"]["IPAddress"]))
Expand Down Expand Up @@ -181,7 +179,7 @@ def _generate_create_request_data(self, outports, system, vm, ssh_port):
cont_data['Volumes'] = volumes

HostConfig = {}
HostConfig['CpusetCpus'] = "0-%d" % cpu
HostConfig['CpuShares'] = "%d" % cpu
HostConfig['Memory'] = memory
HostConfig['PortBindings'] = self._generate_port_bindings(outports, ssh_port)
HostConfig['Binds'] = self._generate_volumes_binds(system)
Expand Down
31 changes: 19 additions & 12 deletions connectors/FogBow.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,19 @@ class FogBowCloudConnector(CloudConnector):
}
"""Dictionary with a map with the FogBow Request states to the IM states."""

def __init__(self, cloud_info):
# check if the user has specified the http protocol in the host and remove it
pos = cloud_info.server.find('://')
if pos != -1:
cloud_info.server = cloud_info.server[pos+3:]
CloudConnector.__init__(self, cloud_info)
def get_http_connection(self):
"""
Get the HTTPConnection object to contact the FogBow API
Returns(HTTPConnection or HTTPSConnection): HTTPConnection connection object
"""

if self.cloud.protocol == 'https':
conn = httplib.HTTPSConnection(self.cloud.server, self.cloud.port)
else:
conn = httplib.HTTPConnection(self.cloud.server, self.cloud.port)

return conn

def get_auth_headers(self, auth_data):
"""
Expand Down Expand Up @@ -155,7 +162,7 @@ def updateVMInfo(self, vm, auth_data):

try:
# First get the request info
conn = httplib.HTTPConnection(self.cloud.server, self.cloud.port)
conn = self.get_http_connection()
conn.request('GET', "/fogbow_request/" + vm.id, headers = headers)
resp = conn.getresponse()

Expand All @@ -178,7 +185,7 @@ def updateVMInfo(self, vm, auth_data):
return (True, vm)
else:
# Now get the instance info
conn = httplib.HTTPConnection(self.cloud.server, self.cloud.port)
conn = self.get_http_connection()
conn.request('GET', "/compute/" + instance_id, headers = headers)
resp = conn.getresponse()

Expand Down Expand Up @@ -227,7 +234,7 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data):

res = []
i = 0
conn = httplib.HTTPConnection(self.cloud.server, self.cloud.port)
conn = self.get_http_connection()

url = uriparse(system.getValue("disk.0.image.url"))
if url[1].startswith('http'):
Expand Down Expand Up @@ -317,7 +324,7 @@ def finalize(self, vm, auth_data):

try:
# First get the request info
conn = httplib.HTTPConnection(self.cloud.server, self.cloud.port)
conn = self.get_http_connection()
conn.request('GET', "/fogbow_request/" + vm.id, headers = headers)
resp = conn.getresponse()

Expand All @@ -333,15 +340,15 @@ def finalize(self, vm, auth_data):
instance_id = None

if instance_id:
conn = httplib.HTTPConnection(self.cloud.server, self.cloud.port)
conn = self.get_http_connection()
conn.request('DELETE', "/compute/" + instance_id, headers = headers)
resp = conn.getresponse()

output = str(resp.read())
if resp.status != 404 and resp.status != 200:
return (False, "Error removing the VM: " + resp.reason + "\n" + output)

conn = httplib.HTTPConnection(self.cloud.server, self.cloud.port)
conn = self.get_http_connection()
conn.request('DELETE', "/fogbow_request/" + vm.id, headers = headers)
resp = conn.getresponse()

Expand Down
10 changes: 4 additions & 6 deletions connectors/Kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,11 @@ def get_http_connection(self):
Returns(HTTPConnection or HTTPSConnection): HTTPConnection connection object
"""

url = uriparse(self.cloud.server)

if url[0] == 'https':
conn = httplib.HTTPSConnection(url[1], self.cloud.port)
elif url[0] == 'http':
if self.cloud.protocol == 'https':
conn = httplib.HTTPSConnection(self.cloud.server, self.cloud.port)
elif self.cloud.protocol == 'http':
self.logger.warn("Using a unsecure connection to Kubernetes API!")
conn = httplib.HTTPConnection(url[1], self.cloud.port)
conn = httplib.HTTPConnection(self.cloud.server, self.cloud.port)

return conn

Expand Down
10 changes: 4 additions & 6 deletions connectors/OCCI.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,10 @@ def get_http_connection(self, auth_data):
else:
auth = auths[0]

url = uriparse(self.cloud.server)

if url[0] == 'https':
conn = self.get_https_connection(auth, url[1], self.cloud.port)
if self.cloud.protocol == 'https':
conn = self.get_https_connection(auth, self.cloud.server, self.cloud.port)
else:
conn = httplib.HTTPConnection(url[1], self.cloud.port)
conn = httplib.HTTPConnection(self.cloud.server, self.cloud.port)

return conn

Expand Down Expand Up @@ -134,7 +132,7 @@ def concreteSystem(self, radl_system, auth_data):
for str_url in image_urls:
url = uriparse(str_url)
protocol = url[0]
if protocol in ['https', 'http'] and url[2] and (url[0] + "://" + url[1]) == (self.cloud.server + ":" + str(self.cloud.port)):
if protocol in ['https', 'http'] and url[2] and (url[0] + "://" + url[1]) == (self.cloud.protocol + "://" + self.cloud.server + ":" + str(self.cloud.port)):
res_system = radl_system.clone()

res_system.getFeature("cpu.count").operator = "="
Expand Down
4 changes: 0 additions & 4 deletions connectors/OpenNebula.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ class OpenNebulaCloudConnector(CloudConnector):
"""str with the name of the provider."""

def __init__(self, cloud_info):
# check if the user has specified the http protocol in the host and remove it
pos = cloud_info.server.find('://')
if pos != -1:
cloud_info.server = cloud_info.server[pos+3:]
CloudConnector.__init__(self, cloud_info)
self.server_url = "http://%s:%d/RPC2" % (self.cloud.server, self.cloud.port)

Expand Down
Loading

0 comments on commit c8384bc

Please sign in to comment.