Esempio n. 1
0
    def __init__(self, **kwargs):
        """
        Constructor - all parameters are optional
        :param name: The keypair name.
        :param public_filepath: The path to/from the filesystem where the
                                public key file is or will be stored
        :param private_filepath: The path where the generated private key file
                                 will be stored
        :param key_size: The number of bytes for the key size when it needs to
                         be generated (Must be >=512 default 1024)
        :param delete_on_clean: when True, the key files will be deleted when
                                OpenStackKeypair#clean() is called
        :return:
        """

        self.name = kwargs.get('name')
        self.public_filepath = kwargs.get('public_filepath')
        self.private_filepath = kwargs.get('private_filepath')
        self.key_size = int(kwargs.get('key_size', 1024))

        if kwargs.get('delete_on_clean') is not None:
            if isinstance(kwargs.get('delete_on_clean'), bool):
                self.delete_on_clean = kwargs.get('delete_on_clean')
            else:
                self.delete_on_clean = str2bool(kwargs.get('delete_on_clean'))
        else:
            self.delete_on_clean = None

        if not self.name:
            raise KeypairConfigError('Name is a required attribute')

        if self.key_size < 512:
            raise KeypairConfigError('key_size must be >=512')
Esempio n. 2
0
    def __init__(self, **kwargs):
        """
        Constructor
        :param name: the volume's name (required)
        :param project_name: the name of the project to associate (optional)
            note: due to a bug in the Cinder API, this functionality will not
            work. see https://bugs.launchpad.net/cinder/+bug/1641982
        :param description: the volume's name (optional)
        :param size: the volume's size in GB (default 1)
        :param image_name: when a glance image is used for the image source
                           (optional)
        :param type_name: the associated volume's type name (optional)
        :param availability_zone: the name of the compute server on which to
                                  deploy the volume (optional)
        :param multi_attach: when true, volume can be attached to more than one
                             server (default False)
        """

        self.name = kwargs.get('name')
        self.project_name = kwargs.get('project_name')
        self.description = kwargs.get('description')
        self.size = int(kwargs.get('size', 1))
        self.image_name = kwargs.get('image_name')
        self.type_name = kwargs.get('type_name')
        self.availability_zone = kwargs.get('availability_zone')

        if kwargs.get('multi_attach'):
            self.multi_attach = str2bool(str(kwargs.get('multi_attach')))
        else:
            self.multi_attach = False

        if not self.name:
            raise VolumeConfigError("The attribute name is required")
 def args2body(self, parsed_args):
     body = super(UpdateSecurityGroup, self).args2body(parsed_args)
     neutron_client = self.get_client()
     parsed_args.id = neutronV20.find_resourceid_by_name_or_id(
         neutron_client, self.resource, parsed_args.id)
     if hasattr(parsed_args, 'stateful') and parsed_args.stateful:
         sec_group = body['security_group']
         sec_group['stateful'] = utils.str2bool(parsed_args.stateful)
     return body
Esempio n. 4
0
    def __init__(self, **kwargs):
        """
        Constructor
        :param name: the volume's name (required)
        :param description: the volume's name (optional)
        :param encryption: VolumeTypeEncryptionConfig (optional)
        :param qos_spec_name: name of the QoS Spec to associate (optional)
        :param public: volume visibility where True denotes global
                       (default - False)

        TODO - Implement project_access parameter that will associate this
        VolumeType to a list of project names
        """

        self.name = kwargs.get('name')
        self.description = kwargs.get('description')
        self.qos_spec_name = kwargs.get('qos_spec_name')

        if 'encryption' in kwargs:
            if isinstance(kwargs['encryption'], dict):
                self.encryption = VolumeTypeEncryptionConfig(
                    **kwargs['encryption'])
            elif isinstance(kwargs['encryption'], VolumeTypeEncryptionConfig):
                self.encryption = kwargs['encryption']
        else:
            self.encryption = None

        if 'public' in kwargs:
            if isinstance(kwargs['public'], str):
                self.public = str2bool(kwargs['public'])
            else:
                self.public = kwargs['public']
        else:
            self.public = False

        if not self.name:
            raise VolumeTypeConfigError("The attribute name is required")
Esempio n. 5
0
 def test_string_to_bool_None(self):
     self.assertIsNone(utils.str2bool(None))
Esempio n. 6
0
 def test_string_to_bool_false(self):
     self.assertFalse(utils.str2bool('false'))
Esempio n. 7
0
 def test_string_to_bool_true(self):
     self.assertTrue(utils.str2bool('true'))
Esempio n. 8
0
    def __init__(self, **kwargs):
        """
        Constructor
        :param name: the cluster template's name (required)
        :param image: name or ID of the base image in Glance used to boot the
                      cluster's servers. The image must have the attribute
                      'os-distro' defined as appropriate for the cluster
                      driver (required)
        :param keypair: name or ID of the keypair to gain cluster machine
                        access (required)
        :param network_driver: The name of a network driver for providing the
                               networks for the containers. Note that this is
                               different and separate from the Neutron network
                               for the bay/cluster. The operation and
                               networking model are specific to the particular
                               driver (optional)
        :param external_net: name or IDof the external Neutron network to
                             provide connectivity to the cluster (required)
        :param floating_ip_enabled: Whether enable or not using the floating IP
                                    of cloud provider. Some cloud providers
                                    used floating IP, some used public IP,
                                    thus Magnum provide this option for
                                    specifying the choice of using floating IP
                                    (default - True)
        :param docker_volume_size: The size in GB for the local storage on each
                                   server for the Docker daemon to cache the
                                   images and host the containers. Cinder
                                   volumes provide the storage. The default is
                                   25 GB. For the devicemapper storage driver,
                                   the minimum value is 3GB. For the overlay
                                   storage driver, the minimum value is 1GB.
                                   (default - 3)
        :param server_type: ServerType enumeration (default - vm)
        :param flavor: name or ID of the nova flavor for booting the node
                       servers (default - m1.small)
        :param master_flavor: name or ID of the nova flavor of the master node
                              for this cluster (optional)
        :param coe: ContainerOrchestrationEngine enum instance
                    (default - kubernetes)
        :param fixed_net: name of a Neutron network to provide connectivity
                          to the internal network for the cluster
                          (optional)
        :param fixed_subnet: Fixed subnet that are using to allocate network
                             address for nodes in bay/cluster (optional)
        :param registry_enabled: Docker images by default are pulled from the
                                 public Docker registry, but in some cases,
                                 users may want to use a private registry.
                                 This option provides an alternative registry
                                 based on the Registry V2: Magnum will create a
                                 local registry in the bay/cluster backed by
                                 swift to host the images (default - True)
        :param insecure_registry: The URL pointing to the user's own private
                                  insecure docker registry to deploy and run
                                  docker containers (optional)
        :param docker_storage_driver: DockerStorageDriver enum instance to
                                      manage storage for the images and
                                      container's writable layer
                                      (default - devicemapper)
        :param dns_nameserver: The DNS nameserver for the servers and
                               containers in the bay/cluster to use.
                               This is configured in the private Neutron
                               network for the bay/cluster.
                               (default provided by Magnum - 8.8.8.8)
        :param public: denotes whether or not the cluster template is public
                       (default False)
        :param tls_disabled: denotes whether or not TLS should be enabled
                             (default False)
        :param http_proxy: host:port for a proxy to use when direct HTTP
                           access from the servers to sites on the external
                           internet is blocked (optional)
        :param https_proxy: host:port for a proxy to use when direct HTTPS
                            access from the servers to sites on the external
                            internet is blocked (optional)
        :param no_proxy: comma separated list of IPs that should not be
                         redirected through the proxy (optional)
        :param volume_driver: The name of a volume driver for managing the
                              persistent storage for the containers. The
                              functionality supported are specific to the
                              driver (optional)
        :param master_lb_enabled: Since multiple masters may exist in a
                                  bay/cluster, a Neutron load balancer is
                                  created to provide the API endpoint for the
                                  bay/cluster and to direct requests to the
                                  masters. In some cases, such as when the
                                  LBaaS service is not available, this option
                                  can be set to false to create a bay/cluster
                                  without the load balancer. In this case, one
                                  of the masters will serve as the API endpoint
                                  (default - True)
        :param labels: Arbitrary labels in the form of a dict. The accepted
                       keys and valid values are defined in the bay/cluster
                       drivers. They are used as a way to pass additional
                       parameters that are specific to a bay/cluster driver.
                       (optional)
        """
        self.name = kwargs.get('name')
        self.image = kwargs.get('image')
        self.keypair = kwargs.get('keypair')
        self.network_driver = kwargs.get('network_driver')
        self.external_net = kwargs.get('external_net')
        self.floating_ip_enabled = str2bool(
            str(kwargs.get('floating_ip_enabled', True)))
        self.docker_volume_size = int(kwargs.get('docker_volume_size', 3))
        self.server_type = map_server_type(
            kwargs.get('server_type', ServerType.vm))
        self.flavor = kwargs.get('flavor')
        self.master_flavor = kwargs.get('master_flavor')
        self.coe = map_coe(
            kwargs.get('coe', ContainerOrchestrationEngine.kubernetes))
        self.fixed_net = kwargs.get('fixed_net')
        self.fixed_subnet = kwargs.get('fixed_subnet')
        self.registry_enabled = str2bool(
            str(kwargs.get('registry_enabled', True)))
        self.insecure_registry = kwargs.get('insecure_registry')
        self.docker_storage_driver = map_docker_storage_driver(
            kwargs.get('docker_storage_driver',
                       DockerStorageDriver.devicemapper))
        self.dns_nameserver = kwargs.get('dns_nameserver')
        self.public = str2bool(str(kwargs.get('public', False)))
        self.tls_disabled = str2bool(str(kwargs.get('tls_disabled', False)))
        self.http_proxy = kwargs.get('http_proxy')
        self.https_proxy = kwargs.get('https_proxy')
        self.no_proxy = kwargs.get('no_proxy')
        self.volume_driver = kwargs.get('volume_driver')
        self.master_lb_enabled = str2bool(
            str(kwargs.get('master_lb_enabled', True)))
        self.labels = kwargs.get('labels')

        if (not self.name or not self.image or not self.keypair
                or not self.external_net):
            raise ClusterTemplateConfigError(
                'The attributes name, image, keypair, and '
                'external_net are required for ClusterTemplateConfig')
 def args2body(self, parsed_args):
     body = super(CreateSecurityGroup, self).args2body(parsed_args)
     if hasattr(parsed_args, 'stateful') and parsed_args.stateful:
         sec_group = body['security_group']
         sec_group['stateful'] = utils.str2bool(parsed_args.stateful)
     return body
Esempio n. 10
0
    def __init__(self, **kwargs):
        """
        Constructor
        :param username: The user (required)
        :param password: The user's password (required)
        :param auth_url: The OpenStack cloud's authorization URL (required)
        :param project_name: The project/tenant name
        :param identity_api_version: The OpenStack's API version to use for
                                     Keystone clients
        :param image_api_version: The OpenStack's API version to use for Glance
                                  clients
        :param network_api_version: The OpenStack's API version to use for
                                    Neutron clients
        :param compute_api_version: The OpenStack's API version to use for Nova
                                    clients
        :param heat_api_version: The OpenStack's API version to use for Heat
                                    clients
        :param volume_api_version: The OpenStack's API version to use
                                   for Cinder clients
        :param magnum_api_version: The OpenStack's API version to use
                                   for magnum clients
        :param user_domain_id: Used for v3 APIs (default='default')
        :param user_domain_name: Used for v3 APIs (default='Default')
        :param project_domain_id: Used for v3 APIs (default='default')
        :param project_domain_name: Used for v3 APIs (default='Default')
        :param interface: Used to specify the endpoint type for keystone as
                          public, admin, internal
        :param proxy_settings: instance of os_credentials.ProxySettings class
        :param cacert: True for https or the certification file for https
                       verification (default=False)
        :param region_name: the region (optional default = None)
        """
        self.username = kwargs.get('username')
        self.password = kwargs.get('password')
        self.auth_url = kwargs.get('auth_url')
        self.project_name = kwargs.get('project_name')

        if kwargs.get('identity_api_version') is None:
            self.identity_api_version = keystone_utils.V3_VERSION_NUM
        else:
            self.identity_api_version = float(kwargs['identity_api_version'])

        if kwargs.get('image_api_version') is None:
            self.image_api_version = glance_utils.VERSION_2
        else:
            self.image_api_version = float(kwargs['image_api_version'])

        if kwargs.get('network_api_version') is None:
            self.network_api_version = 2
        else:
            self.network_api_version = float(kwargs['network_api_version'])

        if kwargs.get('compute_api_version') is None:
            self.compute_api_version = 2
        else:
            self.compute_api_version = float(kwargs['compute_api_version'])

        if kwargs.get('heat_api_version') is None:
            self.heat_api_version = 1
        else:
            val = kwargs['heat_api_version']
            ver = float(val)
            self.heat_api_version = int(ver)

        if kwargs.get('volume_api_version') is None:
            self.volume_api_version = cinder_utils.VERSION_2
        else:
            self.volume_api_version = float(kwargs['volume_api_version'])

        if kwargs.get('magnum_api_version') is None:
            self.magnum_api_version = 1
        else:
            self.magnum_api_version = float(kwargs['magnum_api_version'])

        self.user_domain_id = kwargs.get('user_domain_id', 'default')

        if kwargs.get('user_domain_name') is None:
            self.user_domain_name = 'Default'
        else:
            self.user_domain_name = kwargs['user_domain_name']

        self.project_domain_id = kwargs.get('project_domain_id', 'default')

        if kwargs.get('project_domain_name') is None:
            self.project_domain_name = 'Default'
        else:
            self.project_domain_name = kwargs['project_domain_name']

        if kwargs.get('interface') is None:
            self.interface = 'public'
        else:
            self.interface = kwargs['interface']

        self.region_name = kwargs.get('region_name', None)

        self.cacert = False
        if kwargs.get('cacert') is not None:
            if isinstance(kwargs.get('cacert'), str):
                if file_utils.file_exists(kwargs['cacert']):
                    self.cacert = kwargs['cacert']
                else:
                    self.cacert = str2bool(kwargs['cacert'])
            else:
                self.cacert = kwargs['cacert']

        if isinstance(kwargs.get('proxy_settings'), ProxySettings):
            self.proxy_settings = kwargs.get('proxy_settings')
        elif isinstance(kwargs.get('proxy_settings'), dict):
            self.proxy_settings = ProxySettings(**kwargs.get('proxy_settings'))
        else:
            self.proxy_settings = None

        if (not self.username or not self.password or not self.auth_url
                or not self.project_name):
            raise OSCredsError('username, password, auth_url, and project_name'
                               ' are required')

        self.auth_url = self.__scrub_auth_url()
Esempio n. 11
0
    def __init__(self, **kwargs):
        """
        Constructor
        :param name: A symbolic name for the port (optional).
        :param network_name: The name of the network on which to create the
                             port (required).
        :param admin_state_up: A boolean value denoting the administrative
                               status of the port (default = True)
        :param project_name: The name of the project who owns the network.
                             Only administrative users can specify a project ID
                             other than their own. You cannot change this value
                             through authorization policies (optional)
        :param mac_address: The MAC address. If you specify an address that is
                            not valid, a Bad Request (400) status code is
                            returned. If you do not specify a MAC address,
                            OpenStack Networking tries to allocate one. If a
                            failure occurs, a Service Unavailable (503) status
                            code is returned (optional)
        :param ip_addrs: A list of dict objects where each contains two keys
                         'subnet_name' and 'ip' values which will get mapped to
                         self.fixed_ips. These values will be directly
                         translated into the fixed_ips dict (optional)
        :param security_groups: One or more security group IDs.
        :param port_security_enabled: When True, security groups will be
                                      applied to the port else not
                                      (default - True)
        :param allowed_address_pairs: A dictionary containing a set of zero or
                                      more allowed address pairs. An address
                                      pair contains an IP address and MAC
                                      address (optional)
        :param opt_value: The extra DHCP option value (optional)
        :param opt_name: The extra DHCP option name (optional)
        :param device_owner: The ID of the entity that uses this port.
                             For example, a DHCP agent (optional)
        :param device_id: The ID of the device that uses this port.
                          For example, a virtual server (optional)
        :param extra_dhcp_opts: k/v of options to use with your DHCP (optional)
        :return:
        """
        if 'port' in kwargs:
            kwargs = kwargs['port']

        self.name = kwargs.get('name')
        self.network_name = kwargs.get('network_name')

        if kwargs.get('admin_state_up') is not None:
            self.admin_state_up = str2bool(str(kwargs['admin_state_up']))
        else:
            self.admin_state_up = True

        self.project_name = kwargs.get('project_name')
        self.mac_address = kwargs.get('mac_address')
        self.ip_addrs = kwargs.get('ip_addrs')
        self.security_groups = kwargs.get('security_groups')

        if kwargs.get('port_security_enabled') is not None:
            self.port_security_enabled = str2bool(
                str(kwargs['port_security_enabled']))
        else:
            self.port_security_enabled = None

        self.allowed_address_pairs = kwargs.get('allowed_address_pairs')
        self.opt_value = kwargs.get('opt_value')
        self.opt_name = kwargs.get('opt_name')
        self.device_owner = kwargs.get('device_owner')
        self.device_id = kwargs.get('device_id')
        self.extra_dhcp_opts = kwargs.get('extra_dhcp_opts')

        if not self.network_name:
            raise PortConfigError('The attribute network_name is required')
Esempio n. 12
0
    def __init__(self, **kwargs):
        """
        Constructor - all parameters are optional
        :param name: The network name.
        :param admin_state_up: The administrative status of the network.
                               True = up / False = down (default True)
        :param shared: Boolean value indicating whether this network is shared
                       across all projects/tenants. By default, only
                       administrative users can change this value.
        :param project_name: Admin-only. The name of the project that will own
                             the network. This project can be different from
                             the project that makes the create network request.
                             However, only administrative users can specify a
                             project ID other than their own. You cannot change
                             this value through authorization policies.
        :param external: when true, will setup an external network
                         (default False).
        :param network_type: the type of network (i.e. vlan|flat).
        :param physical_network: the name of the physical network
                                 (required when network_type is 'flat')
        :param segmentation_id: the id of the segmentation
                                 (this is required when network_type is 'vlan')
        :param subnets or subnet_settings: List of SubnetConfig objects.
        :param mtu: MTU setting (optional)
        :return:
        """

        self.project_id = None

        self.name = kwargs.get('name')
        if kwargs.get('admin_state_up') is not None:
            self.admin_state_up = str2bool(str(kwargs['admin_state_up']))
        else:
            self.admin_state_up = True

        if kwargs.get('shared') is not None:
            self.shared = str2bool(str(kwargs['shared']))
        else:
            self.shared = None

        self.project_name = kwargs.get('project_name')

        if kwargs.get('external') is not None:
            self.external = str2bool(str(kwargs.get('external')))
        else:
            self.external = False

        self.network_type = kwargs.get('network_type')
        self.physical_network = kwargs.get('physical_network')
        self.segmentation_id = kwargs.get('segmentation_id')

        self.subnet_settings = list()
        subnet_settings = kwargs.get('subnets')
        if not subnet_settings:
            subnet_settings = kwargs.get('subnet_settings', list())
        if subnet_settings:
            for subnet_config in subnet_settings:
                if isinstance(subnet_config, SubnetConfig):
                    self.subnet_settings.append(subnet_config)
                else:
                    self.subnet_settings.append(
                        SubnetConfig(**subnet_config['subnet']))

        if not self.name or len(self.name) < 1:
            raise NetworkConfigError('Name required for networks')

        self.mtu = kwargs.get('mtu')