Exemplo n.º 1
0
def test_getBoolean_defined_namespace(pcw_file):
    set_pcw_ini(
        pcw_file, """
    [feature]
    bool_property = False
    [feature.namespace.random_namespace]
    bool_property = True
    """)
    assert PCWConfig.getBoolean('feature/bool_property', 'random_namespace')
Exemplo n.º 2
0
def test_getBoolean_namespace_but_not_defined(pcw_file):
    set_pcw_ini(
        pcw_file, """
    [feature]
    bool_property = True
    [feature.namespace.random_namespace]
    providers = azure
    """)
    assert PCWConfig.getBoolean('feature/bool_property', 'random_namespace')
Exemplo n.º 3
0
Arquivo: EC2.py Projeto: grisu48/pcw
 def cleanup_all(self):
     cleanup_ec2_max_snapshot_age_days = PCWConfig.get_feature_property(
         'cleanup', 'ec2-max-snapshot-age-days', self._namespace)
     cleanup_ec2_max_volumes_age_days = PCWConfig.get_feature_property(
         'cleanup', 'ec2-max-volumes-age-days', self._namespace)
     self.cleanup_images()
     if cleanup_ec2_max_snapshot_age_days >= 0:
         self.cleanup_snapshots(cleanup_ec2_max_snapshot_age_days)
     if cleanup_ec2_max_volumes_age_days >= 0:
         self.cleanup_volumes(cleanup_ec2_max_volumes_age_days)
     if PCWConfig.getBoolean('cleanup/vpc_cleanup', self._namespace):
         self.cleanup_uploader_vpcs()
Exemplo n.º 4
0
Arquivo: vault.py Projeto: SUSE/pcw
 def __init__(self, vault_namespace):
     self.url = PCWConfig.get_feature_property('vault', 'url')
     self.user = PCWConfig.get_feature_property('vault', 'user')
     self.namespace = vault_namespace
     self.password = PCWConfig.get_feature_property('vault', 'password')
     self.certificate_dir = PCWConfig.get_feature_property('vault', 'cert_dir')
     if PCWConfig.getBoolean('vault/use-file-cache') and self._getAuthCacheFile().exists():
         logger.info('Loading cached credentials')
         self.auth_json = self.loadAuthCache()
     else:
         self.auth_json = None
     self.client_token = None
     self.client_token_expire = None
Exemplo n.º 5
0
Arquivo: vault.py Projeto: SUSE/pcw
 def getData(self, name=None):
     use_file_cache = PCWConfig.getBoolean('vault/use-file-cache')
     if self.auth_json is None and use_file_cache:
         self.auth_json = self.loadAuthCache()
     if self.isExpired():
         self.auth_json = self.getCredentials()
         expire = datetime.today() + timedelta(seconds=self.auth_json['lease_duration'])
         self.auth_json['auth_expire'] = expire.isoformat()
         if expire > self.client_token_expire:
             self.renewClientToken(self.auth_json['lease_duration'])
         if use_file_cache:
             self.saveAuthCache()
     if name is None:
         return self.auth_json['data']
     return self.auth_json['data'][name]
Exemplo n.º 6
0
Arquivo: EC2.py Projeto: grisu48/pcw
 def cleanup_uploader_vpcs(self):
     for region in self.all_regions:
         response = self.ec2_client(region).describe_vpcs(
             Filters=[{
                 'Name': 'isDefault',
                 'Values': ['false']
             }, {
                 'Name': 'tag:Name',
                 'Values': ['uploader-*']
             }])
         for response_vpc in response['Vpcs']:
             self.log_info(
                 '{} in {} looks like uploader leftover. (OwnerId={}).',
                 response_vpc['VpcId'], region, response_vpc['OwnerId'])
             if PCWConfig.getBoolean('cleanup/vpc-notify-only',
                                     self._namespace):
                 send_mail(
                     'VPC {} should be deleted, skipping due vpc-notify-only=True'
                     .format(response_vpc['VpcId']), '')
             else:
                 resource_vpc = self.ec2_resource(region).Vpc(
                     response_vpc['VpcId'])
                 can_be_deleted = True
                 for subnet in resource_vpc.subnets.all():
                     if len(list(subnet.instances.all())):
                         self.log_warn(
                             '{} has associated instance(s) so can not be deleted',
                             response_vpc['VpcId'])
                         can_be_deleted = False
                         break
                 if can_be_deleted:
                     self.delete_vpc(region, resource_vpc,
                                     response_vpc['VpcId'])
                 elif not self.dry_run:
                     body = 'Uploader leftover {} (OwnerId={}) in {} is locked'.format(
                         response_vpc['VpcId'], response_vpc['OwnerId'],
                         region)
                     send_mail('VPC deletion locked by running VMs', body)
Exemplo n.º 7
0
Arquivo: vault.py Projeto: grisu48/pcw
 def renew(self):
     if PCWConfig.getBoolean(
             'vault/use-file-cache') and self._getAuthCacheFile().exists():
         self._getAuthCacheFile().unlink()
     self.revoke()
     self.getData()
Exemplo n.º 8
0
 def __init__(self, namespace: str):
     self._namespace = namespace
     self.dry_run = PCWConfig.getBoolean('default/dry_run')
     self.logger = logging.getLogger(self.__module__)
Exemplo n.º 9
0
def test_getBoolean_defined(pcw_file):
    set_pcw_ini(pcw_file, """
    [feature]
    bool_property = True
    """)
    assert PCWConfig.getBoolean('feature/bool_property')
Exemplo n.º 10
0
def test_getBoolean_notdefined_namespace(pcw_file):
    assert not PCWConfig.getBoolean('feature/bool_property',
                                    'random_namespace')
Exemplo n.º 11
0
def test_getBoolean_notdefined(pcw_file):
    assert not PCWConfig.getBoolean('feature/bool_property')