Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# All volumes must be in the same zone
vol_id = fs['ids'][0]
response['placement'] = self._get_volume_placement(
vol_id)
# No need to continue to iterate through
# filesystems, if we found one with a volume.
break
except Exception as exc:
response['error'] = ("Exception while finding placement for "
"cluster '{0}'. This can indicate malformed "
"instance data. Or that this method is "
"broken: {1}".format(cluster_name, exc))
bioblend.log.error(response['error'])
response['placement'] = None
else:
bioblend.log.debug("Insufficient info about cluster {0} to get placement."
.format(cluster_name))
return response
except EC2ResponseError as e:
err_msg = ("Problem getting security groups. This could indicate a "
"problem with your account credentials or permissions: "
"{0} (code {1}; status {2})"
.format(str(e), e.error_code, e.status))
bioblend.log.exception(err_msg)
progress['error'] = err_msg
return progress
for sg in sgs:
if sg.name == sg_name:
cmsg = sg
bioblend.log.debug("Security group '%s' already exists; will add authorizations next.", sg_name)
break
# If it does not exist, create security group
if cmsg is None:
bioblend.log.debug("Creating Security Group %s", sg_name)
try:
cmsg = self.ec2_conn.create_security_group(sg_name, 'A security '
'group for CloudMan',
vpc_id=vpc_id)
except EC2ResponseError as e:
err_msg = "Problem creating security group '{0}': {1} (code {2}; " \
"status {3})" \
.format(sg_name, str(e), e.error_code, e.status)
bioblend.log.exception(err_msg)
progress['error'] = err_msg
if cmsg:
progress['name'] = cmsg.name
progress['sg_id'] = cmsg.id
# Add appropriate authorization rules
# If these rules already exist, nothing will be changed in the SG
for port in ports:
filters = {'vpc-id': vpc_id}
# Check if this security group already exists
try:
sgs = self.ec2_conn.get_all_security_groups(filters=filters)
except EC2ResponseError as e:
err_msg = ("Problem getting security groups. This could indicate a "
"problem with your account credentials or permissions: "
"{0} (code {1}; status {2})"
.format(str(e), e.error_code, e.status))
bioblend.log.exception(err_msg)
progress['error'] = err_msg
return progress
for sg in sgs:
if sg.name == sg_name:
cmsg = sg
bioblend.log.debug("Security group '%s' already exists; will add authorizations next.", sg_name)
break
# If it does not exist, create security group
if cmsg is None:
bioblend.log.debug("Creating Security Group %s", sg_name)
try:
cmsg = self.ec2_conn.create_security_group(sg_name, 'A security '
'group for CloudMan',
vpc_id=vpc_id)
except EC2ResponseError as e:
err_msg = "Problem creating security group '{0}': {1} (code {2}; " \
"status {3})" \
.format(sg_name, str(e), e.error_code, e.status)
bioblend.log.exception(err_msg)
progress['error'] = err_msg
if cmsg:
progress['name'] = cmsg.name
def assign_floating_ip(self, ec2_conn, instance):
try:
bioblend.log.debug("Allocating a new floating IP address.")
address = ec2_conn.allocate_address()
except EC2ResponseError:
bioblend.log.exception("Exception allocating a new floating IP address")
bioblend.log.info("Associating floating IP %s to instance %s", address.public_ip, instance.id)
ec2_conn.associate_address(instance_id=instance.id,
public_ip=address.public_ip)
err_msg = "A problem adding security group authorizations: {0} " \
"(code {1}; status {2})" \
.format(str(e), e.error_code, e.status)
bioblend.log.exception(err_msg)
progress['error'] = err_msg
# Add ICMP (i.e., ping) rule required by HTCondor
try:
if not self.rule_exists(
cmsg.rules, from_port='-1', to_port='-1', ip_protocol='icmp'):
cmsg.authorize(
ip_protocol='icmp',
from_port=-1,
to_port=-1,
cidr_ip='0.0.0.0/0')
else:
bioblend.log.debug(
"ICMP rule already exists in {0} SG.".format(sg_name))
except EC2ResponseError as e:
err_msg = "A problem with security ICMP rule authorization: {0} " \
"(code {1}; status {2})" \
.format(str(e), e.error_code, e.status)
bioblend.log.exception(err_msg)
progress['err_msg'] = err_msg
# Add rule that allows communication between instances in the same
# SG
# A flag to indicate if group rule already exists
g_rule_exists = False
for rule in cmsg.rules:
for grant in rule.grants:
if grant.name == cmsg.name:
g_rule_exists = True
bioblend.log.debug(
"ICMP rule already exists in {0} SG.".format(sg_name))
except EC2ResponseError as e:
err_msg = "A problem with security ICMP rule authorization: {0} " \
"(code {1}; status {2})" \
.format(str(e), e.error_code, e.status)
bioblend.log.exception(err_msg)
progress['err_msg'] = err_msg
# Add rule that allows communication between instances in the same
# SG
# A flag to indicate if group rule already exists
g_rule_exists = False
for rule in cmsg.rules:
for grant in rule.grants:
if grant.name == cmsg.name:
g_rule_exists = True
bioblend.log.debug(
"Group rule already exists in the SG.")
if g_rule_exists:
break
if not g_rule_exists:
try:
cmsg.authorize(
src_group=cmsg,
ip_protocol='tcp',
from_port=0,
to_port=65535)
except EC2ResponseError as e:
err_msg = "A problem with security group group " \
"authorization: {0} (code {1}; status {2})" \
.format(str(e), e.error_code, e.status)
bioblend.log.exception(err_msg)
progress['err_msg'] = err_msg