def __call__(self, parser, namespace, values, option_string=None): if values: node_identities = set(chain(*values)) input_macs = set(n for n in node_identities if ":" in n) only_ids = set() for _id in (node_identities - input_macs): try: only_ids.add(int(_id)) except ValueError: raise ArgumentException( "'{0}' is not valid node id.".format(_id)) if input_macs: nodes_mac_to_id_map = dict( (n["mac"], n["id"]) for n in DefaultAPIClient.get_request("nodes/")) for short_mac in input_macs: target_node = None for mac in nodes_mac_to_id_map: if mac.endswith(short_mac): target_node = mac break if target_node: only_ids.add(nodes_mac_to_id_map[target_node]) else: raise ArgumentException( 'Node with mac endfix "{0}" was not found.'.format( short_mac)) node_ids = [int(node_id) for node_id in only_ids] setattr(namespace, self.dest, node_ids)
def configure(self, username, password, satellite_server_hostname=None, activation_key=None): data = { "release_id": self.id, "username": username, "password": password } satellite_flags = [satellite_server_hostname, activation_key] if not any(satellite_flags): data.update({ "license_type": "rhsm", "satellite": "", "activation_key": "" }) elif all(satellite_flags): data.update({ "license_type": "rhn", "satellite": satellite_server_hostname, "activation_key": activation_key }) else: raise ArgumentException('RedHat satellite settings requires both a' ' "--satellite-server-hostname" and ' 'a "--activation-key" flags.') release_response = self.connection.post_request("redhat/setup/", data) return release_response
def change_password(self, params): """To change user password: fuel user change-password """ if params.newpass: APIClient.update_own_password(params.newpass) else: raise ArgumentException( "Expect password [--newpass NEWPASS]")
def wrapped_f(self, params): if method(getattr(params, _arg) for _arg in args): return f(self, params) else: raise ArgumentException( "{0} required!".format( quote_and_join( "--" + arg for arg in args ) ) )
def create(cls, name, release_id, net, net_segment_type=None): data = { "nodes": [], "tasks": [], "name": name, "release_id": release_id } if net.lower() == "nova": data["net_provider"] = "nova_network" else: data["net_provider"] = "neutron" if net_segment_type is not None: data["net_segment_type"] = net_segment_type else: raise ArgumentException( '"--net-segment-type" must be specified!') data = cls.connection.post_request("clusters/", data) return cls.init_with_data(data)
def delete(self, params): """Remove some nodes from environment: fuel --env 1 node remove --node 2,3 Remove nodes no matter to which environment they were assigned: fuel node remove --node 2,3,6,7 Remove all nodes from some environment: fuel --env 1 node remove --all """ if params.env: env = Environment(params.env) if params.node: env.unassign(params.node) self.serializer.print_to_output( {}, "Nodes with ids {0} were removed " "from environment with id {1}.".format( params.node, params.env)) else: if params.all: env.unassign_all() else: raise ArgumentException( "You have to select which nodes to remove " "with --node-id. Try --all for removing all nodes.") self.serializer.print_to_output( {}, "All nodes from environment with id {0} were removed.". format(params.env)) else: nodes = map(Node, params.node) for env_id, _nodes in groupby(nodes, attrgetter("env_id")): list_of_nodes = [n.id for n in _nodes] if env_id: Environment(env_id).unassign(list_of_nodes) self.serializer.print_to_output( {}, "Nodes with ids {0} were removed " "from environment with id {1}.".format( list_of_nodes, env_id)) else: self.serializer.print_to_output( {}, "Nodes with ids {0} aren't added to " "any environment.".format(list_of_nodes))
def _get_password_from_prompt(self): password1 = getpass("Changing password for Fuel User.\nNew Password:"******"Retype new Password:"******"Passwords are not the same.") return password1