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

Commit

Permalink
Merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Jun 19, 2018
2 parents 8763c79 + 54acb05 commit 5093c12
Show file tree
Hide file tree
Showing 20 changed files with 200 additions and 105 deletions.
63 changes: 43 additions & 20 deletions IM/InfrastructureManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def _compute_score(system_score, requested_radl):
return concrete_system, score

@staticmethod
def systems_with_vmrc(radl, auth):
def systems_with_vmrc(sel_inf, radl, auth):
"""
Concrete systems using VMRC
NOTE: consider not-fake deploys (vm_number > 0)
Expand Down Expand Up @@ -382,6 +382,7 @@ def systems_with_vmrc(radl, auth):
vmrc_res = [s0 for vmrc in vmrc_list for s0 in vmrc.search_vm(s)]
# Check that now the image URL is in the RADL
if not s.getValue("disk.0.image.url") and not vmrc_res:
sel_inf.add_cont_msg("No VMI obtained from VMRC to system: " + system_id)
raise Exception("No VMI obtained from VMRC to system: " + system_id)

n = [s_without_apps.clone().applyFeatures(s0, conflict="other", missing="other")
Expand Down Expand Up @@ -435,6 +436,8 @@ def sort_by_score(sel_inf, concrete_systems, cloud_list, deploy_groups, auth):
if sorted_scored_clouds and sorted_scored_clouds[0]:
deploys_group_cloud[id(deploy_group)] = sorted_scored_clouds[0][0]
else:
sel_inf.configured = False
sel_inf.add_cont_msg("No cloud provider available")
raise Exception("No cloud provider available")

return deploys_group_cloud
Expand All @@ -457,24 +460,31 @@ def AddResource(inf_id, radl_data, auth, context=True):

InfrastructureManager.logger.info("Adding resources to Inf ID: " + str(inf_id))

if isinstance(radl_data, RADL):
radl = radl_data
else:
radl = radl_parse.parse_radl(radl_data)
sel_inf = InfrastructureManager.get_infrastructure(inf_id, auth)

InfrastructureManager.logger.debug("Inf ID: " + str(inf_id) + ": \n" + str(radl))
radl.check()
try:
if isinstance(radl_data, RADL):
radl = radl_data
else:
radl = radl_parse.parse_radl(radl_data)

sel_inf = InfrastructureManager.get_infrastructure(inf_id, auth)
InfrastructureManager.logger.debug("Inf ID: " + str(inf_id) + ": \n" + str(radl))
radl.check()

# Update infrastructure RADL with this new RADL
sel_inf.complete_radl(radl)
# Update infrastructure RADL with this new RADL
sel_inf.complete_radl(radl)

# If any deploy is defined, only update definitions.
if not radl.deploys:
sel_inf.update_radl(radl, [])
InfrastructureManager.logger.warn("Inf ID: " + sel_inf.id + ": without any deploy. Exiting.")
return []
# If any deploy is defined, only update definitions.
if not radl.deploys:
sel_inf.update_radl(radl, [])
InfrastructureManager.logger.warn("Inf ID: " + sel_inf.id + ": without any deploy. Exiting.")
sel_inf.add_cont_msg("Infrastructure without any deploy. Exiting.")
return []
except Exception as ex:
sel_inf.configured = False
sel_inf.add_cont_msg("Error parsing RADL: %s" % str(ex))
InfrastructureManager.logger.exception("Inf ID: " + sel_inf.id + " error parsing RADL")
raise ex

for system in radl.systems:
# Add apps requirements to the RADL
Expand All @@ -495,7 +505,7 @@ def AddResource(inf_id, radl_data, auth, context=True):
break

# Concrete systems using VMRC
systems_with_vmrc = InfrastructureManager.systems_with_vmrc(radl, auth)
systems_with_vmrc = InfrastructureManager.systems_with_vmrc(sel_inf, radl, auth)

# Concrete systems with cloud providers and select systems with the greatest score
# in every cloud
Expand Down Expand Up @@ -526,7 +536,8 @@ def AddResource(inf_id, radl_data, auth, context=True):
for deploy_group in deploy_groups:
if not deploy_group:
InfrastructureManager.logger.warning("Inf ID: %s: No VMs to deploy!" % sel_inf.id)
return
sel_inf.add_cont_msg("No VMs to deploy. Exiting.")
return []

cloud_id = deploys_group_cloud[id(deploy_group)]
cloud = cloud_list[cloud_id]
Expand Down Expand Up @@ -578,6 +589,7 @@ def AddResource(inf_id, radl_data, auth, context=True):
sel_inf.update_radl(radl, [(d, deployed_vm[d], concrete_systems[d.cloud_id][d.id][0]) for d in deployed_vm])
if all_failed:
InfrastructureManager.logger.error("VMs failed when adding to Inf ID: %s" % sel_inf.id)
sel_inf.add_cont_msg("All VMs failed. No contextualize.")
else:
InfrastructureManager.logger.info("VMs %s successfully added to Inf ID: %s" % (new_vms, sel_inf.id))

Expand Down Expand Up @@ -896,7 +908,10 @@ def GetInfrastructureState(inf_id, auth):
state = VirtualMachine.UNCONFIGURED

if state is None:
state = VirtualMachine.UNKNOWN
if sel_inf.configured is False:
state = VirtualMachine.FAILED
else:
state = VirtualMachine.UNKNOWN

InfrastructureManager.logger.info("Inf ID: " + str(inf_id) + " is in state: " + state)
return {'state': state, 'vm_states': vm_states}
Expand Down Expand Up @@ -1248,7 +1263,7 @@ def check_auth_data(auth):
return auth

@staticmethod
def CreateInfrastructure(radl, auth, async_call=False):
def CreateInfrastructure(radl_data, auth, async_call=False):
"""
Create a new infrastructure.
Expand All @@ -1257,7 +1272,7 @@ def CreateInfrastructure(radl, auth, async_call=False):
Args:
- radl(RADL): RADL description.
- radl_data(RADL): RADL description.
- auth(Authentication): parsed authentication tokens.
- async_call(bool): Create the inf in an async way.
Expand All @@ -1267,6 +1282,14 @@ def CreateInfrastructure(radl, auth, async_call=False):
# First check the auth data
auth = InfrastructureManager.check_auth_data(auth)

# Then parse the RADL
if isinstance(radl_data, RADL):
radl = radl_data
else:
radl = radl_parse.parse_radl(radl_data)

radl.check()

# Create a new infrastructure
inf = IM.InfrastructureInfo.InfrastructureInfo()
inf.auth = Authentication(auth.getAuthInfo("InfrastructureManager"))
Expand Down
58 changes: 34 additions & 24 deletions IM/VirtualMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,43 @@ def update_status(self, auth, force=False):

return updated

@staticmethod
def add_public_net(radl):
"""
Add a public net to the radl specified
"""
now = str(int(time.time() * 100))

public_nets = []
for net in radl.networks:
if net.isPublic():
public_nets.append(net)

if public_nets:
public_net = None
for net in public_nets:
num_net = radl.systems[0].getNumNetworkWithConnection(net.id)
if num_net is not None:
public_net = net
break

if not public_net:
# There are a public net but it has not been used in this
# VM
public_net = public_nets[0]
num_net = radl.systems[0].getNumNetworkIfaces()
else:
# There no public net, create one
public_net = network.createNetwork("public." + now, True)
radl.networks.append(public_net)
num_net = radl.systems[0].getNumNetworkIfaces()

return public_net, num_net

def setIps(self, public_ips, private_ips, remove_old=False):
"""
Set the specified IPs in the VM RADL info
"""
now = str(int(time.time() * 100))
vm_system = self.info.systems[0]

# First remove old ip values
Expand All @@ -553,29 +585,7 @@ def setIps(self, public_ips, private_ips, remove_old=False):
cont += 1

if public_ips and not set(public_ips).issubset(set(private_ips)):
public_nets = []
for net in self.info.networks:
if net.isPublic():
public_nets.append(net)

if public_nets:
public_net = None
for net in public_nets:
num_net = self.getNumNetworkWithConnection(net.id)
if num_net is not None:
public_net = net
break

if not public_net:
# There are a public net but it has not been used in this
# VM
public_net = public_nets[0]
num_net = self.getNumNetworkIfaces()
else:
# There no public net, create one
public_net = network.createNetwork("public." + now, True)
self.info.networks.append(public_net)
num_net = self.getNumNetworkIfaces()
public_net, num_net = self.add_public_net(self.info)

real_public_ips = [public_ip for public_ip in public_ips if public_ip not in private_ips]
if real_public_ips:
Expand Down
2 changes: 1 addition & 1 deletion IM/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
'InfrastructureInfo', 'InfrastructureManager', 'recipe', 'request', 'REST', 'retry',
'ServiceRequests', 'SSH', 'SSHRetry', 'timedcall', 'UnixHTTPAdapter', 'uriparse',
'VirtualMachine', 'VMRC', 'xmlobject']
__version__ = '1.7.3'
__version__ = '1.7.4'
__author__ = 'Miguel Caballer'
1 change: 1 addition & 0 deletions IM/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class Config:
OIDC_SCOPES = []
VM_NUM_USE_CTXT_DIST = 30
DELAY_BETWEEN_VM_RETRIES = 5
VERIFI_SSL = False


config = ConfigParser()
Expand Down
2 changes: 1 addition & 1 deletion IM/connectors/AzureClassic.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def create_request(self, method, url, auth_data, headers=None, body=None):
subscription_id = self.get_subscription_id(auth_data)
url = "https://%s:%d/%s%s" % (self.AZURE_SERVER, self.AZURE_PORT, subscription_id, url)
cert = self.get_user_cert_data(auth)
resp = requests.request(method, url, verify=False, cert=cert, headers=headers, data=body)
resp = requests.request(method, url, verify=self.verify_ssl, cert=cert, headers=headers, data=body)

return resp

Expand Down
11 changes: 11 additions & 0 deletions IM/connectors/CloudConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shutil
import tempfile
import time
from IM.config import Config


class CloudConnector:
Expand All @@ -22,6 +23,16 @@ def __init__(self, cloud_info, inf):
"""Logger object."""
self.error_messages = ""
"""String with error messages to be shown to the user."""
self.verify_ssl = Config.VERIFI_SSL
"""Verify SSL connections """
if not self.verify_ssl:
try:
# To avoid annoying InsecureRequestWarning messages in some Connectors
import requests.packages
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
except:
pass

def concreteSystem(self, radl_system, auth_data):
"""
Expand Down
4 changes: 2 additions & 2 deletions IM/connectors/Docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def create_request(self, method, url, auth_data, headers=None, body=None):
url)
session = requests.Session()
session.mount('http+unix://', UnixHTTPAdapter.UnixHTTPAdapter())
resp = session.request(method, url, verify=False, headers=headers, data=body)
resp = session.request(method, url, verify=self.verify_ssl, headers=headers, data=body)
else:
url = "%s://%s:%d%s%s" % (self.cloud.protocol, self.cloud.server, self.cloud.port, self.cloud.path, url)
if 'public_key' in auth and 'private_key' in auth:
Expand All @@ -71,7 +71,7 @@ def create_request(self, method, url, auth_data, headers=None, body=None):
cert = None

try:
resp = requests.request(method, url, verify=False, cert=cert, headers=headers, data=body)
resp = requests.request(method, url, verify=self.verify_ssl, cert=cert, headers=headers, data=body)
finally:
if cert:
try:
Expand Down
2 changes: 1 addition & 1 deletion IM/connectors/FogBow.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def create_request(self, method, url, auth_data, headers=None, body=None):
protocol = self.cloud.protocol

url = "%s://%s:%d%s%s" % (protocol, self.cloud.server, self.cloud.port, self.cloud.path, url)
resp = requests.request(method, url, verify=False, headers=headers, data=body)
resp = requests.request(method, url, verify=self.verify_ssl, headers=headers, data=body)

return resp

Expand Down
2 changes: 1 addition & 1 deletion IM/connectors/Kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def create_request(self, method, url, auth_data, headers=None, body=None):
headers.update(auth_header)

url = "%s://%s:%d%s%s" % (self.cloud.protocol, self.cloud.server, self.cloud.port, self.cloud.path, url)
resp = requests.request(method, url, verify=False, headers=headers, data=body)
resp = requests.request(method, url, verify=self.verify_ssl, headers=headers, data=body)

return resp

Expand Down
Loading

0 comments on commit 5093c12

Please sign in to comment.