def test_is_subscription(self): # subscription self.assertTrue(vcloud_plugin_common.is_subscription(vcloud_plugin_common.SUBSCRIPTION_SERVICE_TYPE)) # ondemand self.assertFalse(vcloud_plugin_common.is_subscription(vcloud_plugin_common.ONDEMAND_SERVICE_TYPE)) # None, by default used subscription service, so True self.assertTrue(vcloud_plugin_common.is_subscription(None))
def test_is_subscription(self): # subscription self.assertTrue( vcloud_plugin_common.is_subscription( vcloud_plugin_common.SUBSCRIPTION_SERVICE_TYPE)) # ondemand self.assertFalse( vcloud_plugin_common.is_subscription( vcloud_plugin_common.ONDEMAND_SERVICE_TYPE)) # None, by default used subscription service, so True self.assertTrue(vcloud_plugin_common.is_subscription(None))
def create(vca_client, **kwargs): """create vdc""" config = get_vcloud_config() # Subscription service does not support vdc create, # you must use predefined vdc only if is_subscription(config['service_type']): raise cfy_exc.NonRecoverableError( "Unable create VDC on subscription service.") if ctx.node.properties.get(USE_EXTERNAL_RESOURCE): # use external resource, does not create anything res_id = ctx.node.properties[RESOURCE_ID] ctx.instance.runtime_properties[VDC_NAME] = res_id vdc = vca_client.get_vdc(res_id) if not vdc: raise cfy_exc.NonRecoverableError( "Unable to find external VDC {0}." .format(res_id)) ctx.logger.info( "External resource {0} has been used".format(res_id)) else: # create new vdc vdc_name = ctx.node.properties.get('name') if not vdc_name: raise cfy_exc.NonRecoverableError("'vdc_name' not specified.") task = vca_client.create_vdc(vdc_name) if not task: raise cfy_exc.NonRecoverableError("Could not create VDC: {0}" .format(error_response(vca_client))) wait_for_task(vca_client, task)
def create(vca_client, **kwargs): """create vdc""" config = get_vcloud_config() # Subscription service does not support vdc create, # you must use predefined vdc only if is_subscription(config['service_type']): raise cfy_exc.NonRecoverableError( "Unable create VDC on subscription service.") if ctx.node.properties.get(USE_EXTERNAL_RESOURCE): # use external resource, does not create anything res_id = ctx.node.properties[RESOURCE_ID] ctx.instance.runtime_properties[VDC_NAME] = res_id vdc = vca_client.get_vdc(res_id) if not vdc: raise cfy_exc.NonRecoverableError( "Unable to find external VDC {0}.".format(res_id)) ctx.logger.info("External resource {0} has been used".format(res_id)) else: # create new vdc vdc_name = ctx.node.properties.get('name') if not vdc_name: raise cfy_exc.NonRecoverableError("'vdc_name' not specified.") task = vca_client.create_vdc(vdc_name) if not task: raise cfy_exc.NonRecoverableError( "Could not create VDC: {0}".format(error_response(vca_client))) wait_for_task(vca_client, task)
def get_public_ip(vca_client, gateway, service_type, ctx): if is_subscription(service_type): public_ip = getFreeIP(gateway) ctx.logger.info("Assign external IP {0}".format(public_ip)) else: public_ip = get_ondemand_public_ip(vca_client, gateway, ctx) return public_ip
def get_public_ip(vca_client, gateway, service_type, ctx): """ return new public ip """ if is_subscription(service_type): public_ip = getFreeIP(gateway) ctx.logger.info("Assign external IP {0}".format(public_ip)) else: public_ip = get_ondemand_public_ip(vca_client, gateway, ctx) return public_ip
def creation_validation(vca_client, **kwargs): floatingip = get_mandatory(ctx.node.properties, 'floatingip') edge_gateway = get_mandatory(floatingip, 'edge_gateway') gateway = get_gateway(vca_client, edge_gateway) service_type = get_vcloud_config().get('service_type') public_ip = floatingip.get(PUBLIC_IP) if public_ip: check_ip(public_ip) CheckAssignedExternalIp(public_ip, gateway) else: if is_subscription(service_type): getFreeIP(gateway)
def creation_validation(vca_client, **kwargs): nat = get_mandatory(ctx.node.properties, 'nat') gateway = get_gateway(vca_client, get_mandatory(nat, 'edge_gateway')) service_type = get_vcloud_config().get('service_type') public_ip = nat.get(PUBLIC_IP) if public_ip: check_ip(public_ip) else: if is_subscription(service_type): getFreeIP(gateway) for rule in get_mandatory(ctx.node.properties, 'rules'): if rule['type'] == "DNAT": check_protocol(rule.get('protocol', "any")) original_port = rule.get('original_port') if original_port and not isinstance(original_port, int): raise cfy_exc.NonRecoverableError( "Parameter 'original_port' must be integer") translated_port = rule.get('translated_port') if translated_port and not isinstance(translated_port, int): raise cfy_exc.NonRecoverableError( "Parameter 'translated_port' must be integer")
def creation_validation(vca_client, **kwargs): """ validate node context, fields from floatingip dict: * edge_gateway - mandatory, * public_ip - prefered ip for node, can be empty fields from vcloud_config: * service_type - ondemand, subscription also check availability of public ip if set or exist some free ip in subscription case """ floatingip = get_mandatory(ctx.node.properties, 'floatingip') edge_gateway = get_mandatory(floatingip, 'edge_gateway') gateway = get_gateway(vca_client, edge_gateway) service_type = get_vcloud_config().get('service_type') public_ip = floatingip.get(PUBLIC_IP) if public_ip: check_ip(public_ip) CheckAssignedExternalIp(public_ip, gateway) else: if is_subscription(service_type): getFreeIP(gateway)
def creation_validation(vca_client, **kwargs): """ validate nat rules in node properties """ nat = get_mandatory(ctx.node.properties, 'nat') gateway = get_gateway(vca_client, get_mandatory(nat, 'edge_gateway')) service_type = get_vcloud_config().get('service_type') public_ip = nat.get(PUBLIC_IP) if public_ip: check_ip(public_ip) else: if is_subscription(service_type): getFreeIP(gateway) for rule in get_mandatory(ctx.node.properties, 'rules'): if rule['type'] == "DNAT": utils.check_protocol(rule.get('protocol')) original_port = rule.get('original_port') if original_port and not isinstance(original_port, int): raise cfy_exc.NonRecoverableError( "Parameter 'original_port' must be integer") translated_port = rule.get('translated_port') if translated_port and not isinstance(translated_port, int): raise cfy_exc.NonRecoverableError( "Parameter 'translated_port' must be integer")